Sign in to follow this  
Followers 0
Steven Vandenhoute

read guictrlcreatelist to array

5 posts in this topic

Hello everyone,

I am creating a script and i am stuck in reading the data from a list to an array

I have created a $var wich is a guictrlcreatelist()

this will be filled with paths from my computer.

I need to write this into a .ini file but are unable to read this into an array.

Tried looking on the forum, but didn't find anything usefull (I think)

Here is a copy of my code.

Hope someone can help me.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=D:\My Documents\My Pictures\vanhessen.ico
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author: Steven Vandenhoute

Script Function:
Sync Ariane data to network

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here




#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <File.au3>

FileDelete(@ScriptDir&"\settings.ini")




;variables
$Clear_input1 = 0
$Clear_input2 = 0
Local $hDLL = DllOpen("user32.dll")
Local $inifile = @ScriptDir & "\settings.ini"
Local $inifile_section = "interface_config"
$INP_UNC = 0
$INP_USER = 0
$INP_Password = 0
$chkbox_mail = 0
$Input1 = 0
$Input2 = 0
$INP_from = 0

_check_for_INI_FILE()


#region ### START Koda GUI section ### Form=c:\users\svandenhoute\desktop\ariane sync\ariane_sync.kxf
$Ariane_Sync = GUICreate("Ariane Sync Tool", 498, 469, 192, 114)
$Group1 = GUICtrlCreateGroup("", 8, 8, 481, 385)
$LBL_Password = GUICtrlCreateLabel("Password:", 248, 160, 86, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$LBL_User = GUICtrlCreateLabel("Domain\User:", 248, 104, 113, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$UNC = GUICtrlCreateLabel("Destination Path (UNC):", 248, 40, 197, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Selected_folders = GUICtrlCreateList("", 16, 72, 217, 305)
$Select_folder = GUICtrlCreateButton("Select Folders", 16, 24, 217, 41)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$INP_UNC = GUICtrlCreateInput("", 248, 72, 233, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$INP_USER = GUICtrlCreateInput("", 248, 128, 233, 28)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$INP_Password = GUICtrlCreateInput("", 248, 184, 233, 28, $ES_PASSWORD)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$chkbox_mail = GUICtrlCreateCheckbox("", 248, 224, 17, 17)
$Input1 = GUICtrlCreateInput("", 296, 248, 185, 28)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Input2 = GUICtrlCreateInput("", 296, 280, 185, 28)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$lbl_To = GUICtrlCreateLabel("TO:", 264, 250, 32, 24)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$lbl_smtp = GUICtrlCreateLabel("SMTP:", 250, 288, 40, 24)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$INP_from = GUICtrlCreateInput("", 296, 312, 185, 28)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Save = GUICtrlCreateButton("Save", 248, 343, 105, 33)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$Quit = GUICtrlCreateButton("Quit", 366, 343, 105, 33)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$lbl_sendmail = GUICtrlCreateLabel("Send Mail?", 264, 224, 67, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$lbl_from = GUICtrlCreateLabel("FROM:", 249, 316, 38, 24)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$VH_PIC = GUICtrlCreatePic(@ScriptDir&"\img\VHlogo.jpg", 8, 400, 177, 65)
$Ariane = GUICtrlCreatePic(@ScriptDir&"\img\ariane.jpg", 312, 400, 177, 65)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()

;~ Check for DEL key been pressed to delete faulty selected folder

If _IsPressed("2E", $hDLL) Then
$z = _GUICtrlListBox_GetCurSel($Selected_folders)
_GUICtrlListBox_DeleteString($Selected_folders, $z)
EndIf
Sleep(10)

Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Quit
DllClose($hDLL)
Exit

Case $chkbox_mail
$verify_chkbox = GUICtrlRead($chkbox_mail)

If $verify_chkbox = 1 Then
GUICtrlSetData($Input1, "")
GUICtrlSetData($Input2, "")
GUICtrlSetData($INP_from, "")
GUICtrlSetState($Input1, $GUI_SHOW)
GUICtrlSetState($Input2, $GUI_SHOW)
GUICtrlSetState($INP_from, $GUI_SHOW)
GUICtrlSetState($lbl_To, $GUI_SHOW)
GUICtrlSetState($lbl_smtp, $GUI_SHOW)
GUICtrlSetState($lbl_from, $GUI_SHOW)
EndIf

If $verify_chkbox = 4 Then
GUICtrlSetState($Input1, $GUI_HIDE)
GUICtrlSetState($Input2, $GUI_HIDE)
GUICtrlSetState($lbl_To, $GUI_HIDE)
GUICtrlSetState($lbl_smtp, $GUI_HIDE)
GUICtrlSetState($lbl_from, $GUI_HIDE)
GUICtrlSetState($INP_from, $GUI_HIDE)

EndIf
Case $Select_folder

$var = FileSelectFolder("Select your folder", "")
GUICtrlSetData($Selected_folders, $var)
GUISetState()

Case $Save
_write_INI_FILE()

DllClose($hDLL)
Exit

EndSwitch




WEnd
DllClose($hDLL)



Func _write_INI_FILE()
$INP_UNC = GUICtrlRead($INP_UNC)
$INP_USER = GUICtrlRead($INP_USER)
$INP_Password = GUICtrlRead($INP_Password)
$chkbox_mail = GUICtrlRead($chkbox_mail)
$Input1 = GUICtrlRead($Input1)
$Input2 = GUICtrlRead($Input2)
$INP_from = GUICtrlRead($INP_from)
$Selected_folders=GUICtrlRead($Selected_folders)


MsgBox(0,"",GUICtrlRead($Selected_folders))







_FileCreate($inifile)
Local $file = FileOpen($inifile, 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

FileWrite($file, "[Ariane_Sync]" & @CRLF)
FileWrite($file, "INP_UNC='" & $INP_UNC & "'" & @CRLF)
FileWrite($file, "INP_USER='" & $INP_USER & "'" & @CRLF)
FileWrite($file, "INP_PASSWORD='" & $INP_Password & "'" & @CRLF)
FileWrite($file, "CHKBOX_MAIL='" & $chkbox_mail & "'" & @CRLF)
FileWrite($file, "INPUT1='" & $Input1 & "'" & @CRLF)
FileWrite($file, "INPUT2='" & $Input2 & "'" & @CRLF)
FileWrite($file, "INP_FROM='" & $INP_from & "'" & @CRLF)



FileClose($file)






EndFunc ;==>_write_INI_FILE


Func _check_for_INI_FILE()

If FileExists($inifile) Then
_sync_procedure()
Else
MsgBox(48, "settings.ini file not found...", "settings.ini file will be created." & @CRLF & "Please answer the following questions.", 3)
EndIf
EndFunc ;==>_check_for_INI_FILE

Func _read_ini_file()
MsgBox(0, "", "_read_ini_file")
EndFunc ;==>_read_ini_file

Func _sync_procedure()
_read_ini_file()
MsgBox(0, "", "_sync_procedure")
Exit
EndFunc ;==>_sync_procedure

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites



maybe this?

#include <GUIListBox.au3>
#include <Array.au3>Dim $azArray[1]
$hGUI = GUICreate("Test", 300, 300)
$hListBox = GUICtrlCreateList("Test", 0, 0)
GUICtrlSetData(-1, "Hi|Sup|Hola")
GUISetState()

For $i = 0 To _GUICtrlListBox_GetCount($hListBox) - 1
$azArray[$i] = _GUICtrlListBox_GetText($hListBox, $i)
ReDim $azArray[UBound($azArray) + 1]
Next

_ArrayDisplay($azArray)
While 1
Switch GUIGetMsg()
Case - 3
Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Hi Danyfirex, thanks for your reply, i have your example working, and i understand why it is working... but when i implement it into my code, i receive an empty array

don't know what i am doing wrong.


"You cannot solve a problem with the mind that created it" (Albert Einstein)

Share this post


Link to post
Share on other sites

Here new fixed example. :graduated:

#include <GUIListBox.au3>
#include <Array.au3>Dim $azArray[1]
$hGUI = GUICreate("Test", 300, 300)
$hListBox = GUICtrlCreateList("Test", 0, 0)
GUICtrlSetData(-1, "Hi|Sup|Hola")
GUISetState()


$len=_GUICtrlListBox_GetCount($hListBox)

local $azArray[$len+1]

For $i = 0 To $len
$azArray[$i] = _GUICtrlListBox_GetText($hListBox, $i)
Next
ReDim $azArray[$len]

_ArrayDisplay($azArray)
While 1
Switch GUIGetMsg()
Case - 3
Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Thx a lot, this is indeed now working in my code.

with this my problem is indeed solved and i can continue working on my code... thx a lot


"You cannot solve a problem with the mind that created it" (Albert Einstein)

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
Sign in to follow this  
Followers 0

  • Similar Content

    • AaronOoi
      By AaronOoi
      Hi,
       
      I followed the AutoIT Help guideline for GUICtrlCreateList. When i clicked at the "Add" button, it will update the list to the 3rd line and if i continue to add, it will add to 4th and 5th line, if this going further, the data will be not shown as it keep getting down to the list. I want the data to update from the top always so that the updated data is always from the first line while the rest will keeps going down. Here is an example of the scripts:
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <EditConstants.au3> #include <ComboConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idAdd = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idClear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) Local $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97,$CBS_AUTOHSCROLL) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) Local $idClose = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idAdd GUICtrlSetData($idMylist, "You clicked button No1|") Case $idClear GUICtrlSetData($idMylist, "") Case $idClose MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit EndSwitch WEnd EndFunc ;==>Example  
       
       
       
    • Skysnake
      By Skysnake
      $ListLHT = GUICtrlCreateList("", 8, 152, 664, 279,BitOR($WS_GROUP,$WS_BORDER,$WS_VSCROLL,$WS_HSCROLL))  
      Hi, code works, but not documented.  Its not in the Help file, but HSCROLL works for List
      3.3.12.0
      If I am wrong, please point me in the right direction.
      Have a nice day now
    • dreamzboy
      By dreamzboy
      I have a list box control that allows me to see the output as the script runs.  Since I control those outputs, I want the message to display neatly inside the list box without scrolling all the way to the right to read the text.  I don't need anything fancy that calculates the length as I can just send a message from a new line.  Sound simple enough but I'm having trouble getting the function to issue @CRLF and indent properly.  I've already read through >this thread but it's not what I was looking for.
      This line did not enter a new line.
      GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " Error - One or more fields doesn't match!" & @CRLF & " Remove white space and/or extra entry before trying again." & @CRLF) While this line only gave me 1 tab.
      GUICtrlSetData ($log_label, @TAB & @TAB & @TAB & " Remove white space and/or extra entry before trying again." & @CRLF) Also tried the below but no help either.  It complained about the $aTabs.  I declared $aTabs[1] = [100] at the top (commented out) when trying this method.
      GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & "  Error - One or more fields doesn't match!" & @CRLF) _GUICtrlListBox_SetTabStops ($log_label, $aTabs) _GUICtrlListBox_AddString ($log_label, @TAB & "  Remove white space and/or extra entry before trying again." & @CRLF) Here's my code.  All you have to do is click on the "Generate" button and you'll see what I mean.
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <GuiListBox.au3> #include <array.au3> #include <constants.au3> Opt ("TrayIconDebug", 1) Local $ribcl_temp = '', $xml_temp, $i, $j Local $hn_input, $ip_input, $pw_input Local $host_Count, $ip_Count, $pw_Count Local $msg, $success, $password, $hostname, $ip_address Local $log_label, $generate_btn, $clrLog_btn Local $test_str0 = "dl360g7-25" & @CRLF & "dl360g7-26" Local $test_str1 = "10.112.15.22" & @CRLF & "10.112.15.23" & @CRLF & "10.112.15.24" Local $test_str2 = "pass1" & @CRLF & "pass2" & @CRLF & "pass3" ;Local $aTabs[1] = [100] GUICreate ("Test", 600, 450) GUICtrlCreateLabel ("1. Enter hostname (ex: dl360g7-25):", 30, 70, 250, 20) GUICtrlSetFont (-1, 10) $hn_input = GUICtrlCreateEdit ("", 30, 90, 215, 70) GUICtrlSetData ($hn_input, $test_str0) GUICtrlCreateLabel ("2. Enter iLO static IP address:", 30, 180, 250, 20) GUICtrlSetFont (-1, 10) $ip_input = GUICtrlCreateEdit ("", 30, 200, 215, 70) GUICtrlSetData ($ip_input, $test_str1) GUICtrlCreateLabel ("3. Enter iLO default password:", 30, 290, 200, 20) GUICtrlSetFont (-1, 10) $pw_input = GUICtrlCreateEdit ("", 30, 310, 215, 70) GUICtrlSetData ($pw_input, $test_str2) $log_label = GUICtrlCreateList ("", 300, 90, 270, 292, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL)) $generate_btn = GUICtrlCreateButton ("Generate XML File", 55, 400, 150, 30) GUICtrlSetFont (-1, 10) GUICtrlCreateLabel ("version 2.0", 530, 425, 70) GUICtrlSetColor (-1, 0x0000cd) $clrLog_btn = GUICtrlCreateButton ("Clear Log", 385, 400, 100, 30) GUICtrlSetFont (-1, 10) GUISetState () Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $generate_btn ; Check entry simliarity on all fields $hostname = StringSplit (GUICtrlRead ($hn_input), @CRLF, 3) ;MsgBox (0, "Before", $hostname) $hostname = StringStripWS ($hostname, 3) ;MsgBox (0, "After", $hostname) $host_Count = UBound ($hostname) $ip_address = StringSplit (GUICtrlRead ($ip_input), @CRLF, 3) $ip_Count = UBound ($ip_address) $password = StringSplit (GUICtrlRead ($pw_input), @CRLF, 3) $pw_Count = UBound ($password) If ($host_Count = $ip_Count And $ip_Count = $pw_Count And $host_Count = $pw_Count) Then ;Msgbox($mb_ok,'TRUE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count) GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " It works!") For $i = 0 To $host_Count - 1 ;MsgBox (0, "", $hostname[$i] GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " " & $hostname[$i] & @CRLF) GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " " & $ip_address[$i] & @CRLF) GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " " & $password[$i] & @CRLF) Next Else ;Msgbox($mb_ok,'FALSE', $ip_Count & @crlf & $host_Count & @crlf & $pw_Count) GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " Error - One or more fields doesn't match!" & @CRLF & " Remove white space and/or extra entry before trying again." & @CRLF) GUICtrlSetData ($log_label, @TAB & @TAB & @TAB & " Remove white space and/or extra entry before trying again." & @CRLF) Endif #cs Else GUICtrlSetData ($log_label, @HOUR & ":" & @MIN & ":" & @SEC & " Error - One or more fields doesn't match!") MsgBox (48, "Error", "One or more fields does not match! Please check the entries and try again.") EndIf #ce _GUICtrlListBox_UpdateHScroll ($log_label) Sleep (1000) Case $msg = $clrLog_btn GUICtrlSetData ($log_label, "") ; Clear log file EndSelect Until 0 Cheers,
      Dreamzboy
    • GPinzone
      By GPinzone
      I have a list (GUICtrlCreateList) tall enough to display 7 items. A scrollbar appears when the list had more than 7 items, which is the desired behavior. However, if the list is showing the last 7 items, not the first 7. In other words, the scrollbar is scrolled to the end by default instead of the top of the list. Is there any way to change this behavior?
      Here's what I have:
      Local $List_Queue = GUICtrlCreateList("", 2, 60, 400, 100, BitOR($LBS_MULTIPLESEL,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER)) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    • Tjalve
      By Tjalve
      Hi.
      Im currently writing a small script with a simpel GUI. I have used GUICtrlCreateList() function to create several lists of users. However in some cases i would like the color of some users to become red and sometimes blue. Ive searched the forms and i have found tons of info regarding the GUICtrlCreateListView function. But Im using the GUICtrlCreateList function. Can the same process be applied for items in GUICtrlCreateList aswell? And if so, how?
      Thank you.