Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

condition logic 1

Status
Not open for further replies.

reggler

Programmer
Nov 13, 2008
63
CA
Hi There,
There's even another stone in my way...i should have stayed wuith C++ I know ;)
My problem (also called condition;) )
I want to loop as long as $rslt is -1 and $counter is smaller than $timeout.
My code:
Code:
while { ($rslt == -1) && ($counter < $timeout) }  {
But I get:
invalid command name "-1"
invalid command name "-1"
while executing
"$rslt != -1"
(procedure "BIS_Test::Start" line 616)
invoked from within

And i don't understand why.... thanks for you guys help, onece again.
 
I copied your whilé condition as you posted and added some code and it works fine-look:
Code:
[COLOR=#804040][b]set[/b][/color] rslt -[COLOR=#ff00ff]1[/color]
[COLOR=#804040][b]set[/b][/color] timeout [COLOR=#ff00ff]5[/color]
[COLOR=#804040][b]set[/b][/color] counter [COLOR=#ff00ff]1[/color]
[COLOR=#804040][b]while[/b][/color] { ([COLOR=#008080]$rslt[/color] == -[COLOR=#ff00ff]1[/color]) &amp;&amp; ([COLOR=#008080]$counter[/color] < [COLOR=#008080]$timeout[/color]) } {
[COLOR=#0000ff]  # increment[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"running $counter"[/color]
  [COLOR=#804040][b]set[/b][/color] counter [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$counter[/color] + [COLOR=#ff00ff]1[/color]]
}
Output is:
Code:
running 1
running 2
running 3
running 4
I don't see an problems.
 
Opps, fixed problemwith my syntax highlighting script (ampersand not implemented)
Code:
[COLOR=#804040][b]set[/b][/color] rslt -[COLOR=#ff00ff]1[/color]
[COLOR=#804040][b]set[/b][/color] timeout [COLOR=#ff00ff]5[/color]
[COLOR=#804040][b]set[/b][/color] counter [COLOR=#ff00ff]1[/color]
[COLOR=#804040][b]while[/b][/color] { ([COLOR=#008080]$rslt[/color] == -[COLOR=#ff00ff]1[/color]) && ([COLOR=#008080]$counter[/color] < [COLOR=#008080]$timeout[/color]) } {
[COLOR=#0000ff]  # increment[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"running $counter"[/color]
  [COLOR=#804040][b]set[/b][/color] counter [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$counter[/color] + [COLOR=#ff00ff]1[/color]]
}
 
Huh,

I keep getting:

invalid command name "-1"
invalid command name "-1"
while executing
"$rslt != -1"
(procedure "BIS_Test::Start" line 616)
invoked from within
"BIS_Test::Start"
[/]
my code looks like this:
Code:
    while {  ($rslt == -1) && ($counter < $timeout)  }  {
        #load content from console window into $str
	    #set str [.serialMon.cons get 0.0 end]
        #search for the string "Pass: 10" in $str
        set rslt [string first "Pass: $BIS_Test::total_iterations" $serial::rxBuffer]    
        if {[$rslt != -1]} {                         
        	set cond 1
            while {$cond}  {		                        
                $GUI::twidget see end
                #load content from console window into a list (break at new line)
	        	set lst [split $serial::rxBuffer \n\r]
	        	set length [llength $lst]	        		        	
	        	#debug - $GUI::twidget insert end "\n\n***list length: $length***\n\n"
	        	if {$length>1}  {		        			        	
		        	set str1 [string range [lindex $lst [expr $length - 4]] 0 11]
		        	set str2 [string range [lindex $lst [expr $length - 2]] 0 11]
		        	set str3 [string range [lindex $lst [expr $length - 1]] 0 11]
		        	set len1 [string length $str1]
		        	set len2 [string length $str2]
		        	set len3 [string length $str3]
		        	if {(($len1 > 7) && ($len2 > 7)) || (($len3 > 0) && ($len2 >0))}  {
		        	#see if the last two strings from the console window match set stop condition(s)
		        		if { ([string compare -length 7 $str1 $str2] == 0) } {				        	
			        		set cond 0
	    	    		}
	    	    		if { ([string compare -length 2 $str2 $str3] == 0) && ([string first "memrw run" $str3]==-1 )} {
		    	    		set cond 0		    	    		
	    	    		}
    	    		}    	    		
	        	}
            	finaltest::delay 100
            }            
        }
        finaltest::delay 100
        set counter [expr $counter + 1]
    }

Thanks for throwing an eye on my code.

Ron
 
Hi reggler,

Correct the
Code:
...
if {[red][[/red]$rslt != -1[red]][/red]} {
...
to
Code:
...
if {$rslt != -1} {
...

Now it works :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top