# Button Variables Creation

## Recommended Posts

Hello,

I need this for a project and I don't find a method for the next problem.

I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.

Do you have an idea ?

Thank you for your attention !

##### Share on other sites

AppSoftwareVld,

Welcome to the AutoIt forums.

You could use an array and add an element each time you click the button. But if you could explain why you need to create these variables, we might be able to offer better solutions.

M23

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

##### Share on other sites

It's a bit difficult what I want to do, when the button click he will create a variable and set the variable some data.

Actually, there is one more problem, probably I will open in another topic.

After that I want to show on a list all variables that have a selected data (example show all variables with 'blue' data) or something like that.

Sorry for my bad english, I hope you understood what I want to do.

##### Share on other sites

AppSoftwareVld,

That is simply a repeat of what you want to do - I was asking why you wanted to do it, for example what type of data are you storing with each button press?

If you were to use the array method I suggested then your second problem can be solved by searching through the array for the necessary "key" and then adding those elements to a List control. Again, if you can explain more clearly just what you are trying to do then I can offer more focused help.

M23

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

##### Share on other sites

I don't speak so good english, but all I want to do is when click the button read an input, create a new variable where that will have the text from the input and when i click on another button show a combo with all  the variables that have the text 'blue'.

I don't want to do nothing with them just show them in a combo.

If you don't understand you can enter with team viewer if you have time to help for a moment and show you what I actually want to do, I can't explain so good in english.

##### Share on other sites

AppSoftwareVld,

Does this do what you want?

#include <GUIConstantsEx.au3>

; Array to hold input contents
Global $aContents[1] = [0] ; Set required string to match$sRequired = "blue"

; Create GUI
$hGUI = GUICreate("Test", 500, 500)$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

$cRead = GUICtrlCreateButton("Read", 10, 50, 80, 30)$cShow = GUICtrlCreateButton("Show", 100, 50, 80, 30)

$cCombo = GUICtrlCreateCombo("", 10, 100, 200, 200) GUICtrlSetState($cCombo, $GUI_HIDE) GUISetState() While 1 Switch GUIGetMsg() Case$GUI_EVENT_CLOSE
Exit
Case $cRead ; Increase size of array$aContents[0] += 1
ReDim $aContents[$aContents[0] + 1]
; Check if there is something to add
If GUICtrlRead($cInput) <> "" Then ; Add input contents to array$aContents[$aContents[0]] = GUICtrlRead($cInput)
EndIf
; Clear input
GUICtrlSetData($cInput, "") ; Reset focus to input GUICtrlSetState($cInput, $GUI_FOCUS) Case$cShow
; Create new combo data
$sComboData = "" ;Loop through array For$i = 1 To $aContents[0] ; Check if required value is present If StringInStr($aContents[$i],$sRequired) Then
; And add to combo data
$sComboData &= "|" &$aContents[$i] EndIf Next ; Add data to combo GUICtrlSetData($cCombo, $sComboData) ; Show combo GUICtrlSetState($cCombo, $GUI_SHOW) Case$cCombo
GUICtrlSetState($cCombo,$GUI_HIDE)

EndSwitch

WEnd

M23

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

##### Share on other sites

Yes, this is what I searched for !

Thank you very much man !

##### Share on other sites

AppSoftwareVld,

M23

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

## Create an account

Register a new account

• ### Similar Content

