Jump to content
Sign in to follow this  
Newb

Do ... Until drives me nuts

Recommended Posts

Newb

I've done quite some good steps with autoit, and now I'm almost autosufficient in doing my tasks with it.

But Do .... Until

I never got it.... damn... it's designed such in a wrong way....

need explanations on it.

Here's the code I'm doing

Do
Global $Onset=InputBox("Input numbers", "Insert input numbers (Ex 2,3,10,12)")
ConsoleWrite(Number($Onset))
Until IsInt(Number($Onset))

1st question: How the hell it works...I want the InputBox to show up until user insert a valid integer number (so no letters, no strings, no chars, no floats and so on).

The above code fails. Tried to put

Until IsInt(Number($Onset))=0
and
Until IsInt(Number($Onset))=1

and different changes too, nothing worked properly.

2nd question. This code is at the very beginning of my program, so where I'm declaring global variables that will be used through the rest of the program. Can I declare a global in there? Or since it's into a cycle it will be temporary.

Bonus: Not fitting into what I asked, but i would need a good guide for RegEx <<<FOR AUTOIT>>> because help file is killing me, and other regexp guides are for other languages.

Below, the full code (a binary converter only, for the moment, which returns an array with at place 0 the converted number, and at the others, the single numbers which makes up the converted number). No need to look, just if you're curious.

Global $Ingressi=InputBox("Numero Ingressi", "Inserire numero ingressi (Es: a,b,c,d= 4 ingressi)")
Do
Global $Onset=InputBox("Numero Ingressi", "Inserire gli uni della funzione (Es 2,3,10,12)")
ConsoleWrite(Number($Onset))
Until IsInt(Number($Onset))
Dim $TabSemp[2^$Ingressi][$Ingressi]
Dim $Tav=DecToBin($Onset)
Func DecToBin($decim)
Local $Risultato[$Ingressi+1]
Local $k=0
  While $decim>=1
   If Mod($decim,2)>0 Then
    $Risultato[$k+1]=1
   Else
    $Risultato[$k+1]=0
   EndIf
  $decim=Floor($decim/2)
  $k+=1
WEnd
Local $StringResult
For $i=$k to 1 Step -1
  $StringResult=$StringResult&$Risultato[$i]
Next
$Risultato[0]=$StringResult
Return $Risultato
EndFunc
Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites
DW1

Hi Newb,

1) Check out what Number() does when passed a alpha character; "A string beginning with letters has a numeric value of zero. A string beginning with digits has non-numeric characters stripped."

You just need a better way to detect an integer, your use of Do...Until was correct.

Here is an example with StringRegExp():

Global $Onset
Do
$Onset=InputBox("Input numbers", "Insert input numbers (Ex 2,3,10,12)")
ConsoleWrite(Number($Onset))
Until StringRegExp($Onset, '^d+$')

2) Declare your global variables once, no need to do it in this loop.

Bonus) The help file is pretty good but there is also a link in there to HERE for more information.

You can find a lot of helper applications that usually have a library of examples as well as an easy interface to test your regular expressions in, just remember that autoit uses PCRE so that you are running against the right engine.

Share this post


Link to post
Share on other sites
Newb

Hi Newb, 1) Check out what Number() does when passed a alpha character; "A string beginning with letters has a numeric value of zero. A string beginning with digits has non-numeric characters stripped." You just need a better way to detect an integer, your use of Do...Until was correct. Here is an example with StringRegExp():

Global $Onset Do $Onset=InputBox("Input numbers", "Insert input numbers (Ex 2,3,10,12)") ConsoleWrite(Number($Onset)) Until StringRegExp($Onset, '^d+$')
2) Declare your global variables once, no need to do it in this loop. Bonus) The help file is pretty good but there is also a link in there to HERE for more information. You can find a lot of helper applications that usually have a library of examples as well as an easy interface to test your regular expressions in, just remember that autoit uses PCRE so that you are running against the right engine.
Fist of all, thanks for the help.

for question number 2, i know when i have to declare globals, but since that one was declared into a loop, i had the doubt :)

Bonus: damn, that guide is long and complex (i've stumbled upon it months ago), more like something to read when you have some very specific problems and you have to check all what a specific thing does (like I should have done with Number() function). I would like a more easy to read guide, with some examples with strings explained. There isn't anything similar?

Breaking down the code to the simples, it still doesn't work. I would like to yell that this thing it's bugged, but i've learned that most of the times it's user fault....

so what's up with this? Why i can't still recognize numbers?

Do
Global $Onset=InputBox("Insert any number but 0", "Insert any number but 0")
If IsInt(Number($Onset))=0 Then
ConsoleWrite("Not a number")
Else
ExitLoop
ConsoleWrite("Number accepted")
EndIf
Until 0
Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

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  

×