Jump to content

Clearing input fields?


Edifice
 Share

Recommended Posts

Hello, I have made this GUI that can print the content of the inputfields onto a piece of paper. The user might want to do this twice, with different data, without restarting the program.

Is there any way to reset or empty them all at once?

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <array.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include 'printMGv2.au3';the print UDF for printing using printmg.dll

Global Const $CBS_DROPDOWNLIST = 0x0003, $RED = 0x0000ff, $GREEN = 0x00ff00, $BLUE = 0xff0000, $BLACK = 0x000000
Dim $app_name = "Indlevering"
Dim $client = "ADD-Data "

Dim $row1 = 30
Dim $row2 = $row1 + 30
Dim $row3 = $row2 + 30
Dim $row4 = $row3 + 30
Dim $row5 = $row4 + 30
Dim $rowheight = 20
Dim $colom1 = 20
Dim $colom2 = $colom1 + 120
Dim $colom3 = $colom2 + 120
Dim $colom4 = $colom3 + 120
Dim $smallcolom1 = 30
Dim $smallcolom2 = $smallcolom1 + 80
Dim $smallcolom3 = $smallcolom2 + 80
Dim $smallcolom4 = $smallcolom3 + 80
Dim $smallcolom5 = $smallcolom4 + 80
Dim $smallcolom6 = $smallcolom5 + 80
Dim $smallcolom7 = $smallcolom6 + 80
Dim $colomwidth = 110
Dim $smallwidth = 70

$mainGUI = GUICreate ($client & $app_name, 500, 350)
$clearfields        = GUICtrlCreateButton("Ryd alle felter", 200, 10, 100, 25)
$udskriv        = GUICtrlCreateButton("Udskriv", 200, 300, 100, 25)

$label_modtager     = GUICtrlCreateLabel("Modtager: ",              10,     33,     100,    20,     2)
$combo_modtager     = GUICtrlCreateCombo("Alf",                     110,    30,     70,     20,     $CBS_DROPDOWNLIST) ; create first item
GUICtrlSetData($combo_modtager, "Claus|Lasse|Per|Jacob|Toke") ; add other item
$label_navn         = GUICtrlCreateLabel("Navn:  ",                 10,     58,     100,    20,     2)
$input_name         = GUICtrlCreateInput("",                        110,    55,     300,    20,     0)
$label_tlfnr        = GUICtrlCreateLabel("Telefonnummer:  ",        10,     83,     100,    20,     2)
$input_phonenumber  = GUICtrlCreateInput("",                        110,    80,     150,    20,     0)
$input_other        = GUICtrlCreateInput("",                    270,    80,     140,    20,     0)
$label_indleveret   = GUICtrlCreateLabel("Indleveret produkt:  ",   10,     108,    100,    20,     2)
$combo_indleveret   = GUICtrlCreateCombo("Almindelig PC",           110,    105,    170,    20,     $CBS_DROPDOWNLIST) ; create first item
GUICtrlSetData($combo_indleveret, "Laptop|Hardware|Andet") ; add other item snd set a new default
$chkbx_garanti      = GUICtrlCreateCheckbox("Garantireperation",    10,     130,    100,    20)
$combo_faknr        = GUICtrlCreateCombo("Faktura nr.",             110,    130,    100,    20, 2) ; create first item
GUICtrlSetData($combo_faknr, "Ukendt") ; add other item snd set a new default

