Sign in to follow this  
Followers 0
Shams

Problem with Do loop

10 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Until $String_1 = "Sub" or "Super" or "Ultra"
should be
Until $String_1 = "Sub" or $String_1 = "Super" or $String_1 = "Ultra"

BTW you also should use the code tags to post code  ;)

Share this post


Link to post
Share on other sites

Thanks Mikell, I do not know what code tags are, but it worked and it is now fine. Thanks

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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 ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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

 

2 people like this

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

Monkey's are, like, natures humans.

Share this post


Link to post
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.

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

Just replace '==' with '='

thanks, you got a sharp eye didnt notice this line

If $String == $aStrings[$i] ;"=="

 


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.

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