Sign in to follow this  
Followers 0
Razor

Help with While and Wend

3 posts in this topic

Hi, I wrote this little script:

While 1

If StringInStr ($manstr, "Dell") Then

$pcman = "Dell"

ExitLoop

EndIf

If StringInStr ($manstr, "Compaq") Then

$pcman = "Compaq"

ExitLoop

EndIf

If StringInStr ($manstr, "IBM") Then

$pcman = "IBM"

ExitLoop

EndIf

Wend

It works, but if $manstr is something else, the script just pegs the processor (infinite loop), how do fix the above code to Exit if $manstr isn't one of the above 3?

Share this post


Link to post
Share on other sites



Something like:

While 1
    If StringInStr ($manstr, "Dell") Then
        $pcman = "Dell"
        ExitLoop
    EndIf
    
    If StringInStr ($manstr, "Compaq") Then
        $pcman = "Compaq"
        ExitLoop
    EndIf
    If StringInStr ($manstr, "IBM") Then
        $pcman = "IBM"
        ExitLoop
    EndIf

    If NOT StringInStr ($manstr, "Dell") Or StringInStr ($manstr, "Compaq") Or StringInStr ($manstr, "IBM") Then Exit
Wend

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Why use a while loop then it never loops.

I stops after first run always useless to run a while loop then

If you constantly want to check

While 1
  Select
    Case $manstr= "Dell"
      $pcman = "Dell"
      exitloop
    Case $manstr= "Compaq"
      $pcman = "Compaq"
      exitloop
    Case $manstr= "IBM"
      $pcman = "IBM"
      exitloop
    Case Else
      sleep(250)
  EndSelect
Wend

Here the loop does loop and checks every 4the of a second wich doesn't suck up much cpu

Edited by MrSpacely

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0