$hindleveret = GUICreate ("", 500, 130, 0, 180, $WS_POPUP, $WS_EX_MDICHILD, $mainGUI)
    $hSubTabs = GUICtrlCreateTab (0, 0, 500, 280)
    $hSubTabPage1 = GUICtrlCreateTabItem ("Beskrivelse")
        $check_color_black  = GUICtrlCreateCheckbox("Sort",             $smallcolom1, $row1, $smallwidth, $rowheight)
        $check_color_silver = GUICtrlCreateCheckbox("Sølv",            $smallcolom2, $row1, $smallwidth, $rowheight)
        $check_color_blue   = GUICtrlCreateCheckbox("Blå",                 $smallcolom3, $row1, $smallwidth, $rowheight)
        $check_color_yellow = GUICtrlCreateCheckbox("Gul",              $smallcolom4, $row1, $smallwidth, $rowheight)
        $check_color_green  = GUICtrlCreateCheckbox("Grøn",                $smallcolom5, $row1, $smallwidth, $rowheight)
        $check_color_red    = GUICtrlCreateCheckbox("Rød",             $smallcolom6, $row1, $smallwidth, $rowheight)
        $combo_brand    = GUICtrlCreateCombo("Mærke",                  $colom1,      $row2, $colomwidth, $rowheight, 2) ; create first item
        GUICtrlSetData($combo_brand, "Asus|MSI|Toshiba|Clevo|HP|Shuttle|Aopen|Calvin|Acer|Packard Bell|Samsung|Lenovo|IBM|NZXT|Antec|Apevia|Western Digital") ; add other item snd set a new default
        $diversebskrvls = GUICtrlCreateInput("",                    $colom1, $row3, 450, $rowheight)
    $hSubTabPage2 = GUICtrlCreateTabItem ("Tilbehør")
        $recoverymedier = GUICtrlCreateCheckbox("Recovery Medier",  $colom1, $row1, $colomwidth, $rowheight)
        $PSU            = GUICtrlCreateCheckbox("Strømforsyning",  $colom2, $row1, $colomwidth, $rowheight)
        $taske          = GUICtrlCreateCheckbox("Taske",            $colom3, $row1, $colomwidth, $rowheight)
        $memorystick    = GUICtrlCreateCheckbox("Memorystick",      $colom4, $row1, $colomwidth, $rowheight)
        $eksternhdd     = GUICtrlCreateCheckbox("Ekstern Harddisk", $colom1, $row2, $colomwidth, $rowheight)
        $eksterndvdrw   = GUICtrlCreateCheckbox("Ekstern DVD/RW",   $colom2, $row2, $colomwidth, $rowheight)
        $manual         = GUICtrlCreateCheckbox("Manual",           $colom3, $row2, $colomwidth, $rowheight)
        $3gmodem        = GUICtrlCreateCheckbox("3G Modem",         $colom4, $row2, $colomwidth, $rowheight)
        $diversetlbhr   = GUICtrlCreateInput("",                    $colom1, $row3, 450, $rowheight)
    $hSubTabPage3 = GUICtrlCreateTabItem ("Fejlbeskrivelse")
        $fejlbeskrivelse = GUICtrlCreateInput("",                   $colom1, $row1, 450, $rowheight)

GUISetState (@SW_SHOW, $mainGUI)
GUISetState (@SW_SHOW, $hindleveret)


runprogram()

Func runprogram()
    While 1
    $nMsg = GUIGetMsg ()
    Select 
        Case $nMsg = $GUI_EVENT_CLOSE
            program_exit()
        Case $nMsg = $udskriv
            ;If GUICtrlRead($input_phonenumber) > 99999999 Or GUICtrlRead($input_phonenumber) < 20000000 Then
            ;   MsgBox(0, "Fejl", "Telefonnummeret er ikke indtastet korrekt! Venligst udfyld telefonnummeret")
            ;Else
            print()
            ;EndIf
        Case $nMsg = $clearfields
            clearfields()
        EndSelect
    WEnd
EndFunc

Func accesory()
    $accesory = ""
    If GUICtrlread($recoverymedier) = 1 Then
        $accesory = $accesory & "Recoverymedier, "
    EndIf
    If GUICtrlread($PSU) = 1 Then
        $accesory = $accesory & "Strømforsyning, "
    EndIf
    If GUICtrlread($taske) = 1 Then
        $accesory = $accesory & "Taske, "
    EndIf
    If GUICtrlread($memorystick) = 1 Then
        $accesory = $accesory & "Memorystick, "
    EndIf
    If GUICtrlread($eksternhdd) = 1 Then
        $accesory = $accesory & "Ekstern Harddisk, "
    EndIf
    If GUICtrlread($eksterndvdrw) = 1 Then
        $accesory = $accesory & "Ekstern DVD/RW, "
    EndIf
    If GUICtrlread($manual) = 1 Then
        $accesory = $accesory & "Manualer, "
    EndIf
    If GUICtrlread($3gmodem) = 1 Then
        $accesory = $accesory & "3G Modem, "
    EndIf
    Return($accesory)
EndFunc

Func color()
    $color = ""
    If GUICtrlread($check_color_black) = 1 Then
        $color = $color & "Sort, "
    EndIf
    If GUICtrlread($check_color_blue) = 1 Then
        $color = $color & "Blå, "
    EndIf
    IF GUICtrlread($check_color_green) = 1 Then
        $color = $color & "Grøn, "
    EndIf
    If GUICtrlread($check_color_red) = 1 Then
        $color = $color & "Rød, "
    EndIf
    IF GUICtrlread($check_color_silver) = 1 Then
        $color = $color & "Sølv, "
    EndIf
    If GUICtrlread($check_color_yellow) = 1 Then
        $color = $color & "Gul"
    EndIf
    Return($color)
EndFunc

