Jump to content

gui question


Recommended Posts

hi

i make a gui with some Checkbox

like

apple, peach, juice , etc

all i whant is that when i press the ok button , the choice i made to go into a variable $choice

for example if i choose apple and peach, the $choice will contains apple and peach

( for verify filewrite ("c:\test.exe" , $choice) the file will be something like

apple , juice

Link to comment
Share on other sites

xcal

Where's the part where you ask a question?

That is not help :whistle: ...

erikson

Like this?

#include <GUIConstants.au3>

GUICreate("Test", 200, 300)

$Choice = "Nothing"
$Apple = GUICtrlCreateCheckbox("apple", 20, 30)
$Peach = GUICtrlCreateCheckbox("peach", 20, 60)
$Juice = GUICtrlCreateCheckbox("juice", 20, 90)

$Button = GUICtrlCreateButton("Choose", 120, 260)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Button
            If GUICtrlRead($Apple) = $Gui_Checked Then $Choice = GUICtrlRead($Apple, 1)
            If GUICtrlRead($Peach) = $Gui_Checked Then $Choice = GUICtrlRead($Peach, 1)
            If GUICtrlRead($Juice) = $Gui_Checked Then $Choice = GUICtrlRead($Juice, 1)
            MsgBox(0, "", "You chousen: " & $Choice)
        Case $Gui_Event_Close
            Exit
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

You'll want to have a look at GUICtrlRead().

It'll look something like...

If GuiCtrlRead($mycheckbox) = $GUI_CHECKED Then

$myvar = 'it''s check'

Else

$myvar = 'it''s not checked'

EndIf

i will give you a short example

CODE
#region --- GuiBuilder code Start ---

; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Checkbox_2 = GuiCtrlCreateCheckbox("apple", 20, 70, 80, 40)

$Checkbox_3 = GuiCtrlCreateCheckbox("juice", 20, 120, 90, 70)

$Checkbox_4 = GuiCtrlCreateCheckbox("peach", 20, 210, 100, 70)

$Checkbox_5 = GuiCtrlCreateCheckbox("grapes", 20, 0, 100, 60)

$Button_6 = GuiCtrlCreateButton("Select!", 220, 120, 130, 60)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

$choose = <what i must put here to take the choose i make?>

filewrite ("c:\test.txt", $choose) ; for verification

Exit

#endregion --- GuiBuilder generated code End ---

it`s not a complete scrpt i use just for example.

so if i choose apple and juice , in $choose will be apple and juice

Link to comment
Share on other sites

#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)

Global $choice[3]

$hmain = GuiCreate("CheckBoxes", 139, 140,-1, -1 )
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$Chkbox1 = GuiCtrlCreateCheckbox("apple", 20, 20, 100, 20)
GUICtrlSetOnEvent(-1, "chkstr")
$Chkbox2 = GuiCtrlCreateCheckbox("peach", 20, 50, 100, 20)
GUICtrlSetOnEvent(-1, "chkstr")
$Chkbox3 = GuiCtrlCreateCheckbox("juice", 20, 80, 90, 20)
GUICtrlSetOnEvent(-1, "chkstr")
$button = GUICtrlCreateButton("Save", 20, 110, 50, 20)
GUICtrlSetOnEvent(-1, "OK")
GuiSetState()

While 1
    Sleep(10)
WEnd

Func chkstr()
    Select
        Case @GUI_CTRLID = $Chkbox1
            $chkb1 = GUICtrlRead($Chkbox1)
            If $chkb1 = $GUI_UNCHECKED Then
                $choice[0] = ""
            ElseIf $chkb1 = $GUI_CHECKED Then
                $choice[0] = "apple,"
            EndIf
        Case @GUI_CTRLID = $Chkbox2
            $chkb2 = GUICtrlRead($Chkbox2)
            If $chkb2 = $GUI_UNCHECKED Then
                $choice[1] = ""
            ElseIf $chkb2 = $GUI_CHECKED Then
                $choice[1] = "pear,"
            EndIf
        Case @GUI_CTRLID = $Chkbox3
            $chkb3 = GUICtrlRead($Chkbox3)
            If $chkb3 = $GUI_UNCHECKED Then
                $choice[2] = ""
            ElseIf $chkb3 = $GUI_CHECKED Then
                $choice[2] = "juice,"
            EndIf         
    EndSelect
EndFunc

Func OK()
    $SaveChoice = FileSaveDialog("Save your choice(s)", @ScriptDir, "Text (*.txt)", 2,"Choice.txt")
        If Not @error Then
            For $i = 0 To 2
            $ChoiceCreate = FileOpen($SaveChoice ,1)
            FileWrite($ChoiceCreate,$choice[$i])
            FileClose($ChoiceCreate)
            Next
        EndIf   
EndFunc

Func close()
    Exit
EndFunc

I'm clueless but I gave it a shot..

Cheers

Edit:

Wasn't sure if the elements were spose to be written to txt file line by line or if they should be on one line... settled for 1 line.

Edited by smashly
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...