Jump to content

Using operators and limiting InputGUI to numbers Only


 Share

Recommended Posts

More neophite questions here. Have about 571 pdf files each file containing about 2000 documents. The files are named something like:

1-2000.pdf

2001-4000.pdf

4001-6000.pdf

etc, etc

Want to create a little script that will allow users to type in the number of the document they are looking for that will automatically open the correct pdf file for them. So far I have this:

include <GUIConstants.au3>

GUICreate(" Priors Search", 320,120)

$file = GUICtrlCreateInput ( "", 10, 5, 300, 20)

GUICtrlSetState(-1,$GUI_NODROPACCEPTED)

GUICtrlSetLimit (-1, 7)

$btn = GUICtrlCreateButton ("Search", 40, 75, 60, 20)

GUISetState ()

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn

exitloop

EndSelect

Wend

if $file >= 1 And $file <= 2000 then

MsgBox (4096, "results", "This nubmer is between 1 and 2000")

EndIf

Questions:

1. What Function should I use to limit the characters in my input box to numbers only?

2. My >= and <= operators are not working. If I enter a number between 1 and 2000 I should get the MsgBox. What did I do wrong?

3. What function would I use to open a pdf file?

Sorry for so many questions in one post. Thanks.

Link to comment
Share on other sites

Questions:

1. What Function should I use to limit the characters in my input box to numbers only?

2. My >= and <= operators are not working. If I enter a number between 1 and 2000 I should get the MsgBox. What did I do wrong?

3. What function would I use to open a pdf file?

1) You need to add $ES_NUMBER to GUICtrlCreateInput() function.

2) $file contain the value of ControlID fromGUICtrlCreateInput(). You need to read the ControlID $FileNumber = GUICtrlRead($file)

3) ShellExecute or ShellExecuteWait

#include <GUIConstants.au3>

GUICreate(" Priors Search", 320, 120)
$file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 7)
$btn = GUICtrlCreateButton("Search", 40, 75, 60, 20)

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $FileNumber = GUICtrlRead($file)
            ExitLoop
    EndSelect
WEnd
If $FileNumber >= 1 And $FileNumber <= 2000 Then
    MsgBox(4096, "results", "This nubmer is between 1 and 2000")
EndIf
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

1) You need to add $ES_NUMBER to GUICtrlCreateInput() function.

2) $file contain the value of ControlID fromGUICtrlCreateInput(). You need to read the ControlID $FileNumber = GUICtrlRead($file)

3) ShellExecute or ShellExecuteWait

#include <GUIConstants.au3>

GUICreate(" Priors Search", 320, 120)
$file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 7)
$btn = GUICtrlCreateButton("Search", 40, 75, 60, 20)

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $FileNumber = GUICtrlRead($file)
            ExitLoop
    EndSelect
WEnd
If $FileNumber >= 1 And $FileNumber <= 2000 Then
    MsgBox(4096, "results", "This nubmer is between 1 and 2000")
EndIf
Cool, it is starting to click now. Another question. I have 571 files which means I will need to write 571 IF THEN statements. Is there a better way to do this or is that an OK route to go? Edited by williamk
Link to comment
Share on other sites

  • Moderators

You could have all the files in an array and do a For / Next loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

maybe...

#include <GUIConstants.au3>

GUICreate(" Priors Search", 320, 120)
$file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 7)
$btn = GUICtrlCreateButton("Search", 40, 75, 60, 20, $BS_DEFPUSHBUTTON )

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            Open_File()
    EndSelect
WEnd

Func Open_File()
    $FileNumber = GUICtrlRead($file)
    
    For $x = 1 to 1142000 Step 2000
    If $FileNumber >= $x And $FileNumber <= ($x -1) + 2000 Then
        ;ShellExecute( $x & "-" & (($x -1) + 2000) & ".pdf")
        MsgBox(4096, "results", $x & "-" & (($x -1) + 2000) & ".pdf")
    EndIf
    Next
EndFunc

EDIT: updated to ( minus 1 ) in the pdf name

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate(" Priors Search", 320, 120)
$file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 7)
$btn = GUICtrlCreateButton("Search", 40, 75, 60, 20, $BS_DEFPUSHBUTTON )

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            Open_File()
    EndSelect
WEnd

Func Open_File()
    $FileNumber = GUICtrlRead($file)
    
;No need for a loop when math can do it
    $i = Floor(($i - 1 ) / 2000) * 2000
    $start = $i + 1
    $end = $i + 2000

    $filname = $start & "-" & $end & ".pdf"
   ;ShellExecute( $filename)
    MsgBox(4096, "results", $filename)
    EndIf
    Next
EndFunc

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
Share on other sites

#include <GUIConstants.au3>
 
 GUICreate(" Priors Search", 320, 120)
 $file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
 GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
 GUICtrlSetLimit(-1, 7)
 $btn = GUICtrlCreateButton("Search", 40, 75, 60, 20, $BS_DEFPUSHBUTTON )
 
 GUISetState()
 
 $msg = 0
 While $msg <> $GUI_EVENT_CLOSE
     $msg = GUIGetMsg()
     Select
         Case $msg = $btn
             Open_File()
     EndSelect
 WEnd
 
 Func Open_File()
     $FileNumber = GUICtrlRead($file)
     
;No need for a loop when math can do it
     $i = Floor(($i - 1 ) / 2000) * 2000
     $start = $i + 1
     $end = $i + 2000
 
     $filname = $start & "-" & $end & ".pdf"
   ;ShellExecute( $filename)
     MsgBox(4096, "results", $filename)
     EndIf
     Next
 EndFunc

your math does this,,,,

>Running AU3Check (1.54.5.0) params: from:C:\Program Files\AutoIt3\beta

C:\Program Files\AutoIt3\beta\Examples\Helpfile\SoundPlay2.au3(24,20) : WARNING: $i: possibly used before declaration.

$i = Floor(($i -

~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\beta\Examples\Helpfile\SoundPlay2.au3(30,38) : WARNING: $filename: possibly used before declaration.

MsgBox(4096, "results", $filename)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\beta\Examples\Helpfile\SoundPlay2.au3(31,5) : ERROR: syntax error

EndIf

~~~~^

C:\Program Files\AutoIt3\beta\Examples\Helpfile\SoundPlay2.au3(30,38) : ERROR: $filename: undeclared global variable.

MsgBox(4096, "results", $filename)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\beta\Examples\Helpfile\SoundPlay2.au3 - 2 error(s), 2 warning(s)

!>AU3Check ended.rc:2

>Exit code: 0 Time: 2.205

8)

NEWHeader1.png

Link to comment
Share on other sites

My bad

#include <GUIConstants.au3>

GUICreate(" Priors Search", 320, 120)
$file = GUICtrlCreateInput("", 10, 5, 300, 20, $ES_NUMBER)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 7)
$btn = GUICtrlCreateButton("Search", 40, 75, 60, 20, $BS_DEFPUSHBUTTON )

GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
     $msg = GUIGetMsg()
     Select
         Case $msg = $btn
             Open_File()
     EndSelect
WEnd

Func Open_File()
     $FileNumber = GUICtrlRead($file)
     
    ;No need for a loop when math can do it
     $i = Floor(($FileNumber - 1 ) / 2000) * 2000
     $start = $i + 1
     $end = $i + 2000

     $filename = $start & "-" & $end & ".pdf"
   ;ShellExecute( $filename)
     MsgBox(4096, "results", $filename)
     
EndFunc

(Forgot to change the $i to $FileNumber and a typo with the $filename)

Edited by Shevilie

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

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