Jump to content

Greater than...


Recommended Posts

The goal of this block of code is to set the variable named $Sets to the max number entered into the input box by the user. The user will be entering numbers like 6 the first time thru the loop and then 3 and then 22.

I would expect $Sets to = 22. Instead I get 6 as the max number entered.

What did I code wrong???

$tabNames = "tab11/tab10/tab9/tab8/tab7/tab6/tab5/tab4/tab3/tab2/tab1/"
$tabNames = StringTrimRight ($tabNames, 1);remove last "/"
$tabNamesARRAY = StringSplit ($tabNames, "/")
$SetARRAY = StringSplit ($tabNames, "/")
$Sets = 0
For $i = $tabNamesARRAY [0] to 1 Step -1
     While 1
        $SetARRAY [$i] = InputBox ("AutoIt", "Enter number like 1, 2 or 3?", "", "", 600, 140)
        If @error = 1 Then EXIT;cancel was selected
        If StringIsInt ($SetARRAY [$i]) = 0 Then;is it a number
           MsgBox (0, "AutoIt", "The input must be a number..... Try again.")
        Else
           ExitLoop
        EndIf
    WEnd
    msgbox(0,"SetARRAY", $SetARRAY [$i])
    If $SetARRAY [$i] > $Sets Then $Sets = $SetARRAY [$i]
    msgbox(0,"Sets",$Sets)
Next

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Developers

What did I code wrong???

<{POST_SNAPBACK}>

You are comparing strings in stead of values. change this line

If $SetARRAY [$i] > $Sets Then $Sets = $SetARRAY [$i]
to

If Number($SetARRAY [$i]) > Number($Sets) Then $Sets = $SetARRAY [$i]

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

Thanks... your code works (as always)

...but why would the "Number" statement be needed if the array value is already a number from the input box???

<{POST_SNAPBACK}>

Because the inputbox always returns a string.

Why would the function spend more time to figure out if it was a number?

Link to comment
Share on other sites

Yep - that makes sense...

I'll try and remember that an input box always returns a string...

always returns a string...

always returns a string...

always returns a string...

Oh - I'll still forget it some day into the future.

Thanks all for the really fast answers.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Developers

Thanks... your code works (as always)

...but why would the "Number" statement be needed if the array value is already a number from the input box???

<{POST_SNAPBACK}>

Heres a quote from the helpfile that explains how autoit works internally.

In this case AutoIt does a string type compare unless you use the Number() function.

In AutoIt there is only one datatype called a Variant.  A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in.  For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings

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

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