Func garanti()
    $garanti = ""
    If GUICtrlRead($chkbx_garanti) = 1 Then
        $garanti = "indenfor garanti"
    Else
        $garanti = "undenfor garanti"
    EndIf
    Return($garanti)
EndFunc

Func Print()
    Local $mmssgg,$marginx,$marginy
    Dim $currenty = 0
    Dim $currentx = 0
    local $header1 = 25
    local $header2 = 17
    local $header3 = 13
    local $body = 10
    local $leftmargin = 25
    local $rightmargin = 15
    local $topmargin = 15
    local $linespacing_small = 1.3
    local $linespacing_medium = 1.5
    
    Dim $startpoint = 1
    Dim $lenght = 90
    Dim $var = 0
    Dim $result2 = 1
    Dim $empty  = ""
    
    $hp = _PrintDllStart($mmssgg);this must always be called first
    if $hp = 0 then
        consolewrite("Error from dllstart = " & $mmssgg & @CRLF)
        Exit
    endif
    
    ;choose the printer if you don't want the default printer
    ;_PrintSetPrinter($hp);see also _PrinterSelectPrinter
    _PrintPageOrientation($hp,1);set ordinary printing
    _PrintStartPrint($hp)
    $pageheight = _PrintGetpageheight($hp) - _PrintGetYOffset($hp)
    $pagewidth = _PrintGetpageWidth($hp) - _PrintGetXOffset($hp)
    
    ; Print headline
    $currenty = $topmargin
    $currentx = $leftmargin
    _PrintSetFont($hp,'Tahoma',$header1,0,'')
    $text = "ADD-Data Indlevering"
    _PrintText($hp,$text, $currentx, $currenty)
    $textheight = _PrintGetTextHeight($hp,$text)
    $currenty = $currenty + $textheight

    ; Print line under headline
    $currentx = $currentx - 5
    $currenty = $currenty - 17
    _PrintSetLineWid($hp,2)
    _PrintSetLineCol($hp,$BLACK)
    _PrintLine($hp,$currentx, $currenty,int($pagewidth - $currentx - $rightmargin),$currenty)
    $currentx = $leftmargin
        
    ;print "Modtaget af" in the top right corner
    _PrintSetFont($hp,'Tahoma',$header3,0,'')
    $currenty = $currenty - 6
    $text = "Modtaget af " & GUICtrlRead($combo_modtager, 1) & " d. " & @MDAY & "-" & @MON & "-" & @YEAR & " kl. " & @HOUR & ":" & @MIN
    $textwidth = _PrintGetTextWidth($hp,$text)
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, int($pagewidth - $textwidth - $rightmargin - 20), $currenty)
    
    ;Print "kunde informationer"
    $currenty = $currenty + int($textheight * $linespacing_medium)
    _PrintSetFont($hp,'Tahoma',$header2,0,'')
    $text = "Kunde information"
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty) 

    ;Print customer name
    $currenty = $currenty + int($textheight * $linespacing_small)
    $currentx = $currentx * 2
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Navn: " & GUICtrlRead($input_name, 1)
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)
    
    ;Print Contact information
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Telefonnummer: " & GUICtrlRead($input_phonenumber, 1) & " Anden Kontakt: " & GUICtrlRead($input_other, 1)
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)

    ;Print "Produkt informationer"
    $currenty = $currenty + int($textheight * $linespacing_medium)
    $currentx = $leftmargin
    _PrintSetFont($hp,'Tahoma',$header2,0,'')
    $text = "Produkt information"
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty) 

    ;Print customer name and waranty info
    $currenty = $currenty + int($textheight * $linespacing_small)
    $currentx = $currentx * 2
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Indleveret: " & GUICtrlRead($combo_indleveret, 1) & " " & garanti()
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)
    
    ;Print invoice ID
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Faktura nr: " & GUICtrlRead($combo_faknr, 1)
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)

    ;Print "beskrivelse"
    $currenty = $currenty + int($textheight * $linespacing_small)
    $currentx = $currentx + $leftmargin
    _PrintSetFont($hp,'Tahoma',$header3,0,'')
    $text = "Beskrivelse"
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)

    ;Print color
    $currenty = $currenty + int($textheight * $linespacing_medium)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Farve: " & color()
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)
    
    ;Print textfield beneth the colors
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = GUICtrlRead($diversebskrvls, 1)
    
    $startpoint = 1
    $var = 0
    $result2 = 1
    
    while $result2 > 0
        $var = StringMid($text, $startpoint, $lenght)
        $result2 = Stringcompare($var, $empty, 2)       
        $startpoint = $startpoint + $lenght
        $textheight = _PrintGetTextHeight($hp,$text)
        _PrintText($hp,$var, $currentx, $currenty)
        $currenty = $currenty + int($textheight * $linespacing_small)
    WEnd
    
    ;Print list of accesory
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = "Tilbehør: " & accesory()
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty)
    
    ;Print textfield beneth the accesory
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = GUICtrlRead($diversetlbhr)

    $startpoint = 1
    $var = 0
    $result2 = 1
    
    while $result2 > 0
        $var = StringMid($text, $startpoint, $lenght)
        $result2 = Stringcompare($var, $empty, 2)       
        $startpoint = $startpoint + $lenght
        $textheight = _PrintGetTextHeight($hp,$text)
        _PrintText($hp,$var, $currentx, $currenty)
        $currenty = $currenty + int($textheight * $linespacing_small)
    WEnd

    ;Print "Fejlbeskrivelse"
    $currenty = $currenty + int($textheight * $linespacing_medium)
    $currentx = $leftmargin
    _PrintSetFont($hp,'Tahoma',$header2,0,'')
    $text = "Fejlbeskrivelse"
    $textheight = _PrintGetTextHeight($hp,$text)
    _PrintText($hp,$text, $currentx, $currenty) 

    ;Print textfield "Fejlbeskrivelse"
    $currenty = $currenty + int($textheight * $linespacing_small)
    _PrintSetFont($hp,'Tahoma',$body,0,'')
    $text = GUICtrlRead($fejlbeskrivelse)

    $startpoint = 1
    $var = 0
    $result2 = 1
    
    while $result2 > 0
        $var = StringMid($text, $startpoint, $lenght)
        $result2 = Stringcompare($var, $empty, 2)       
        $startpoint = $startpoint + $lenght
        $textheight = _PrintGetTextHeight($hp,$text)
        _PrintText($hp,$var, $currentx, $currenty)
        $currenty = $currenty + int($textheight * $linespacing_small)
    WEnd

    _PrintEndPrint($hp)
    _printDllClose($hp)
    program_exit()
