fopetesl

Entering user data - remove prompt MsgBox?

7 posts in this topic

#1 ·  Posted (edited)

;===============================================

Func GetScanSettings() ; Read User Input for scan

Local $collectusername, $collectbatch

$UserFile = "Sample.dat" ; Global $UserFile = save this scan's parameters
$datafile = FileOpen($UserFile)
 If( $datafile <> -1) Then
  $collectusername = FileReadLine($datafile, 1)
 EndIf
FileClose($datafile)

; now open a new 'clean' file..
$datafile = FileOpen($UserFile,$FO_OVERWRITE )

;Create GUI
$Main = GUICreate('Enter Sample Detail', 500, 500)

; MsgBox($MB_SYSTEMMODAL, "GetScanSettings", "Is @ line 390!")

Opt("GUICoordMode",1)
 If( $collectusername <> "") Then
   $username = GUICtrlCreateInput($collectusername,100,20,100)
 Else
   $username = GUICtrlCreateInput('',100,20,100)
 EndIf
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$BatchNum = GUICtrlCreateInput("",100,45,100,0)
$BatchNumlabel = GUICtrlCreateLabel('Batch',30,48)
$Button_1 = GUICtrlCreateButton ("OK", 190, 70, 0, 0, 0x0001)
$Button_2 = GUICtrlCreateButton ("Done", 245, 70, 0, 0)

GUISetState (); Run the GUI until the dialog is closed

While 1
    $msg = GUIGetMsg()
    Select
;        Case $msg = $GUI_EVENT_CLOSE
;            Exit
        Case $msg = $Button_1
           If( $collectusername <> "") Then
            $collectusername = GUICtrlRead($username)
           EndIf
            WinSetState('Collect Username and Batch','',@SW_HIDE)
;            WinSetState('','',@SW_HIDE)
            $collectbatch = GUICtrlRead($BatchNum)
            MsgBox(0,'Scan Detail','Username: ' & $collectusername & @CRLF & 'Batch: ' & $collectbatch)
            ExitLoop
         Case $msg = $Button_2
            ExitLoop
    EndSelect
Wend
    GUIDelete($Main)
 FileWrite($datafile,$collectusername & @CRLF & $collectbatch & @CR)
 FileClose($datafile)

EndFunc ;<=== GetScanSetings

I cannot see where the prompt MsgBox is generated. I don't need a second MsgBox.

I tried commenting out WinsetState but that causes the data entering box to disappear but still leaves what would be the 2nd MsgBox.

I clearly do not understand WinSetState in this context

Edit: I was confusing GUI with MsgBox so have solved that question but not why I need WinSetState()

 

Edited by fopetesl
Discovered 2nd MsgBox

The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

I see WinSetState for @SW_HIDE after you press a button.

It's so the GUI hides away instead of staying on screen after you activate its controls.

An example how I  use it would be a GUI to install programs, and then a MsgBox() when its done to let you know the install is done.

Instead of leaving the GUI up on screen the entire time while programs are installing in the background I use the same WinSetState() command to take it off screen.

Share this post


Link to post
Share on other sites
2 hours ago, ViciousXUSMC said:

I see WinSetState for @SW_HIDE after you press a button.

It's so the GUI hides away instead of staying on screen after you activate its controls.

An example how I  use it would be a GUI to install programs, and then a MsgBox() when its done to let you know the install is done.

Instead of leaving the GUI up on screen the entire time while programs are installing in the background I use the same WinSetState() command to take it off screen.

I see what you're saying but the function just doesn't work if I either comment out WinSetState() or remove the 1st text, "Collect Username & Batch".

So the WinSetState() is necessary but I do not understand why.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

Hey,

Can you try the following code and tell me if that works the way you want it to?

 

#include <FileConstants.au3>
Opt("MustDeclareVars", 1)

_GetScanSettings()


