Jump to content
Sign in to follow this  
GlennRogers

My first GUI (Struggling)

Recommended Posts

GlennRogers

Hi people I'm having a bit of trouble with the functionality of this GUI im making. I'm going to use the brand part later on so not too concerned about that. When I input a value into the SKU field I want to be able to click the OK button which will close the GUI and continue with the rest of the script but store the input as a variable(at the moment pushing the button does nothing). Also when Clicking the red X or the cancel button I want it to quit the whole script, not just close the GUI.

Edit: I also want to wait for the OK button to be pressed before continuing, not just keep running the rest of the script in the background.

I'm really new to this sort of stuff so not too sure what im doing :(

 

GUI.jpg

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <Process.au3>


$oIE = _IECreate("http://sca2k8wmwp3/wmweb/main.asp", 1)
_IELoadWait($oIE, 1000)
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)

_IELoadWait($oIE, 1000)


Local $fraBottom = _IEFrameGetObjByName($oIE, "fraBottom")
Local $fraRight = _IEFrameGetObjByName($fraBottom, "fraRight")
Local $fraNavigator = _IEFrameGetObjByName($fraBottom, "fraNavigator")
Local $fraData = _IEFrameGetObjByName($fraRight, "fraData")



#region ### START Koda GUI section ### Form=
Global $Choose = GUICreate("SKU and product brand", 399, 314, 409, 311)
Global $SCA = GUICtrlCreateRadio("SCA/V1", 200, 192, 65, 17)
Global $RAY = GUICtrlCreateRadio("RAYS/V1", 296, 192, 65, 17)
Global $GCC = GUICtrlCreateRadio("GCC/V1", 200, 232, 65, 17)
Global $BCF = GUICtrlCreateRadio("BCF/V1", 296, 232, 65, 17)
Global $OK = GUICtrlCreateButton("OK", 72, 272, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 216, 272, 75, 25)
Global $Label1 = GUICtrlCreateLabel("Enter a SKU and choose which brand it belongs to.", 16, 96, 246, 33)
Global $input = GUICtrlCreateInput("", 48, 160, 121, 21)
Global $Label2 = GUICtrlCreateLabel("SKU:", 16, 160, 29, 17)
Global $Label3 = GUICtrlCreateLabel("Brand:", 200, 160, 35, 17)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\GlennR\Desktop\hello555.bmp", 176, 8, 217, 73)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###



GUISetState()

Do
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $OK
            $sKey = '"' & GUICtrlRead($input)


            GUICtrlSetState($input, $GUI_FOCUS)

        Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Cancel
            GUIDelete($Choose)

    EndSelect
Until False



Local $TextInput = _IEGetObjByName($fraNavigator, "txtMenuInpt")

_IEAction($TextInput, "focus")
Sleep(1000)
_IEFormElementSetValue($TextInput, "Carton Maintenance")
Sleep(500)
Send("{DOWN}")
Sleep(500)
Send("{DOWN}")
Sleep(500)
Send("{ENTER}")

_IELoadWait($oIE)
Sleep(1000)
_IELoadWait($oIE)
Sleep(8000)

Global $fraCriteria = _IEFrameGetObjByName($fraRight, "fraCriteria")

Call("Criteria")

Func Criteria()

    Local $oForm = _IEFormGetObjByName($fraCriteria, "CRITERIA_FORM")
    Local $oWarehouse = _IEFormElementGetObjByName($oForm, "MANH_CO_DIV")
    _IEFormElementOptionSelect($oWarehouse, "2007", 1, "byValue")


    Local $oFrom = _IEFormElementGetObjByName($oForm, "CR_FROM_STAT_CODE")
    _IEFormElementOptionSelect($oFrom, "10", 1, "byValue")

    Local $oTo = _IEFormElementGetObjByName($oForm, "CR_TO_STAT_CODE")
    _IEFormElementOptionSelect($oTo, "10", 1, "byValue")


    Local $SKU = _IEFormElementGetObjByName($oForm, "SKU_ID_STYLE")
    _IEAction($SKU, "focus")
    Send($sKey)
    Sleep(500)
    Send("{ENTER}")

EndFunc   ;==>Criteria


$sPageContents = _IEBodyReadHTML($fraData)



        Local $iPosStart = StringInStr($sPageContents, $sKey)
        Local $iPosEnd = StringInStr($sPageContents, 'units', 0, 2, $iPosStart)
        Local $sLine = StringMid($sPageContents, $iPosStart, $iPosEnd - $iPosStart)
        Local $sResult = StringRight($sLine, StringLen($sLine) - StringInStr($sLine, '"', 0, -1))
Edited by GlennRogers

Share this post


Link to post
Share on other sites
Melba23

GlennRogers,

A modified version of the script which should do what you want:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <Process.au3>

; IE code removed