EndFunc

Func program_exit()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

Edifice,

If you changed your script so that the inputs were created in immediate succession, you can use a loop to help you empty the inputs.

As controls are created in Autoit, they are given the next available ControlID. So if you create a series of controls in immediate succession they will have consecutive ControlIDs. You can then use these ControlIDs in a loop to address each control in turn. Here is a short example:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

; We create the controls in IMMEDIATE succession - look in the SciTE console to see the ControlID for each control
$hLabel_1 = GUICtrlCreateLabel("Label 1", 10, 10, 100, 20)
    ConsoleWrite("This label has a ControlID of " & $hLabel_1 & @CRLF)
$hLabel_2 = GUICtrlCreateLabel("Label 2", 10, 30, 100, 20)
    ConsoleWrite("This label has a ControlID of " & $hLabel_2 & @CRLF)
$hLabel_3 = GUICtrlCreateLabel("Label 3", 10, 50, 100, 20)
    ConsoleWrite("This label has a ControlID of " & $hLabel_3 & @CRLF)
$hLabel_4 = GUICtrlCreateLabel("Label 4", 10, 70, 100, 20)
    ConsoleWrite("This label has a ControlID of " & $hLabel_4 & @CRLF)
$hLabel_5 = GUICtrlCreateLabel("Label 5", 10, 90, 100, 20)
    ConsoleWrite("This label has a ControlID of " & $hLabel_5 & @CRLF)

$hButton = GUICtrlCreateButton("Empty labels", 10, 150, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Loop through the ControlIDs and blank them
            For $i = $hLabel_1 To $hLabel_5
                GUICtrlSetData($i, "")
            Next
    EndSwitch

WEnd

But you must maks sure that you create the controls in IMMEDIATE succession - or you will address controls that you do want to!

Pleasae ask if anything is unclear. :D

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

Okay I just did that to all my GUI stuff, just one problem: The command clears the text from the checkboxes but not the fact that they are checked. How do I make sure they are all unchecked?

Edited by Edifice
Link to comment
Share on other sites

GUICtrlSetState(item, $GUI_UNCHECKED)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, and one last n00bie thing. How do I get combo and dropdown menus to the default state. The SetData will just add stuff to them?

I assume you mean combo and list boxes

$sData = "1st|2nd|3rd|4th"
$hCombo = GUICtrlCreateCombo("",x,y,w,h,styles)
GUICtrlSetData($hCombo, $sData, "1st")

;;  In here you do  whatever you want until it's time to reset the combo and then use the next line

GUIctrlSetData($hCombo, "|" & $sData, "1st") ;;  The leading pipe symbol deletes the existing contents

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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