Jump to content

I need help with GUI/Scripting Combination


Joosh
 Share

Recommended Posts

Okay, first off I will tell you my situation, I work for a software retail company and my boss has asked me to compile a program that he can put on his laptop to record sales at a LAN, now I did this but I did it all as a script using Input Boxes he wants me to have a drop down list or a selection list for the Input Box Cash or Credit Card? so the idea of the program is that it will ask three questions, 1. What is the barcode Number? (This is already interfaced with the barcode reader and will read the barcode into the script then press ok. 2. What is the price? easily manually entered as it is never really longer than 5 or so digits, and 3. Cash or Credit, this is where i have become stuck because i was using only scripts not GUI, is it only possible to do a list/drop down/combo box with GUI or is it possible with just scripting??

If not possible this is what i currently have,

#include <GUIConstants.au3>

GUICreate("Cash or Credit Card") ; will create a dialog box that when displayed is centered

$n1=GUICtrlCreateList ("", 10,10,-1,100 )

GUICtrlSetData(-1,"Cash|Credit Card", "item2")

$n2=GUICtrlCreateButton ("OK",0,100)

GUICtrlSetState(-1,$GUI_FOCUS) ; the focus is on this button

GUISetState () ; will display an empty dialog box

; Run the GUI until the dialog is closed

Do

$msg = GUIGetMsg()

if $msg = $n2 then

msgbox(0,"This is What you have chosen", GUICtrlRead($n1)) ; display the value

endif

Until $msg = $GUI_EVENT_CLOSE

BUT!!! I need this to run as part of the script as the script has duties to perform after this sequence, I need it to save the Cash or Credit Card (Whichever was chosen) as a variable so it can be used later in my script, CAN ANYONE PLEASE HELP ME!!!???

Link to comment
Share on other sites

put it in a function and return a value. In your script, call the function and save the return in a variable.

See the Func...EndFunc structure in the help file.

Link to comment
Share on other sites

Ummmm I am really confused here, If anyone could show me an example or tweak mine so it would be set to run as a function and return the Credit Card or Cash as a variable $c then i would really appreciate it. The function needs to be inserted as part of a script with other sequences to be run afterwards, i would really appreciate any help. Joosh

#include <GUIConstants.au3>

GUICreate("Cash or Credit Card") ; will create a dialog box that when displayed is centered

$n1=GUICtrlCreateList ("", 10,10,-1,100 )

GUICtrlSetData(-1,"Cash|Credit Card", "item2")

$n2=GUICtrlCreateButton ("OK",0,100)

GUICtrlSetState(-1,$GUI_FOCUS) ; the focus is on this button

GUISetState () ; will display an empty dialog box

; Run the GUI until the dialog is closed

Do

$msg = GUIGetMsg()

if $msg = $n2 then

msgbox(0,"This is What you have chosen", GUICtrlRead($n1)) ; display the value

endif

Until $msg = $GUI_EVENT_CLOSE

Link to comment
Share on other sites

Ummmm I am really confused here, If anyone could show me an example or tweak mine so it would be set to run as a function and return the Credit Card or Cash as a variable $c then i would really appreciate it. The function needs to be inserted as part of a script with other sequences to be run afterwards, i would really appreciate any help. Joosh

<{POST_SNAPBACK}>

Quick tip - when posting on this forum, put your code in CODE or CODEBOX tags - it's a little easier to read that way :)

So take all your code, and put it in a function. At the end of the function, RETURN a value.

#Include <GuiList.au3>
#include <GUIConstants.au3>

Func CashOrCredit()
    Local $msg, $Return = -1, $Selected, $n1, $n2
    GUICreate("Cash or Credit Card"); will create a dialog box that when displayed is centered

    $n1=GUICtrlCreateList ("", 10,10,-1,100 )

    GUICtrlSetData(-1,"Cash|Credit Card", "item2")

    $n2=GUICtrlCreateButton ("OK",0,100)
    GUICtrlSetState($n2, $GUI_DisAble)
    GUICtrlSetState(-1,$GUI_FOCUS); the focus is on this button

    GUISetState (); will display an empty dialog box
   ; Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
        If $msg = $n1 Then;the list was clicked
            If _GUICtrlListSelectedIndex($n1) <> $LB_ERR Then;items are selected
                GUICtrlSetState($n2, $GUI_Enable)
            Else
                GUICtrlSetState($n2, $GUI_Disable)
            EndIf
        EndIf
        If $msg = $n2 then;OK Button was clicked
            $Selected = _GUICtrlListSelectedIndex($n1);get the index of the selected item
            If $Selected <> $LB_ERR Then;items are indeed selected
                $Return = $Selected + 1;return a 1-based index
            EndIf
        EndIf
        If $msg = $GUI_EVENT_CLOSE Then
            $Return = 0
        EndIf
    Until $Return >= 0
    GUIDelete()
    Return $Return
EndFunc

In your script, call the function and save it's return in a value:

$c = CashOrCredit()
Select
  Case $c = 0
    MsgBox(0,'Warning','User cancelled selection')
  Case $c = 1
    MsgBox(0,'Info','User selected Cash')
  Case $c = 2
    MsgBox(0,'Info','User selected Credit')
  Case Else
    MsgBox(0,'Error','Something weird happened')
EndSelect
Link to comment
Share on other sites

Okay i have done all of that now but i get an error that reads

Line 398 (File "C:\Program Files\AutoIt3\Include\GuiList.au3"):

Local $p = DllStructCreate ($RECT)

Local $p = ^ ERROR

Error: Unknown function name.

Any Ideas, i finish in 2 hours so any help before then would be great :)

Link to comment
Share on other sites

Is there anyway to open a presaved txt document in a single line command?

I have tried run("C:\Program Files\test.txt") as an example but it doesnt load it gives me the error Unable to Execute External Program

Link to comment
Share on other sites

Ummm how would i save the return as a variable please I am very new to GUI although I am somewhat experienced In Scripting

<{POST_SNAPBACK}>

Not experienced enough to know how to create a function that returns a value and to get the value.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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