• First I would just like to say HELLO! to anyone reading. It has been a while since I've posted to the Forums but I'm always crawling around.
Now to the matter at hand. I have been looking high and low for a simplistic answer my burned out brain can find but to no avail. I've only recently upped my AutoIt skill and only by a little bit such as ordering my script neatly with my own UDFs and using Global/Dim more often to make my GUI creation understandable and easy to keep things orderly. My current problem however is figuring out how to make my newest endeavor work which is my own "Debugger". I've made a GUI with an Edit Control to display what my Variables are holding and other information from a concurrently running Script. I have access to all of the scripts I'm attempting to connect but I'm dumbfounded on how I would separately read variable information from one running script into another. I'll provide my "Debugger" script that I want to read variables into and a "Meta Script" I'd want to pass info from.
#Region Include Files #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #EndRegion #Region AutoIt Options ;Opt("TrayAutoPause", 0) ;Opt("TrayMenuMode", 3) #EndRegion #Region Hotkeys HotKeySet("{ESC}", "ExitProgram") HotKeySet("{PGDN}", "PauseProgram") HotKeySet("!1", "Snippet_1") HotKeySet("!2", "Snippet_2") HotKeySet("!3", "Snippet_3") HotKeySet("!4", "Snippet_4") HotKeySet("!5", "Snippet_5") HotKeySet("!6", "Snippet_6") HotKeySet("!7", "Snippet_7") HotKeySet("!8", "Snippet_8") HotKeySet("!9", "Snippet_9") #EndRegion #Region Global Variables #Region Globals Global $gMain,$ctrlEdit ;, $gParent #EndRegion #Region$gMain Params Dim $gMainW = @DesktopWidth / 2 Dim$gMainH = @DesktopHeight / 2 Dim $gMainX = (@DesktopWidth / 2) - ($gMainW / 2) Dim $gMainY = (@DesktopHeight / 2) - ($gMainH / 2) Dim $gMainStyle =$WS_POPUP Dim $gMainStyleEx = -1 ;Dim$gMainParent = $gParent #EndRegion #Region$ctrlEdit Params Dim $ctrlEditW = Round($gMainW * 0.98) Dim $ctrlEditH = Round($gMainH * 0.98) Dim $ctrlEditX = ($gMainW - $ctrlEditW) / 2 Dim$ctrlEditY = ($gMainH -$ctrlEditH) / 2 Dim $ctrlEditStyle = -1 Dim$ctrlEditStyleEx = -1 #EndRegion #EndRegion #Region GUI Initialization ;$gParent = GUICreate("", -1, -1, -1, -1, -1,$WS_EX_TOOLWINDOW) $gMain = GUICreate("",$gMainW, $gMainH,$gMainX, $gMainY,$gMainStyle, $gMainStyleEx) GUISetBkColor($COLOR_BLACK, $gMain)$ctrlEdit = GUICtrlCreateEdit("MainW: " & $gMainW & @CRLF & "MainH: " &$gMainH & @CRLF & "EditW: " & $ctrlEditW & @CRLF & "EditH: " &$ctrlEditH, $ctrlEditX,$ctrlEditY, $ctrlEditW,$ctrlEditH, $ctrlEditStyle,$ctrlEditStyleEx) GUISetState(@SW_SHOW, $gMain) #EndRegion MainFunction() #Region Main Function (GUI) Func MainFunction() While 1$msg = GUIGetMsg() If $msg =$GUI_EVENT_CLOSE Then Exit EndIf WEnd EndFunc #EndRegion #Region Functions Func Functions() EndFunc #EndRegion #Region Program 1 Func Snippet_1() EndFunc #EndRegion #Region Program 2 Func Snippet_2() EndFunc #EndRegion #Region Program 3 Func Snippet_3() EndFunc #EndRegion #Region Program 4 Func Snippet_4() EndFunc #EndRegion #Region Program 5 Func Snippet_5() EndFunc #EndRegion #Region Program 6 Func Snippet_6() EndFunc #EndRegion #Region Program 7 Func Snippet_7() EndFunc #EndRegion #Region Program 8 Func Snippet_8() EndFunc #EndRegion #Region Program 9 Func Snippet_9() EndFunc #EndRegion #Region Pause/Exit Functions Func PauseProgram() While 1 Sleep(1000) WEnd EndFunc Func ExitProgram() Exit EndFunc #EndRegion Pause/Exit Functions #Region Snippets #CS #CE #EndRegion #Region Other Information #CS #CE #EndRegion That's the Debugger script. Please forgive anything ignorant but point it out if you will, I'll take any pointers to get better! (I usually use a Select to get $GUI_EVENT_CLOSE but this is early on) Now if I made another script with a basic GUI similar to this and wanted to read say the GUI Width ($gMainW) into the Debugger Edit Control could I do it? If so, could I do it for every variable I have in a script? I read something about the Run function and adding the variables as an option parameter I believe which I think I could do with an array to keep it from being super long and ugly but would that be the only way to do this? Any information is going to be appreciated and thank you in advance for your time!

