Jump to content

Help with While and Wend


Razor
 Share

Recommended Posts

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?

Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...