abdulrahmanok Posted October 10, 2016 Posted October 10, 2016 Hi this is my code : Local $sFileRead = FileReadLine($hFileOpen, 1) Local $sFileRead2 = FileReadLine($hFileOpen, 2) Local $sFileRead3= FileReadLine($hFileOpen, 3) Local $sFileRead4 = FileReadLine($hFileOpen, 4) and 25 variable like this ............. I wrote it like this because I need each variable for specific event like this : _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 1 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead)) _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 2 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead2)) So i need to read each line from text file and put it in different variables Sorry for my English I hope you understand what i mean
BrewManNH Posted October 10, 2016 Posted October 10, 2016 FileReadToArray and then just use the array elements instead of individual variables. If you don't know how to use arrays then go here to learn about them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
abdulrahmanok Posted October 10, 2016 Author Posted October 10, 2016 On 10/10/2016 at 12:42 PM, BrewManNH said: FileReadToArray and then just use the array elements instead of individual variables. If you don't know how to use arrays then go here to learn about them. Expand Thanks for your response i actually tried this before but my try was very noob ... $sFilePath = @ScriptDir & "/1.txt" ; Open the file for reading and store the handle to a variable. Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $arr[3] = [$sFileRead = FileReadLine($hFileOpen, 1), $sFileRead = FileReadLine($hFileOpen, 1), $sFileRead = FileReadLine($hFileOpen, 1)] For $i = 0 to 3 - 1 ; We have an array with three elements but the last index is two. _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead)) Next Very difficult
AutoBert Posted October 10, 2016 Posted October 10, 2016 On 10/10/2016 at 1:05 PM, abdulrahmanok said: Very difficult Expand Use FileReadToArray as @BrewManNH suggested.
BrewManNH Posted October 10, 2016 Posted October 10, 2016 I said to use FileReadToArray. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
abdulrahmanok Posted October 10, 2016 Author Posted October 10, 2016 expandcollapse popup#include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <file.au3> Example() Func Example() Local $htry, $sFilePath = @ScriptDir & "/1.txt" Local $hFileOpen, $sFilePath = @ScriptDir & "/try.txt" Local $sFileRead = FileReadLine($hFileOpen, 1) Local $sFileRead2 = FileReadLine($hFileOpen, 2) Local $sFileRead3 = FileReadLine($hFileOpen, 3) Local $sFileRead4 = FileReadLine($hFileOpen, 4) Local $sFileRead5 = FileReadLine($hFileOpen, 5) Local $sFileRead6 = FileReadLine($hFileOpen, 6) Local $sFileRead7 = FileReadLine($hFileOpen, 7) Local $sFileRead8 = FileReadLine($hFileOpen, 8) Local $sFileRead9 = FileReadLine($hFileOpen, 9) Local $sFileRead10 = FileReadLine($hFileOpen, 10) Local $sFileRead11 = FileReadLine($hFileOpen, 11) Local $sFileRead12 = FileReadLine($hFileOpen, 12) Local $sFileRead13 = FileReadLine($hFileOpen, 13) Local $sFileRead14 = FileReadLine($hFileOpen, 14) Local $sFileRead15 = FileReadLine($hFileOpen, 15) ; Create 1D array Local $aArray[] = [$sFileRead ,$sFileRead2,$sFileRead3,$sFileRead4] ; Write it to file _FileWriteFromArray($sFilePath, $aArray, Default, Default, @CRLF) Sleep(1000) ; Re-read it - with count _FileReadToArray($sFilePath, $hFileOpen) _ArrayDisplay($hFileOpen, "1D array - count", Default, 8) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EndFunc ;==>Example maybe almost ...............
BrewManNH Posted October 10, 2016 Posted October 10, 2016 You seriously should just use FileReadToArray and dispense with all of the FileReadLine stuff, it is totally unnecessary. I'm not sure how that is going over your head, but using FileReadLine over and over again to then write a file to be read by FRTA is bizarre to say the least. Also, you don't need _FileReadToArray, you should be using FileReadToArray If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/10/2016 at 2:28 PM, BrewManNH said: You seriously should just use FileReadToArray and dispense with all of the FileReadLine stuff, it is totally unnecessary. I'm not sure how that is going over your head, but using FileReadLine over and over again to then write a file to be read by FRTA is bizarre to say the least. Also, you don't need _FileReadToArray, you should be using FileReadToArray Expand After This Post : https://www.autoitscript.com/forum/topic/185030-read-date-from-menu/#comment-1328997 I learned a little about Arrays And I Created This code : Local $aArray = FileReadToArray(@ScriptDir&"\Calc.txt") If @error Then Else For $i = 0 To UBound($aArray) - 1 ; Loop through the array. ; Read File To Array is Done ExitLoop Next But My Problem Now is to Set This Array Values To ListBox : _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 1 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead)) _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 2 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[0])) ; This is my Try _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 3 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[1])) _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 4 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead4)) _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 5 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead5)) _GUICtrlListBox_AddString($idListBox, StringFormat("Houres For 6 : ")) _GUICtrlListBox_AddString($idListBox, StringFormat($sFileRead6))
l3ill Posted October 17, 2016 Posted October 17, 2016 Should look something like this (untested) Local $aArray = FileReadToArray(@ScriptDir&"\Calc.txt") If @error Then Else For $i = 0 To UBound($aArray) - 1 ; Loop through the array. _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$i])) ; should look more like this ; Read File To Array is Done ;~ ExitLoop Dont exit loop unless there is an error handler Next My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/17/2016 at 9:49 AM, l3ill said: Should look something like this (untested) Local $aArray = FileReadToArray(@ScriptDir&"\Calc.txt") If @error Then Else For $i = 0 To UBound($aArray) - 1 ; Loop through the array. _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$i])) ; should look more like this ; Read File To Array is Done ;~ ExitLoop Dont exit loop unless there is an error handler Next Expand Niiice It's worked ! But It extract Array Like This : 1 2 3 4 and i want it like This : first day 1 second day 2 third day 3 fourth day 4
l3ill Posted October 17, 2016 Posted October 17, 2016 (edited) I need an example of your calc.txt and post your entire updated code please... Edited October 17, 2016 by l3ill My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/17/2016 at 10:06 AM, l3ill said: I need an example of you calc.txt Expand that it : 1 2 3 4 5 but i want add line Before "1" Called Day And Before "2" Called Day ....
l3ill Posted October 17, 2016 Posted October 17, 2016 Try something like this _GUICtrlListBox_AddString($idListBox, "Hours for: " & ($aArray[$i])) _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$i])) ; should look more like this Change "Hours For:" to anything you want. First, Second etc will be more difficult to program, although there is probably a udf for it somewhere... My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/17/2016 at 10:06 AM, l3ill said: I need an example of your calc.txt and post your entire updated code please... Expand Finally Did it by Add another Array : GUICreate("List Box Add String", 400, 296) $idListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $WS_HSCROLL)) GUISetState(@SW_SHOW) Local $aArray2 = FileReadToArray(@ScriptDir&"\try.txt") For $i = 0 To UBound($aArray2) - 1 ; Loop through the array. Next Local $aArray = FileReadToArray(@ScriptDir&"\Calc.txt") If @error Then Else For $i = 0 To UBound($aArray) - 1 ; Loop through the array. _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$i])) ; should look more like this _GUICtrlListBox_AddString($idListBox, StringFormat($aArray2[$i])) ; should look more like this Ty Very Much For Help Finally my Script is clean now
l3ill Posted October 17, 2016 Posted October 17, 2016 Now run Tidy and see what really clean looks like My Contributions... Reveal hidden contents SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/17/2016 at 10:16 AM, l3ill said: Now run Tidy and see what really clean looks like Expand Ty Very Much !
abdulrahmanok Posted October 17, 2016 Author Posted October 17, 2016 On 10/17/2016 at 10:15 AM, l3ill said: Try something like this _GUICtrlListBox_AddString($idListBox, "Hours for: " & ($aArray[$i])) _GUICtrlListBox_AddString($idListBox, StringFormat($aArray[$i])) ; should look more like this Change "Hours For:" to anything you want. First, Second etc will be more difficult to program, although there is probably a udf for it somewhere... Expand Nice Idea
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