Global $Choose = GUICreate("SKU and product brand", 399, 314, 409, 311)
Global $SCA = GUICtrlCreateRadio("SCA/V1", 200, 192, 65, 17)
Global $RAY = GUICtrlCreateRadio("RAYS/V1", 296, 192, 65, 17)
Global $GCC = GUICtrlCreateRadio("GCC/V1", 200, 232, 65, 17)
Global $BCF = GUICtrlCreateRadio("BCF/V1", 296, 232, 65, 17)
Global $OK = GUICtrlCreateButton("OK", 72, 272, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 216, 272, 75, 25)
GUICtrlCreateLabel("Enter a SKU and choose which brand it belongs to.", 16, 96, 246, 33) ; Why store the ControlID if you are not using it later? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $input = GUICtrlCreateInput("", 48, 160, 121, 21)
GUICtrlCreateLabel("SKU:", 16, 160, 29, 17)
GUICtrlCreateLabel("Brand:", 200, 160, 35, 17)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\GlennR\Desktop\hello555.bmp", 176, 8, 217, 73)
GUISetState(@SW_SHOW)

;GUISetState()  ; Just the once will do <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1 ; More often used fopr infinite loops than Do...Until, although there is nothing wrong with so doing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $OK
            ; Read the input <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sKey = '"' & GUICtrlRead($input)
            ; I assume you want to delete the GUI here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            GUIDelete($Choose)
            ; And continue the script by leaving the infinite loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ExitLoop

        Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Cancel
            ; Just exit the script <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Exit
    EndSelect
WEnd

; Just to show we have read it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
MsgBox(0, "Input Content", $sKey)

; IE code removed

;Call("Criteria")
Criteria() ; Just use the function name <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$sPageContents = "fred" ; _IEBodyReadHTML($fraData) ; Force a value <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Local $iPosStart = StringInStr($sPageContents, $sKey) ; You will now have the $sKey value set <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $iPosEnd = StringInStr($sPageContents, 'units', 0, 2, $iPosStart)
Local $sLine = StringMid($sPageContents, $iPosStart, $iPosEnd - $iPosStart)
Local $sResult = StringRight($sLine, StringLen($sLine) - StringInStr($sLine, '"', 0, -1))

; Put functions at the end of the script - much easier to follow then
Func Criteria()

    ; IE code removed

EndFunc   ;==>Criteria
Please ask if the comments are unclear or if you have any additional questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
GlennRogers

Hi Melba. Just trying to figure out how to store a radio button selection as a variable and then use that later on. I have added the green comments where im getting stuck and to explain it.

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <Process.au3>


$oIE = _IECreate(http://hello, 1)
_IELoadWait($oIE, 1000)
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)

_IELoadWait($oIE, 1000)

Local $rbsca = "2007"   ; Values for options in optionselect drop down
Local $rbray = "2009"
Local $rbgcc = "2008"
Local $rbbcf = "5005"
Global $RadioValue = ''
Local $fraBottom = _IEFrameGetObjByName($oIE, "fraBottom")
Local $fraRight = _IEFrameGetObjByName($fraBottom, "fraRight")
Local $fraNavigator = _IEFrameGetObjByName($fraBottom, "fraNavigator")
Local $fraData = _IEFrameGetObjByName($fraRight, "fraData")


Global $Choose = GUICreate("SKU and product brand", 399, 314, 409, 311)
Global $SCA = GUICtrlCreateRadio("SCA/V1", 200, 192, 65, 17)
Global $RAY = GUICtrlCreateRadio("RAYS/V1", 296, 192, 65, 17)
Global $GCC = GUICtrlCreateRadio("GCC/V1", 200, 232, 65, 17)
Global $BCF = GUICtrlCreateRadio("BCF/V1", 296, 232, 65, 17)
Global $OK = GUICtrlCreateButton("OK", 72, 272, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 216, 272, 75, 25)
Global $Label1 = GUICtrlCreateLabel("Enter a SKU and choose which brand it belongs to.", 16, 96, 246, 33)
Global $input = GUICtrlCreateInput("", 48, 160, 121, 21)
Global $Label2 = GUICtrlCreateLabel("SKU:", 16, 160, 29, 17)
Global $Label3 = GUICtrlCreateLabel("Brand:", 200, 160, 35, 17)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\GlennR\Desktop\hello555.bmp", 176, 8, 217, 73)
Global $RadioValue = ''
GUISetState(@SW_SHOW)



While 1 ;
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $OK
            ; Read the input <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sKey = GUICtrlRead($input)



        Case GUICtrlRead($SCA) = 1    ; I want this like an IF statement sort of thing.
            $RadioValue = $rbsca      ; If the $GCC radio button is selected then $RadioValue = "2008"
        Case GUICtrlRead($RAY) = 1
            $RadioValue = $rbray
        Case GUICtrlRead($GCC) = 1
            $RadioValue = $rbgcc
        Case GUICtrlRead($BCF) = 1
            $RadioValue = $rbbcf






            GUIDelete($Choose)

            ExitLoop

        Case $nMsg = $GUI_EVENT_CLOSE Or $nMsg = $Cancel

            Exit
    EndSelect