Edit: Sadly it just dawned on me that I could make a UDF that will create a child window that will do this instead of having a separate script trying to invade another... I'll still be keeping an eye on this for any comments but I apologize if I wasted your time!
• By 3Jake
Hello Smart People!
I have a multi-column .CSV that I would like to draw information from, in order to populate (send) that info to some fields in an Oracle form.  This would be for account-creation in Oracle.

I have the basic script to navigate (tab) through the fields in the Oracle form, but I am SUPER-new to AutoIT and don’t quite see how to get the script to import and use variables from a .CSV

For example:

My script just waits for the page to be active, then enters data and tabs between fields like this:

; Wait for the window to be active WinWaitActive("Oracle is Cool - E-Business is the Best") ; User Name Send("jsmith") Send("{TAB}") ; Password Send("Password1") Send("{TAB}") Send("Password1") Send("{TAB}") ; Description Send("John Smith") Send("{TAB}") (etc. etc. etc.…)

The winning solution would take one row at a time, feed it into fields on the Oracle form, save, and then start in on the next row

It looks like I’d need a combination of “FileReadToArray” ( or“FileReadLine”?) and “StringSplit” to loop through the values and set them to variables, which would then replace my current "hard-coded" values to be typed them into the form?

I found the following example in the “Help” snippets for stringsplit()… this seems like it’s in the ballpark but I’m having some trouble wrapping this around what I’ve put together, since each entry in the array would have multiple elements per line instead of just “Day”:

Func Example() Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri,Sat,Sun", ",") ;Split the string of days using the delimiter "," and the default flag value. #cs The array returned will contain the following values:$aDays[1] = "Mon" $aDays[2] = "Tues"$aDays[3] = "Wed" ... $aDays[7] = "Sun" #ce For$i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", "$aDays[" &$i & "] - " & $aDays[$i]) Next EndFunc ;==>Example

This post also seems like a similar example, but I don’t need it to be so selective RE: one specific column:

Any advice would be appreciated!  Thanks for taking a minute to look!

• Good morning,

I am trying to align a two-line text in a button so that it would be centered in the button but can't succeed to do it for the vertical part.
Can someone tell me what I do wrong ?
Here is my code:
$btn3 = GUICtrlCreateButton("Execute " & @LF & " file 1", 100, 65, 60, 50, _ BitOr($BS_CENTER,$BS_BOTTOM,$BS_MULTILINE)) and here is the resulting layout I get in my window.
I tried to follow the help, made a lot of different parameter combinations (here it's $BS_BOTTOM, but I tried $BS_VCENTER and BS_TOP), still get the same result : vertical alignement is a no go for me. Can someone help ? TIA Gilles • By Pike Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG! To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1" Case 1 LocalsRead = IniRead("config.ini", "Config", "One", "Default")
SoundPlay($sRead, @HotKeyPressed) <------------------------------- Run($sRead, @HotKeyPressed)                                                                                 <------------------------------- This 'Run' doesn't work even by itself!
See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated.

Much Respect,
Pike

Func _HandleButton() $iClickCount += 1$iTimer = TimerInit() AdlibRegister("CheckButtonPress", $CheckTime) EndFunc Func CheckButtonPress() If TimerDiff($iTimer) < $CheckTime Or$iTimer = 0 Then Return Switch $iClickCount Case 1 Local$sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)",$FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local $sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One",$sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $sFileName) EndSwitch$iClickCount = 0 AdlibUnRegister() EndFunc

• By misioooo
Hi!

I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file).
Part with button looks like this:
$ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff) $hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1,$hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here?
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...