Page 1 of 1

Does Rev have counterparts to VB's left$,mid$,right$

Posted: Mon Jul 19, 2010 4:11 am
by urbaud
Visual Basic has left$, mid$ and right$ functions when dealing with text. Does rev have similar text functions? If so, where would I find examples of them? Can't find a reference to this when searching the forum.

Re: Does Rev have counterparts to VB's left$,mid$,right$

Posted: Mon Jul 19, 2010 6:11 am
by bangkok
urbaud wrote:Visual Basic has left$, mid$ and right$ functions when dealing with text. Does rev have similar text functions? If so, where would I find examples of them? Can't find a reference to this when searching the forum.
Left$ would be the easiest :
put char 1 to 2 of theString
=left$(theString,2)

Re: Does Rev have counterparts to VB's left$,mid$,right$

Posted: Mon Jul 19, 2010 9:59 am
by bn
Dan,
You can also use
put char -2 to -1 of myVar into Field "myField"
For the last two chars, etc

Or
Put middle char of myVar into Field "myField"

Regards
Bernd

Re: Does Rev have counterparts to VB's left$,mid$,right$

Posted: Thu Jul 22, 2010 10:43 pm
by urbaud
Hi Bernd and Bangkok,
Thanks to you both for responding to my post. The reason for my initial question about counterparts in Rev for the VB left$, mid$ and right$ functions was because a friend asked me if I knew Rev well enough to translate the following VB code into Rev.

text1.text = 12345
dim i as integer
dim ctr as string
for i = len(text1.text) to 1 step -1
ctr = ctr + mid(text1.text,i,1)
next i
text2.text = ctr
print text1.texta
print ctr

I don’t know if you know what this does, so I’ll show the display:
12345
54321

Here’s my rendition of the above VB code in Rev:

Code: Select all

on mouseUp --displays text backwards
  put "Bill Gates" into name1  
  put name1 into fld "l1"
      repeat with i =1 to len(name1) 
	wait 200 milliseconds
      get the char(i) of name1  
      put it before fld "l2"  
      end repeat
   end mouseUp
Display:
Bill Gates
setaG lliB

It’s been awhile since I dabbled in VB so I had to look up what the VB functions do:
Left$() Returns the left n characters of a string; temp = left$ ( teststring$, 4 )
Right - Returns the right n characters of a string; temp = right$ ( teststring$, 4 )
Mid - Returns n characters from a string, starting a any position; temp = mid$ ( teststring$, 1, 4 )

So, below are my translations of the VB functions, with thanks to both of you for your suggestions:

Code: Select all

on mouseUp  --like VB left$ function
   put "Bill Gates" into name1
   put name1 into fld "l1"
   put char 1 to 4 name1 into fld "l2"  
   put char 1 to 7 name1 into fld "l3"
   put char 1 to 2 name1 into fld “l4”
   End mouseUp
Display:
Bill Gates
Bill
Bill Ga
Bi
--

Code: Select all

on mouseUp  --like VB right$ function
   put "Bill Gates" into name1
   put name1 into fld "l1"
   put char 4 to -1 of name1 into fld "l2"  
   put char -2 to -1 of name1 into fld "l3" 
   put char 7 to -1 of name1 into Field "l4" 
end mouseUp
Display:
Bill Gates
l Gates
Es
ates
--

Code: Select all

on mouseUp  --like VB mid$ function
   put "Bill Gates" into name1
   put name1 into fld "l1"
   put char 1 to 4 of name1 into fld "l2"   
   put char 6 to 7 of name1 into fld "l3" 
   put middle char of name1 into Field "l4"                                                                                   
end mouseUp
Display:
Bill Gates
Bill
Ga
G

Oh, and by the way, since I have your attention, I have a question. As you know, when using a slider, you can set the values to be shown at the bottom of the slider in the properties of the slider. Is there a way to show those values in a text or label field? So, as the slider is moved, is it possible to show the changing values in a field, label or text?

Again, thanks to both of you for your help.
Dan

Re: Does Rev have counterparts to VB's left$,mid$,right$

Posted: Fri Jul 23, 2010 3:10 am
by mwieder
The VB code looks like a simple reversed-text algorithm. Try something like

Code: Select all

on mouseUp
    put empty into field "text2"
    repeat for each char tChar in field "text1"
        put tChar before field "text2"
    end repeat
end mouseUp

Re: Does Rev have counterparts to VB's left$,mid$,right$

Posted: Fri Jul 23, 2010 3:20 am
by mwieder
Oh, and by the way, since I have your attention, I have a question. As you know, when using a slider, you can set the values to be shown at the bottom of the slider in the properties of the slider. Is there a way to show those values in a text or label field? So, as the slider is moved, is it possible to show the changing values in a field, label or text?
The message you're looking for there is "scrollbarDrag". I realize it's not really intuitive: you have to know beforehand that a slider is a scrollbar and then pick the appropriate message from the available ones. But putting the following into the slider (scrollbar) script

Code: Select all

on scrollbardrag pValue
    put pValue into field "fldScrollValue"
end scrollbardrag
should do the trick