Lisuter Posted October 10, 2018 Posted October 10, 2018 (edited) Hello... How i can write data from txt to +3 Input? Example: In txt i have:Michael XYZ, 21, Boston Olex Marshal, 17, Boston Alex XYZ, 19, Boston And now i want load that data to input in autoit. Name y.o city [ Input1] [Input2] [Input3] [ Input4] [Input5] [Input6] [ Input7] [Input8] [Input9] After load should be: Name y.o city [Michael XYZ] [21] [Boston] [ Olex Marshal] [17] [Boston] [ Alex XYZ] [19] [Boston] FileOpen("Test.txt",0) $aas = GUICtrlSetData($Input1, FileReadLine("Test.txt",1)) FileClose("Test.txt") But its wrong. ofcourse its load all to input 1. So now how do you load this data directly into each input separately? The comma stop sign is here. Each line is a new person Edited October 10, 2018 by Lisuter
Lisuter Posted October 10, 2018 Author Posted October 10, 2018 (edited) Okay i try some and now working with first line from txt and load it to Input1, Input2, Input3 correctly. Now, how to loop all, each line from txt to each input? My working code for each: FileOpen("Test.txt",0) MsgBox(0,"Test", FileReadLine("Test.txt",1)) $aas = FileReadLine("Test.txt",1) $aSplitLine = StringSplit($aas,",") GUICtrlSetData($Input1, $aSplitLine[1]) GUICtrlSetData($Input2, $aSplitLine[2]) GUICtrlSetData($Input3, $aSplitLine[3]) FileClose("Test.txt") Edited October 10, 2018 by Lisuter
Moderators JLogan3o13 Posted October 10, 2018 Moderators Posted October 10, 2018 @Lisuter as an awareness, in the future - especially when dealing with a GUI - you will always receive more help if you post your entire code rather than asking us to guess at what you are trying to do. That said, if you are trying to simply update the input fields on the GUI with a line from the text file, you could do something like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $aFile = FileReadToArray("test.txt") Local $hGUI = GuiCreate("Test", 300, 200) Local $Input1 = GUICtrlCreateInput("", 10, 10, 90, 50) Local $Input2 = GUICtrlCreateInput("", 105, 10, 90, 50) Local $Input3 = GUICtrlCreateInput("", 200, 10, 90, 50) Local $sGo = GUICtrlCreateButton("Go", 250, 150, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sGo For $sLine In $aFile $aTemp = StringSplit($sLine, ",") GUICtrlSetData($Input1, $aTemp[1]) GUICtrlSetData($Input2, $aTemp[2]) GUICtrlSetData($Input3, $aTemp[3]) Sleep(1000) Next EndSwitch WEnd If you are looking rather to add all the lines into the input fields, you can do something like this: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $aFile = FileReadToArray("test.txt") Local $hGUI = GuiCreate("Test", 300, 200) Local $Input1 = GUICtrlCreateInput("", 10, 10, 90, 50, $ES_MULTILINE) Local $Input2 = GUICtrlCreateInput("", 105, 10, 90, 50, $ES_MULTILINE) Local $Input3 = GUICtrlCreateInput("", 200, 10, 90, 50, $ES_MULTILINE) Local $sGo = GUICtrlCreateButton("Go", 250, 150, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sGo For $sLine In $aFile $aTemp = StringSplit($sLine, ",") GUICtrlSetData($Input1, ((GUICtrlRead($Input1) = "") ? $aTemp[1] :GUICtrlRead($Input1) & @CRLF & $aTemp[1])) GUICtrlSetData($Input2, ((GUICtrlRead($Input2) = "") ? $aTemp[2] :GUICtrlRead($Input2) & @CRLF & $aTemp[2])) GUICtrlSetData($Input3, ((GUICtrlRead($Input3) = "") ? $aTemp[3] :GUICtrlRead($Input3) & @CRLF & $aTemp[3])) Sleep(1000) Next EndSwitch WEnd Beyond a couple of lines, however, you may want to switch to a listview for easier handling. Lisuter 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Subz Posted October 10, 2018 Posted October 10, 2018 Another example: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 40) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 $sGetData = "" For $j = 0 To UBound($aControl, 2) - 1 $sGetData &= GUICtrlRead($aControl[$i][$j]) & @CRLF Next MsgBox(4096, $i & " Line Data", $sGetData) Next EndSwitch WEnd EndFunc Lisuter 1
Lisuter Posted October 10, 2018 Author Posted October 10, 2018 21 minutes ago, Subz said: Another example: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 40) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 $sGetData = "" For $j = 0 To UBound($aControl, 2) - 1 $sGetData &= GUICtrlRead($aControl[$i][$j]) & @CRLF Next MsgBox(4096, $i & " Line Data", $sGetData) Next EndSwitch WEnd EndFunc Thanks. Its really good working for me, but i dont know how to make print its all in Edit1: Excample: After click GetData all data from input put to Edit1 in one line: Edit1: Name is: Michael XYZ, 21 years old, Boston city, Name is: Olex Marshal, 17 years old, Boston city,Name is: Alex XYZ, 19 years old, Boston city,
careca Posted October 10, 2018 Posted October 10, 2018 expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 40) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 MsgBox(4096, $i & " Line Data", 'Name is: '&GUICtrlRead($aControl[$i][0])&', '&GUICtrlRead($aControl[$i][1])&' years old, '&GUICtrlRead($aControl[$i][2])&' city') Next EndSwitch WEnd EndFunc Like that? Lisuter 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
Lisuter Posted October 11, 2018 Author Posted October 11, 2018 Hello! Thanks for answer, but i want like that in Edit1:------------------------- Info:Name is: Michael XYZ, 21 years old, Boston city, Name is: Olex Marshal, 17 years old, Boston city,Name is: Alex XYZ, 19 years old, Boston city, ------------------------- Now i have only the last data from last input, also without "Info:". I want to load all. In txt i have:Michael XYZ, 21, Boston Olex Marshal, 17, Boston Alex XYZ, 19, Boston Now after click Get Data in Edit1 i have: ------------------------------Name is: Michael XYZ, 21 years old, Boston city ------------------------------- Code: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\test.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 100) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) Local $ed = GUICtrlCreateEdit("", 20, $y+35, 300, 60) ;250 SZEROKOŚĆ GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 Global $Edit1 = GUICtrlSetData(-1,"Info:"&@CRLF) Global $Edit1 = GUICtrlSetData(-1,'Name is: '&GUICtrlRead($aControl[$i][0])&', '&GUICtrlRead($aControl[$i][1])&' years old, '&GUICtrlRead($aControl[$i][2])&' city') Next EndSwitch WEnd EndFunc Please help.
Subz Posted October 11, 2018 Posted October 11, 2018 Do you mean something like: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData, $sEdit = "" Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 100) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) Local $idEdit = GUICtrlCreateEdit("", 20, $y+35, 300, 60) ;250 SZEROKOŚĆ GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData GUICtrlSetData($idEdit, "") $sEdit = "Info:" & @CRLF For $i = 0 To UBound($aControl) - 1 $sEdit &= "Name is: " & GUICtrlRead($aControl[$i][0]) & ", " & GUICtrlRead($aControl[$i][1]) & " years old, " & GUICtrlRead($aControl[$i][2]) & " city" & @CRLF Next GUICtrlSetData($idEdit, $sEdit) EndSwitch WEnd EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now