Func _GetScanSettings()

    Local $sFile, $hFile
    Local $sUsername, $sBatch
    Local $idMsg, $idInpUser, $idInpBatch, $idBtnOK, $idBtnDone

    $sFile = "Sample.dat"
    $hFile = FileOpen($sFile)
    If $hFile <> -1 Then $sUsername = FileReadLine($hFile, 1)
    FileClose($hFile)

    $hFile = FileOpen($sFile, $FO_OVERWRITE)

    GUICreate('Enter Sample Detail', 500, 500)

    $idInpUser = GUICtrlCreateInput("", 100, 20, 100)
    GUICtrlSetData($idInpUser, $sUsername)
    GUICtrlCreateLabel("Username", 30, 23)

    $idInpBatch = GUICtrlCreateInput("",100, 45, 100, 0)
    GUICtrlCreateLabel("Batch", 30, 48)

    $idBtnOK = GUICtrlCreateButton ("OK", 190, 70, 0, 0, 0x0001)
    $idBtnDone = GUICtrlCreateButton ("Done", 245, 70, 0, 0)

    GUISetState()


    While 1
        $idMsg = GUIGetMsg()

        Switch $idMsg
            Case $idBtnOK
                $sUsername = GUICtrlRead($idInpUser)
                $sBatch = GUICtrlRead($idInpBatch)
                MsgBox(0, "Scan Detail", "Username: " & $sUsername & @CRLF & _
                    "Batch: " & $sBatch)
                ExitLoop

             Case $idBtnDone
                ExitLoop

        EndSwitch
    Wend


    GUIDelete()
    FileWrite($hFile, $sUsername & @CRLF & $sBatch & @CR)
    FileClose($hFile)

EndFunc

 

Share this post


Link to post
Share on other sites

Thanks, Floops. Looks good but still doesn't help me understand WinSetState() :(

I'll test it fully tomorrow.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

if you want to press the msgbox without exiting your gui, just remove the Exitloop under $msg = $Button_1, or just delete the msgbox if you dont want any testing to be done.

#include <FileConstants.au3>
Run("notepad.exe")
Sleep(100)
GetScanSettings()
;===============================================

Func GetScanSettings() ; Read User Input for scan

Local $collectusername, $collectbatch

$UserFile = "Sample.dat" ; Global $UserFile = save this scan's parameters
$datafile = FileOpen($UserFile)
 If( $datafile <> -1) Then
  $collectusername = FileReadLine($datafile, 1)
 EndIf
FileClose($datafile)

; now open a new 'clean' file..
$datafile = FileOpen($UserFile,$FO_OVERWRITE )

;Create GUI
$Main = GUICreate('Enter Sample Detail', 500, 500)

; MsgBox($MB_SYSTEMMODAL, "GetScanSettings", "Is @ line 390!")

Opt("GUICoordMode",1)
 If( $collectusername <> "") Then
   $username = GUICtrlCreateInput($collectusername,100,20,100)
 Else
   $username = GUICtrlCreateInput('',100,20,100)
 EndIf
$usernamelabel = GUICtrlCreateLabel('Username',30,23)
$BatchNum = GUICtrlCreateInput("",100,45,100,0)
$BatchNumlabel = GUICtrlCreateLabel('Batch',30,48)
$Button_1 = GUICtrlCreateButton ("OK", 190, 70, 0, 0, 0x0001)
$Button_2 = GUICtrlCreateButton ("Done", 245, 70, 0, 0)

GUISetState (@SW_SHOW); Run the GUI until the dialog is closed

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3
            Exit
        Case $msg = $Button_1
           If( $collectusername <> "") Then
            $collectusername = GUICtrlRead($username)
           EndIf
            WinSetState("Untitled - Notepad", "", @SW_HIDE); this will hide the notepad
;            WinSetState('','',@SW_HIDE)
            $collectbatch = GUICtrlRead($BatchNum)
            MsgBox(0,'Scan Detail','Username: ' & $collectusername & @CRLF & 'Batch: ' & $collectbatch); this is the msgbox that pops out if you press ok button in your gui
;~             ExitLoop <------ you need to remove this to keep your script running. unless you have another functions
         Case $msg = $Button_2
            ExitLoop
    EndSelect
Wend
    GUIDelete($Main)
 FileWrite($datafile,$collectusername & @CRLF & $collectbatch & @CR)
 FileClose($datafile)

EndFunc ;<=== GetScanSetings

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

Thanks, guys. All working fine now,

even if WinSetState() seems a puzzle.


The most powerful number in the Universe.  Zero.

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