Jump to content

GUI Choices - Message Loop or On Event


Jslim
 Share

Recommended Posts

Hi.

I've scoured the forum interwebs the last few days trying to figure out which mode I want to use for something I am writing. This is spawned by the fact that I cannot get the second button to work on the GUI I am creating. To give you an idea before what I am struggling with before posting my code:

1. I am using a loop now.  - Basically my code asks for an input and then has a button to do some stuff with that input.

2. After the initial stuff is complete the GUI then shows three more inputs below the first one. I am also pulling the data that is user entered from the first input into a field in the first field of the second line of inputs.

3. The second input has a drop down of some array variables.

4. The third input has the result of a SQL query that is using the first inputs data as a parameter.

5. The conundrum - when I try to run some stuff using all of the second set of inputs, with the use of a second button the loop I tried to use caused my first button not to work.

I am thinking I'm going wrong because I am not defining the second buttons function in the first loop...

Any help would be appreciated and I apologize in advance if it’s something totally obvious. It took some serious pride swallowing to even post my question here.

forum.au3

Link to comment
Share on other sites

  • Moderators

I think you need to first go back over your code and do some cleanup, I see an EndSelect with no Select statement - and you have a LOT of code in an open-ended While statement (you may have had it closed at one point and then gotten turned around while troubleshooting).

Edit: Scratch that, I see it was simply that your function was not closed properly.

Have you tried defining all of your controls in the beginning, and simply making them visible on certain triggers? Something like this (removed the SQL code to simplify):

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <String.au3>
#include <file.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>

Global $pstool, $code, $grab, $jobsdrop, $msg, $readcode, $oMyError, $sqlCon, $NameList, $sqlRs, $code2, $desc, $OptionName, $go, $readDesc, $setmatra
Global $server = "usoXXXXX"
Global $db = "DB"
Global $username = "******"
Global $password = "*****"

;create GUI
$pstool = GUICreate("PS Job Code Fixer", 400, 300, 100, 150, -1, 0x00000018)
GUICtrlCreateLabel("Enter Invalid Job Code", 140,  20)
$code = GUICtrlCreateInput("", 160, 51, 55, 22)
$grab = GUICtrlCreateButton("Lookup", 152, 88, 70, 25)
GUICtrlCreateLabel("Insert into PSTran", 148,  130)

$psCodelbl = GUICtrlCreateLabel("PSCode", 22, 170)
    GUICtrlSetState($psCodelbl, $GUI_HIDE)
$code2 = GUICtrlCreateInput($readcode, 20, 190, 55, 22)
    GUICtrlSetState($code2, $GUI_HIDE)
$matraCodelbl = GuiCtrlCreateLabel("matraCode", 121, 170)
    GUICtrlSetState($matraCodelbl, $GUI_HIDE)
$setmatra = GUICtrlCreateCombo("", 120, 190, 104, 20)
    GUICtrlSetData($setmatra, $jobsdrop)
    GUICtrlSetState($setmatra, $GUI_HIDE)
$matraDesclbl = GUICtrlCreateLabel("matraDesc", 270, 170)
    GUICtrlSetState($matraDesclbl, $GUI_HIDE)
$desc = GuiCtrlCreateInput($OptionName, 270, 190, 104, 20)
    GUICtrlSetState($desc, $GUI_HIDE)
$go = GUICtrlCreateButton("Insert", 152, 240, 70, 25)
    GUICtrlSetState($go, $GUI_HIDE)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $grab
            GUICtrlSetState($psCodelbl, $GUI_SHOW)
            GUICtrlSetState($code2, $GUI_SHOW)
            GUICtrlSetState($matraCodelbl, $GUI_SHOW)
            GUICtrlSetState($setmatra, $GUI_SHOW)
            GUICtrlSetState($matraDesclbl, $GUI_SHOW)
            GUICtrlSetState($desc, $GUI_SHOW)
            GUICtrlSetState($go, $GUI_SHOW)
            ;rest of code
    EndSwitch
WEnd
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

No I haven't tried that method but looking at it makes total sense.

Let me give that a whirl. I'll let you know how it works out. Thanks so much for the help and speedy response! I kept lurking on the forum hoping someone would take pity on me and give me some much needed direction. :)

Link to comment
Share on other sites

Hello Sir.

