Jump to content

GUI works only one time


panuys
 Share

Recommended Posts

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 
#include 
#include 
#include 
#include 
#include 
#include 

Global Const $TitleTxt = "EEPROM Tests", $Ver = "101.00" 
Global $AssyType 

Global $inpHPartNum, $inpHSerialNum 
Global $TestRes 
Global $inpSerialNum[4], $inpPartNum[4] 
Global $SerLabel[4], $PartLabel[4] 

Global $btnExit, $btnStart 

;Opt("GUIDataSeparatorChar", "|") 
Opt("GUICloseOnESC", 1) 
;Create main window.----------------------------------------------------------------------------- 
Opt("GUIOnEventMode", 1) ;1: enable OnEventMode 

GUICreate($TitleTxt, 500, 540) ;create main dialog box 
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;if [EXIT] is pressed then exit 

GUICtrlCreateLabel ("Script Rev - "&$Ver, 1010, 3, 90) ;display rev label 
GUICtrlSetColor(-1,0xff0000) ; red 

;Create ComboBox ----------------------------------------------------------------------------------------------- 

GUICtrlCreateLabel ("Assembly to Test", 80, 10, 82) 
$AssyType = GUICtrlCreateCombo ( "", 170, 10, 108, 88) 
GUICtrlSetData(-1, "747-1111|747-2222|747-3333","747-2222") 

$btnStart = GUICtrlCreateButton ("START", 75, 370 ,80, 25) ;Create Start button 
GUICtrlSetOnEvent($btnStart, "StartClicked") 

$btnExit = GUICtrlCreateButton ("EXIT", 300, 370, 80, 25) ;Create Exit button 
GUICtrlSetOnEvent($btnExit, "CLOSEClicked") 

;Top Level Assy ----------------------------------------------------------------------------------- 

GUICtrlCreateLabel ("TOP Part Number", 210, 60, 98) 
$inpHPartNum = GUICtrlCreateInput ( GUICtrlRead($AssyType), 310, 60, 75, 18) ;Create Input for Part Number 

GUICtrlCreateLabel ("TOP Serial Number", 210, 40, 98) 
$inpHSerialNum = GUICtrlCreateInput ( "", 310, 40, 50, 18) ;Create Input for Serial Number 
GUICtrlSetLimit(-1, 6) ; to limit the entry to 6 chars 
GUICtrlSetOnEvent($inpHSerialNum, "StartClicked") 

$TestRes = GUICtrlCreateEdit("", 10, 410, 400, 120, BitOr($ES_AUTOVSCROLL,$WS_VSCROLL,$WS_HSCROLL)) 
GUICtrlSetLimit ( $TestRes, 1000000 ) 
GUICtrlSetOnEvent($TestRes, "StartClicked") ; WHY shows when [START] not clicked yet 

GUICtrlSetOnEvent($AssyType, "SetUpApp") 

GUISetState () 

; Just idle around 
While 1 
Sleep(10) 
WEnd 

Func CLOSEClicked() 
Exit 
EndFunc 

Func SetUpApp() 

Local $j 
GUICtrlSetData($TestRes, "") ;clear for new data entry 
GUICtrlSetData($inpHSerialNum, "") ;clear for new data entry 

Local $top = 110 

For $j = 1 to 3 

$PartLabel[$j] = GUICtrlCreateLabel ("Part Number_Bd" & $j, 190, $top, 98) 
$inpPartNum[$j] = GUICtrlCreateInput (StringTrimRight(GUICtrlRead($AssyType),2), 282, $top, 85, 18) 

$SerLabel[$j] = GUICtrlCreateLabel ("Serial Number_Bd" & $j, 10, $top, 98) 
$inpSerialNum[$j] = GUICtrlCreateInput ( "", 110, $top, 70, 18) ; WHY previous selected asy. SN shows 
GUICtrlSetOnEvent($inpSerialNum[$j], "StartClicked") 


$top = $top + 30 ; controls spacing 

Next 

$j = 0 

EndFunc ;SetUpApp 

Func StartClicked() ;[Start] clicked 

GUICtrlSetData($TestRes, "") ;clear for new data entry 

GUICtrlSetData($TestRes, StringFormat("TOP Serial Number=%s\r\n", GUICtrlRead($inpHSerialNum)), 1) 

Local $i 

For $i = 1 To 3 ;The for loop only works the first selection from ComboBox. 
GUICtrlSetData($TestRes, StringFormat("Serial Number_Bd" & $i & "=%s\r\n", GUICtrlRead($inpSerialNum[$i])), 1) 
Next 

$i= 0 

EndFunc ;StartClicked 



; --------------------------------------------------------------------------------------------------------
This script has the following bugs:

Data are shown in the EDIT CONTROL area (Should Be only when the START button is clicked).

All INPUT CONTROLs are OK only the first time when any item selected from the drop-down of the ComboBox but the following attemps, why instead of BLANK before any data entry, previous values are shown after the CONTROLs are BLANK for awhile? and why the Board Serial Number are not accepted.

Link to comment
Share on other sites

  • Moderators

panuys,

Welcome to the AutoIt forum. :)

Data are shown in the EDIT CONTROL area (Should Be only when the START button is clicked).

Then you need to remove the GUICtrlSetOnEvent(ControlID, "StartClicked") lines from everything other than the "Start" button. :idiot:

