gettingstarted
[Top] [All Lists]

InStr problems

To: gettingstarted at lists dot realsoftware dot com
Subject: InStr problems
From: Aubrey Todd <atodd at copper dot net>
Date: Thu, 27 May 2004 11:41:04 -0700
Delivered-to: gettingstarted at lists dot realsoftware dot com
List-help: <mailto:gettingstarted-request@lists.realsoftware.com?subject=help>
List-id: Getting Started <gettingstarted.lists.realsoftware.com>
List-post: <mailto:gettingstarted@lists.realsoftware.com>
References: <20040527170005 dot C3E161EA461 at lists dot realsoftware dot com>

I am having a problem with the InStr command in the following code:

  Dim Pos as Integer

  //Check for Justaposition on the left
 //Checks for a number before the '(' and inserts a '*' if appropriate
  Pos=-1
  Do //This loop works fine
    Pos=Pos+2
    Pos=InStr(Pos,ProbStr,"(")
    If Pos>1 Then
     perform some process here
    End If
  Loop Until Pos=0

  //Check for Justaposition on the right
 //Checks for a number after the ')' and inserts a '*' if appropriate
  Pos=-1
  Do //This loop does not work all the time
    Pos=Pos+2
    Pos=InStr(Pos,ProbStr,")") //<===Problem occurs here
    If Pos>1 Then
     perform some process here
    End If
  Loop Until Pos=0

ProbStr is a string property.
If ProbStr=(2+1/2)+(3+1/4) both loops work correctly.
If ProbStr=Dec(2+1/2)+Dec(3+1/4), the second loop does not exit because Pos never goes to zero. In the second loop, Pos=InStr(Pos,ProbStr,")")=21 the second time through, then loop and Pos=Pos+2=23, but when it hits Pos=InStr(Pos,ProbStr,")") again, Pos is set to 21 instead of zero. If I manually change the command to Pos=InStr(23,ProbStr,")"), it works fine and returns a zero.

Anyone have a hint as to what I am doing wrong or why it does not work?

Thanks,
Aubrey
PB G4 Mac OS 10.3.3
RB 5.2.4



_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>