Jump to content

read guictrlcreatelist to array


Recommended Posts

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)

Link to comment
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
Link to comment
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
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

×
×
  • Create New...