New topic: TRUE or FALSE in loops, how do I do!?
<http://forums.realsoftware.com/viewtopic.php?t=30532> Page 1 of 1 [ 9 posts ] Previous topic | Next topic Author Message Eclipse Post subject: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:18 am Joined: Sat May 19, 2007 6:01 am Posts: 74 This works: Quote:IF Instr(data2, TextField1.text) = 0 THEN ... DO UNTIL InStr(strPage, TextField1.text) = 0 ... (not tested, but likely...) But not reverse! Quote:IF Instr(data2, TextField1.text) = 1 THEN ... DO UNTIL InStr(strPage, TextField1.text) = 1 ... How do I write TRUE or 1...!? Silly question... Really... But I need the TRUE alternative! Or do I need to write IF NOT ...!? Top piMaster Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:30 am Joined: Fri Sep 30, 2005 9:12 am Posts: 670 Location: Rockford, IL You could use this: Code:IF Instr(data2, TextField1.text) <> 0 THEN ... _________________ RB2009r4 Pro on Win XP Top Eclipse Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:36 am Joined: Sat May 19, 2007 6:01 am Posts: 74 Thank you! Silly logic!! Well... Whatever. As long as it works! Top Steve Garman Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:38 am Joined: Fri Sep 30, 2005 3:53 pm Posts: 3053 Location: England Eclipse wrote:Silly logic!!Instr doesn't just tell you whether the substring is in the string, it tells you where in the string it is.Code:IF Instr(data2, TextField1.text) > 0 Then _________________ Steve Garman Using REALbasic 2008r2 Professional on Windows Vista Ultimate and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop Occasional blog Last edited by Steve Garman on Sat Oct 17, 2009 11:41 am, edited 1 time in total. Top Phil M Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:41 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 140 I had thought that REALbasic had an Operator_Convert implemented from Boolean to Integer, but I guess I was wrong. You can easily add it... put this in a module with a GLOBAL scope. Code:Function Operator_Convert( Extends b As Boolean ) As Integer If True Return 1 Else Return 0 End Function However, the function you are linking there, "InStr" returns an Integer not a Boolean, showing you the first char where your search string is found. For example, InStr( "Hello World", "o" ) would return "5", but InStr( "Hello World", "z" ) would return "0". Here is an example of something similar to what it seems like you are trying to implement: Code:Function Count( source As String, find As String ) As Integer Dim theCount As Integer Dim thePos As Integer = 1 If InStr( source, find ) > 0 Then // already know its in there at least once, so start with 1 for counter theCount = 1 Do Until ( thePos = 0 ) thePos = InStr( thePos, source, find ) // uses optional "start at" option If ( thePos > 0 ) Then theCount = theCount + 1 Loop End If Return theCount End Function As far as using Booleans, you can just use the True / False keywords. Top Eclipse Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:54 am Joined: Sat May 19, 2007 6:01 am Posts: 74 With respect! Thank you very much! I have experience of Microsoft ASP, as the webdeveloper... One day the experience in RealBasic will also arrive to me! Top Phil M Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 11:58 am Joined: Fri Sep 30, 2005 12:18 pm Posts: 140 While you can treat Booleans as their integer types with the Operator_Convert( ) I showed you above, it is better coding practice to use the True / False keywords because the meaning is immediately clear. Top Eclipse Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 12:42 pm Joined: Sat May 19, 2007 6:01 am Posts: 74 Yes... I think it was the issue! I read the zero as FALSE, not as zero, as in the number! *** If I do like this, Code: FOR j = 0 TO UBound(myArray) < --- first loop FOR .... < --- second loop IF ...... = TRUE THEN EXIT NEXT NEXT IF i use the EXIT command, will also the first loop exit!? Top Phil M Post subject: Re: TRUE or FALSE in loops, how do I do!?Posted: Sat Oct 17, 2009 12:51 pm Joined: Fri Sep 30, 2005 12:18 pm Posts: 140 Language Reference wrote:The Exit statement causes control to exit a loop and jump to another line of code without the loop conditions being satisfied. The optional keywords enable you to control where execution will resume. To make your code clear use... Code:For j As Integer = 0 To Ubound( myArray ) For x As Integer = 0 To Ubound( mySecondArray ) If something = True Then Exit For x // or j if thats what you intend Next Next Verbose coding isn't bad, and can actually save you a lot of time later on when you revisit the code a few months from now... long enough to have to "relearn" what it does. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 9 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
