Jump to content

Problem with Do loop


Recommended Posts

Hi Guys,

I became familiar with Autoit just recently and trying to automate a software. The problem is that as I run it, the Do loop is not working. I want to know if there is any problems with the loop or not.... would you guys please help me

Do
   $String_1 = InputBox ( "Unit Type", "Select your Unit type : Sub for Sub-critical, Super for Super-critical, Ultra for Ultra Super-critical")
   Until $String_1 = "Sub" or "Super" or "Ultra"
   If $String_1 = "Sub" Then
   Send ( "{Up}")
   ElseIf $String_1 = "Super" Then
   Send ( "")
   ElseIf $String_1 = "Ultra" Then
   Send ( "{down}")
   EndIf

I want to use the output of the Do loop for the next stages.

Edited by Jos
Link to comment
Share on other sites

  • Developers

CodeTags are like he shown in his answer... oh wait he didn't use the either. :)

Click the <> icon in the editor when posting and paste your code there.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Code tags (<> button in the toolbar when you post) turn this:

Do
   $String_1 = InputBox ( "Unit Type", "Select your Unit type : Sub for Sub-critical, Super for Super-critical, Ultra for Ultra Super-critical")
   Until $String_1 = "Sub" or "Super" or "Ultra"
   If $String_1 = "Sub" Then
   Send ( "{Up}")
   ElseIf $String_1 = "Super" Then
   Send ( "")
   ElseIf $String_1 = "Ultra" Then
   Send ( "{down}")
   EndIf

...into this...

Do
   $String_1 = InputBox ( "Unit Type", "Select your Unit type : Sub for Sub-critical, Super for Super-critical, Ultra for Ultra Super-critical")
   Until $String_1 = "Sub" or "Super" or "Ultra"
   If $String_1 = "Sub" Then
   Send ( "{Up}")
   ElseIf $String_1 = "Super" Then
   Send ( "")
   ElseIf $String_1 = "Ultra" Then
   Send ( "{down}")
   EndIf

...and keep our eyes from bleeding as we try to read your code ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

If you have a lot of that in your code, just make a little function to help.

Do
    $Input = InputBox("title", "prompt")
Until _StringIs($Input, "Sub|Super|Ultra")


Func _StringIs($String, $SubString)
    If Not StringInStr($SubString, "|") Then
        Return ($String == $SubString)
    EndIf
    $aStrings = StringSplit($SubString, "|", 2)
    For $i = 0 To UBound($aStrings) - 1
        If $String == $aStrings[$i] Then
            Return True
        EndIf
    Next
    Return False
EndFunc

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Good day @JohnOne your example is good for practising coding skills, but how do I make it to not case sensitive?

I have tried like this

Do
    $Input = InputBox("title", "prompt")
Until _StringIs($Input, "Sub|Super|Ultra|sub|super|ultra")


Func _StringIs($String, $SubString)
    If Not StringInStr($SubString, "|") Then
        Return ($String == $SubString)
    EndIf
    $aStrings = StringSplit($SubString, "|", 2)
    For $i = 0 To UBound($aStrings) - 1
        If $String == $aStrings[$i] Then
            Return MsgBox(64, "", $Input)
        EndIf
    Next
    Return False
EndFunc

it worked but is there any other way to make it not casesensitive???

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

You could try a combobox in a GUI to list the options so that users can only choose the options you offer them rather than looping them through an inputbox until they provide a proper answer.  

I just wanted to come up with my own strange solution to this where I could use this code for the combobox but since its an inputbox it loops back to the function until a proper answer is given.

 

Test()


Func Test()
$vInput = InputBox("Unit Type", "Select your Unit type : Sub for Sub-critical, Super for Super-critical, Ultra for Ultra Super-critical")
    Switch $vInput
        Case "Sub"
            MsgBox(0, "", "Good Answer - Sub")
        Case "Super"
            MsgBox(0, "", "Good Answer - Super")
        Case "Ultra"
            MsgBox(0, "", "Good Answer - Ultra")
        Case Else
            Test()
    EndSwitch
EndFunc

 

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...