why instead of BLANK before any data entry, previous values are shown after the CONTROLs are BLANK for awhile?

Because you are creating new inputs each time and the old ones are showing through. The easy way to solve this is to delete the labels and inputs each time you run the SetUpApp function. A better way to solve it would be to create the labels and inputs only once and then empty them each time. :idiot:

I hope this does what you want now - look for the <<<<<<<<<<<<<<< lines:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global Const $TitleTxt = "EEPROM Tests", $Ver = "101.00"
Global $AssyType

Global $inpHPartNum, $inpHSerialNum
Global $TestRes
Global $inpSerialNum[4], $inpPartNum[4]
Global $SerLabel[4], $PartLabel[4]

Global $btnExit, $btnStart

;Opt("GUIDataSeparatorChar", "|")
Opt("GUICloseOnESC", 1)
;Create main window.-----------------------------------------------------------------------------
Opt("GUIOnEventMode", 1) ;1: enable OnEventMode

GUICreate($TitleTxt, 500, 540) ;create main dialog box
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;if [EXIT] is pressed then exit

GUICtrlCreateLabel("Script Rev - " & $Ver, 1010, 3, 90) ;display rev label
GUICtrlSetColor(-1, 0xff0000) ; red

;Create ComboBox -----------------------------------------------------------------------------------------------

GUICtrlCreateLabel("Assembly to Test", 80, 10, 82)
$AssyType = GUICtrlCreateCombo("", 170, 10, 108, 88)
GUICtrlSetData(-1, "747-1111|747-2222|747-3333", "747-2222")
GUICtrlSetOnEvent($AssyType, "SetUpApp")

$btnStart = GUICtrlCreateButton("START", 75, 370, 80, 25) ;Create Start button
GUICtrlSetOnEvent($btnStart, "StartClicked") ; This is where you register "StartClicked" <<<<<<<<<<<<<<<<<<<

$btnExit = GUICtrlCreateButton("EXIT", 300, 370, 80, 25) ;Create Exit button
GUICtrlSetOnEvent($btnExit, "CLOSEClicked")

;Top Level Assy -----------------------------------------------------------------------------------

GUICtrlCreateLabel("TOP Part Number", 210, 60, 98)
$inpHPartNum = GUICtrlCreateInput(GUICtrlRead($AssyType), 310, 60, 75, 18) ;Create Input for Part Number

GUICtrlCreateLabel("TOP Serial Number", 210, 40, 98)
$inpHSerialNum = GUICtrlCreateInput("", 310, 40, 50, 18) ;Create Input for Serial Number
GUICtrlSetLimit(-1, 6) ; to limit the entry to 6 chars
;GUICtrlSetOnEvent($inpHSerialNum, "StartClicked") ; Delete this <<<<<<<<<<<<<<<<<<<<<<<<<<<<

$TestRes = GUICtrlCreateEdit("", 10, 410, 400, 120, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $WS_HSCROLL))
GUICtrlSetLimit($TestRes, 1000000)
;GUICtrlSetOnEvent($TestRes, "StartClicked") ; WHY shows when [START] not clicked yet ; Delete this <<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetState()

; Just idle around
While 1
    Sleep(10)
WEnd

Func CLOSEClicked()
    Exit
EndFunc   ;==>CLOSEClicked

Func SetUpApp()

    ;Local $j ; variables in For...Next loops are automatically Local <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($TestRes, "") ;clear for new data entry
    GUICtrlSetData($inpHSerialNum, "") ;clear for new data entry

    Local $top = 110

    For $j = 1 To 3

        GUICtrlDelete($PartLabel[$j]) ; Delete previous control <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $PartLabel[$j] = GUICtrlCreateLabel("Part Number_Bd" & $j, 190, $top, 98)
        GUICtrlDelete($inpPartNum[$j]) ; Delete previous control <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $inpPartNum[$j] = GUICtrlCreateInput(StringTrimRight(GUICtrlRead($AssyType), 2), 282, $top, 85, 18)

        GUICtrlDelete($SerLabel[$j]) ; Delete previous control <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $SerLabel[$j] = GUICtrlCreateLabel("Serial Number_Bd" & $j, 10, $top, 98)
        GUICtrlDelete($inpSerialNum[$j]) ; Delete previous control <<<<<<<<<<<<<<<<<<<<<<<<<<<<
        $inpSerialNum[$j] = GUICtrlCreateInput("", 110, $top, 70, 18) ; WHY previous selected asy. SN shows
        ;GUICtrlSetOnEvent($inpSerialNum[$j], "StartClicked") ; Delete this <<<<<<<<<<<<<<<<<<<<<<<<<<<<

        $top = $top + 30 ; controls spacing

    Next

    ;$j = 0

EndFunc   ;==>SetUpApp

Func StartClicked() ;[Start] clicked

    GUICtrlSetData($TestRes, "") ;clear for new data entry

    GUICtrlSetData($TestRes, StringFormat("TOP Serial Number=%s\r\n", GUICtrlRead($inpHSerialNum)), 1)

    ;Local $i ; variables in For...Next loops are automatically Local <<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    For $i = 1 To 3 ;The for loop only works the first selection from ComboBox.
        GUICtrlSetData($TestRes, StringFormat("Serial Number_Bd" & $i & "=%s\r\n", GUICtrlRead($inpSerialNum[$i])), 1)
    Next

    ;$i = 0

EndFunc   ;==>StartClicked

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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