Although the code works in the way that it shows the GUI per function it seems I lost something in translation. And I'm not sure why. I see where we are pulling in the variable for $readcode but I don't see the GUICtrlRead function that was in my original script to define it. It was located right after the While loop I was using. I figured maybe since you removed some portions of the script to make it easier to see that it was removed by accident. However when I try to insert the GUICtrlRead into the script above I am not getting the desired results. It's not pulling it into the GUICtrlInput as I would expect. I added a MsgBox after the Case $grab to see what value the $readcode was showing and its blank.. :( I have commented out some code to simplify the script to troubleshoot but it has the additions from above.

I have attached my code thus far.

Thanks.

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <String.au3>
#include <file.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>


Global $pstool, $code, $grab, $jobsdrop, $msg, $readcode, $oMyError, $sqlCon, $NameList, $sqlRs, $code2, $desc, $OptionName, $go, $readDesc, $setmatra
Global $psCodelbl, $psTranlbl, $matraCodelbl, $matraDesclbl
Global $server = "usoXXXXX"
Global $db = "DB"
Global $username = "******"
Global $password = "*****"


;set up array for jobcodes

Global $jobs[8] = ["NULL", "0 - Administrator", "2 - Manager", "3 - Team Captain", "11 - Cashier", "13 - Reports", "21 - Field Services", "22 - Service Desk" ]
   $jobsdrop = ""
For $i = 0 To UBound($jobs) - 1
   $jobsdrop &= "|" & $jobs[$i]
Next


_Setup()
Func _Setup()
Global $NULL = "NULL"
Global $admin = "0 - Administrator"
Global $manager = "2 - Manager"
Global $TC = "3 - Team Captain"
Global $cashier = "11 - Cashier"
Global $reports = "13 - Reports"
Global $FS = "21 - Field Services"
Global $SD = "22 - Service Desk"


;create GUI
$pstool = GUICreate("PS Job Code Fixer", 400, 300, 100, 150, -1, 0x00000018)
GUICtrlCreateLabel("Enter Invalid Job Code", 140,  20)
$code = GUICtrlCreateInput("", 160, 51, 55, 22)
$readcode = GUICtrlread($code, 1)
$grab = GUICtrlCreateButton("Lookup", 152, 88, 70, 25)


;$psTranlbl = GUICtrlCreateLabel("Insert into PSTran", 148,  130)
;GUICtrlSetState($psTranlbl, $GUI_HIDE)

;$psCodelbl = GUICtrlCreateLabel("PSCode", 22, 170)
;GUICtrlSetState($psCodelbl, $GUI_HIDE)
;$code2 = GUICtrlCreateInput($readcode, 20, 190, 55, 22)
;$readcode = GUICtrlread($code, 1)
;GUICtrlSetState($code2, $GUI_HIDE)
;$matraCodelbl = GuiCtrlCreateLabel("matraCode", 121, 170)
;GUICtrlSetState($matraCodelbl, $GUI_HIDE)
;$setmatra = GUICtrlCreateCombo("", 120, 190, 104, 20)
;GUICtrlSetData($setmatra, $jobsdrop)
;GUICtrlSetState($setmatra, $GUI_HIDE)
;$matraDesclbl = GUICtrlCreateLabel("matraDesc", 270, 170)
;GUICtrlSetState($matraDesclbl, $GUI_HIDE)
;$go = GUICtrlCreateButton("Insert", 152, 240, 70, 25)
;GUICtrlSetState($go, $GUI_HIDE)



GUISetState()



While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE

            Exit

        Case $grab
MsgBox(0, "test", $readcode, 5)
            ;GUICtrlSetState($psCodelbl, $GUI_SHOW)

            ;GUICtrlSetState($code2, $GUI_SHOW)

            ;GUICtrlSetState($matraCodelbl, $GUI_SHOW)

            ;GUICtrlSetState($setmatra, $GUI_SHOW)

            ;GUICtrlSetState($matraDesclbl, $GUI_SHOW)

            ;GUICtrlSetState($desc, $GUI_SHOW)

            ;GUICtrlSetState($go, $GUI_SHOW)





$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$sqlCon = ObjCreate("ADODB.Connection")
$sqlCon.Open("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";")
$NameList=""

If @error Then
MsgBox(0, "ERROR", "Failed to connect to the database")
Exit
Else
MsgBox(0, "Success!", "Connection to database successful!")
EndIf

$sqlRs = ObjCreate("ADODB.Recordset")
If Not @error Then
    $sqlRs.open ("select job_desc from vw_matra_merch where job = " & $readcode, $sqlCon)
    $OptionName = $sqlRs.Fields ('job_desc' ).Value
    MsgBox(0, "Record Found", "Job_desc  " & $OptionName)
    $sqlRs.MoveNext
    $sqlRs.close
 EndIf

EndSwitch
WEnd


Exit

 

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