WEnd



MsgBox(262144, "SKU", $sKey)
Sleep(2000)







Local $TextInput = _IEGetObjByName($fraNavigator, "txtMenuInpt")

_IEAction($TextInput, "focus")
Sleep(1000)
_IEFormElementSetValue($TextInput, "Carton Maintenance")
Sleep(500)
Send("{DOWN}")
Sleep(500)
Send("{DOWN}")
Sleep(500)
Send("{ENTER}")

_IELoadWait($oIE)
Sleep(1000)
_IELoadWait($oIE)
Sleep(8000)

Global $fraCriteria = _IEFrameGetObjByName($fraRight, "fraCriteria")




Local $oForm = _IEFormGetObjByName($fraCriteria, "CRITERIA_FORM")
Local $oWarehouse = _IEFormElementGetObjByName($oForm, "MANH_CO_DIV")
Local $SCAwh = _IEFormElementOptionSelect($oWarehouse, "2007", 1, "byValue")

_IEFormElementOptionSelect($oWarehouse, $RadioValue, 1, "byValue")    ; Will select an option from the dropdown based on which radio button is selected


Local $oFrom = _IEFormElementGetObjByName($oForm, "CR_FROM_STAT_CODE")
_IEFormElementOptionSelect($oFrom, "10", 1, "byValue")

Local $oTo = _IEFormElementGetObjByName($oForm, "CR_TO_STAT_CODE")
_IEFormElementOptionSelect($oTo, "10", 1, "byValue")


Local $SKU = _IEFormElementGetObjByName($oForm, "SKU_ID_STYLE")
_IEAction($SKU, "focus")
Sleep(250)
Send($sKey)
Sleep(500)
Send("{ENTER}")






Func Criteria()
    $sPageContents = _IEBodyReadHTML($fraData)

    Local $iPosStart = StringInStr($sPageContents, $sKey)
    Local $iPosEnd = StringInStr($sPageContents, 'units', 0, 2, $iPosStart)
    Local $sLine = StringMid($sPageContents, $iPosStart, $iPosEnd - $iPosStart)
    Local $sResult = StringRight($sLine, StringLen($sLine) - StringInStr($sLine, '"', 0, -1))


EndFunc   ;==>Criteria

Share this post


Link to post
Share on other sites
Melba23

GlennRodgers,

Just look for the radios being selected:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <IE.au3>
#include <Misc.au3>
#include <Process.au3>

Local $rbsca = "2007" ; Values for options in optionselect drop down
Local $rbray = "2009"
Local $rbgcc = "2008"
Local $rbbcf = "5005"
Global $RadioValue = ''

Global $Choose = GUICreate("SKU and product brand", 399, 314, 409, 311)
GUIStartGroup()
Global $SCA = GUICtrlCreateRadio("SCA/V1", 200, 192, 65, 17)
Global $RAY = GUICtrlCreateRadio("RAYS/V1", 296, 192, 65, 17)
Global $GCC = GUICtrlCreateRadio("GCC/V1", 200, 232, 65, 17)
Global $BCF = GUICtrlCreateRadio("BCF/V1", 296, 232, 65, 17)
GUIStartGroup()
Global $OK = GUICtrlCreateButton("OK", 72, 272, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 216, 272, 75, 25)
GUICtrlCreateLabel("Enter a SKU and choose which brand it belongs to.", 16, 96, 246, 33) ; Again, if you do not use the ControlID again, why store it?
Global $input = GUICtrlCreateInput("", 48, 160, 121, 21)
GUICtrlCreateLabel("SKU:", 16, 160, 29, 17)
GUICtrlCreateLabel("Brand:", 200, 160, 35, 17)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\GlennR\Desktop\hello555.bmp", 176, 8, 217, 73)
GUISetState(@SW_SHOW)

While 1 ;

    Switch GUIGetMsg() ; Switch is much easier to code than Select if all the checks are on the same variable
        Case $GUI_EVENT_CLOSE, $Cancel
            Exit
        Case $OK
            ; Read the input <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $sKey = GUICtrlRead($input)
            GUIDelete($Choose)
            ExitLoop
        Case $SCA
            $RadioValue = $rbsca ; If the $GCC radio button is selected then $RadioValue = "2008"
        Case $RAY
            $RadioValue = $rbray
        Case $GCC
            $RadioValue = $rbgcc
        Case $BCF
            $RadioValue = $rbbcf
    EndSwitch
WEnd

MsgBox(262144, "SKU", $sKey)
MsgBox(262144, "Radio", $RadioValue)
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
GlennRogers

Hi Melba not quit sure what you mean about storing the control ID. I made the gui using KODA.

Share this post


Link to post
Share on other sites
JLogan3o13

He is pointing out that you don't need to assign the variable $Label1 to the label unless you are going to do something with that label later on. Notice how he omits this and just creates the label.


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

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  

×