iahngy Posted October 1, 2016 Share Posted October 1, 2016 I have a very long file of data , if entering on the excel it has colums and rows for some kinds of recipe for diff process of tools...but i m not allowed to use txt or excel.. how do i put such long data from a text file directly on the script ...the whole purpose is i trying to display the data on the listview without depending on txt file /excel ? Link to comment Share on other sites More sharing options...
water Posted October 1, 2016 Share Posted October 1, 2016 What do you mean by "without depending on txt file"? What kind of "file of data" do you need to process? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iahngy Posted October 1, 2016 Author Share Posted October 1, 2016 i mean how do i put the whole text data on to the script to display them using listview ...but like hardcoded...once time of use the file only ...and whenever the script open ..the script get the data from it's self ..not from any file anymore. Link to comment Share on other sites More sharing options...
water Posted October 1, 2016 Share Posted October 1, 2016 Please have a look at FileInstall. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iahngy Posted October 1, 2016 Author Share Posted October 1, 2016 i read it ..it is for install a file but ...my case , I 'd like to know how do i put data of a file on to the script so it only use within the script . for example, i have these in a test.txt file 00,01,02,03 10,11,12,13 20,21,22,23 30,31,32,33 if i type it into an array 2D like below , it will take forever ...i dont know if there is any code for presenting those data from a file onto the script instead of typing into 2D array. so the script doenst use the txt file every time it is opened. Local $aArray[][] = [ _ ["00", "01", "02", "03"], _ ["10", "11", "12", "13"], _ ["20", "21", "22", "23"], _ ["30", "31", "32", "33"]] Link to comment Share on other sites More sharing options...
water Posted October 1, 2016 Share Posted October 1, 2016 What's wrong with reading the file very time you run the script? Create a second script to process the file once and create the needed output, then copy this output to your first script. Shouldn't be too hard to use FileRead, StringSplit plus some string concatenation to create the needed output. The first and last line would need some manual brush up though. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
AutoBert Posted October 1, 2016 Share Posted October 1, 2016 (edited) Why not using _FileReadToArray? #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <File.au3> #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Example() Func Example() Local $iTimer, $idListview Local $aArray _FileReadToArray('test.txt',$aArray,$FRTA_NOCOUNT,',') ; Create GUI GUICreate("ListView Add Array", 400, 300) $idListview = GUICtrlCreateListView("Items|SubItems 1|SubItems 2|SubItems 3", 2, 2, 394, 268) GUISetState(@SW_SHOW) $iTimer = TimerInit() _GUICtrlListView_AddArray($idListview, $aArray) MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example In the test.txt file is data posted by you in https://www.autoitscript.com/forum/topic/184813-put-txt-file-data-on-to-the-script/?do=findComment&comment=1327458 Nearly the same example, but now the LV-Header is the row 1 of Test.txt: #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <File.au3> #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Example() Func Example() Local $iTimer, $idListview Local $aArray, $sPath='test.txt' Local $sHeader=StringReplace(FileReadLine($sPath),',','|') _FileReadToArray($sPath,$aArray,$FRTA_NOCOUNT,',') _ArrayDelete($aArray,0) ; Create GUI GUICreate("ListView Add Array", 400, 300) $idListview = GUICtrlCreateListView($sHeader, 2, 2, 394, 268) GUISetState(@SW_SHOW) $iTimer = TimerInit() _GUICtrlListView_AddArray($idListview, $aArray) MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Edited October 2, 2016 by AutoBert Link to comment Share on other sites More sharing options...
iahngy Posted October 1, 2016 Author Share Posted October 1, 2016 Thank you..at work they dont let people use any file/script...I m waiting on permission to use just the script ...I m thinkig reading the file and convert string to array ...i dont remember the syntax for from string to a code though. Ah i hvent use AutoIT for a long time ago since my work changed. Link to comment Share on other sites More sharing options...
water Posted October 2, 2016 Share Posted October 2, 2016 Example script to read a file and create an array structure as described by you: #include <Array.au3> #include <File.au3> Global $aFileRead _FileReadToArray(@ScriptDir & "\Test_Input.txt", $aFileRead, $FRTA_COUNT, ",") _ArrayDisplay($aFileread) Global $hFileWrite = FileOpen(@ScriptDir & "\Test_Output.au3", $FO_APPEND) FileWriteLine($hFileWrite, "Local $aArray[][] = [ _") Global $sTemp = "" For $i = 1 To $aFileread[0][0] $sTemp = "[" For $j = 0 To $aFileread[0][1] - 1 $sTemp = $sTemp & '"' & $aFileread[$i][$j] & '"' If $j < $aFileread[0][1] - 1 Then $sTemp = $sTemp & ',' Next If $i < $aFileread[0][0] Then $sTemp = $sTemp & '], _' Else $sTemp = $sTemp & '] _' EndIf FileWriteLine($hFileWrite, $sTemp) Next FileWriteLine($hFileWrite, ']') My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iahngy Posted October 3, 2016 Author Share Posted October 3, 2016 Thank you Water, I have the script working by converting xcel to string and assigned the variable string equal that string. Would you tell me how to convert an input from input box to a digit? i think it only supply strings and i tried to activate the excel sheet from the input ..it never takes the numbers...but if i manually enter the number in the function ..it works. Link to comment Share on other sites More sharing options...
water Posted October 3, 2016 Share Posted October 3, 2016 You found the solution yourself Use function "Number" to convert a string to a number. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iahngy Posted October 6, 2016 Author Share Posted October 6, 2016 I have another new problem..is there a way to edit the string and save it from the gui? i m using listview to display the string . Link to comment Share on other sites More sharing options...
AutoBert Posted October 6, 2016 Share Posted October 6, 2016 Look in @Melba23 signatur. Afair is there a link to ListviewEx Link to comment Share on other sites More sharing options...
iahngy Posted October 6, 2016 Author Share Posted October 6, 2016 I dont think it is easy to edit a code from a gui ( like a string ) ...I tried Melba's code ..it just temporarily edit ..but after reopen the gui..it only shows the original again. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2016 Moderators Share Posted October 6, 2016 iahngy, Quote I tried Melba's code ..it just temporarily edit No, the UDF will permanently change the ListView content - but you then need to save that content to a file if you want to read in the modified data again when the script restarts. If you do not do that then the original data will be re-read and you get what you describe. How about posting the code you are using so we can offer some 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iahngy Posted October 6, 2016 Author Share Posted October 6, 2016 Melba, wonder why you use file extention ".lvs " for ? why not .txt or csv ? I was reading your examples...Still i ran out of time ..i ll try to write one tonight ..but i wonder if you have any short example of listviewex for display color certain cell and hightlight the cell selected ? sorry ..i m going to market but will try to write one later. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2016 Moderators Share Posted October 6, 2016 (edited) iahngy, Quote Melba, wonder why you use file extention ".lvs " for ? why not .txt or csv ? If you are referring to the files I use in the examples to save the ListView content then you can use any extension you wish - there is nothing special about the one I use. Quote any short example of listviewex for display color certain cell and hightlight the cell selected ? The selected cell is always highlighted (highlit?) and you colour specific cells using _GUIListViewEx_SetColour. Post the code you have tried and I will see what I can do to make it work. M23 Edited October 6, 2016 by Melba23 Typo 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
iahngy Posted October 7, 2016 Author Share Posted October 7, 2016 I cant find the button to insert code...I attached the file ... I only add 2 basic things : to hight light the selected cell but it highlight the whole row , and to add color for certain cell but it doesnt show color.. Would you please fix for me ..Also would you add the feature edit the cell or delete the cells and save it and open the script again with new edited one. rosea.au3 Link to comment Share on other sites More sharing options...
iahngy Posted October 7, 2016 Author Share Posted October 7, 2016 (edited) i got cell highlight working now ..thank you verymuch ..forgot to put register function before gui set state. when i set state $lvI = _GUIListViewEx_Init($idLV, $qa, 0, 0, False, 32+512) it errs . "C:\Program Files\AutoIt3\Include\GUIListViewEx.au3" (3159) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If StringInStr(($aGLVEx_Data[0][13])[$iItem + 1][$iSubItem], ";") Then If StringInStr(($aGLVEx_Data[0][13]^ ERROR Edited October 7, 2016 by iahngy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 7, 2016 Moderators Share Posted October 7, 2016 (edited) iahngy, I had to add/delete a few commas to your text to get the same number of elements on each line, but once that is done it seems to work quite nicely: expandcollapse popup#include <GUIConstantsEx.au3> #include <Array.au3> #include <File.au3> #include "GUIListViewEx.au3" ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Just for the example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global $str = "" _ & "*Fungal Diseases,*Black Spot,*Control1,*Control2,,,,," & @CRLF _ & ",Warm, wet weather,destroy leaves,,,,," & @CRLF _ & ",watery leaves,Avoid watering.,,,,,," & @CRLF _ & ",black spots,Avoid shady ,,,,,," & @CRLF _ & ",,improve pH,,,,,," & @CRLF _ & ",*Powdery Mildew,*Control,,,,,," & @CRLF _ & ",whitish coating,sprayed preventatively,,,,,," & @CRLF _ & ",temp 80F,,,,,,," & @CRLF _ & ",humidity 97%,,,,,,," & @CRLF _ & ",,,,,,,," & @CRLF _ & ",*Stem Cankers ,*control,,,,,," & @CRLF _ & ",improper pruning,fungicide spray,,,,,," & @CRLF _ & ",,Prune out,,,,,," & @CRLF _ & ",,1/4 inch bud ,,,,,," & @CRLF _ & ",,slanted away,,,,,," & @CRLF _ & ",,,,,,,," & @CRLF _ & "*Roses resist spot,*Cultivar ,*Type, Height,Color, Fragrant,,," & @CRLF _ & ",Pink Peace , Hybrid , 3 to 4,pink, Very fragrant,,," & @CRLF _ & ",Tiffany, Tea,4 to 5,lpink,Yes,,," & @CRLF _ & ",Tropicana,HT,5 to 6,red,OK fragrant,,," & @CRLF _ & ",,,,,,,," & @CRLF _ & "*Rose Virus ,Mosaic Virus,Control,,,Rose Rosette,Control,," & @CRLF _ & ",through grafting,aphids leafhoppers,,,multiflora,horti oil,," & @CRLF _ & ",,Control weeds,,,veget shoots,insect soap,," & @CRLF _ & ",,,,,crinkled Leaves,Remove plant,," & @CRLF _ & ",,,,,wingless mite,,," & @CRLF _ & ",,,,,reddish excess thorny ,,," & @CRLF _ & ",,,,,Witches-broom,,," ; Create file if it does not exist If Not FileExists($sFilePath) Then FileWrite($sFilePath, $str) EndIf ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Just for the example ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Set ListView coordinates Global $iLVx = 40, $iLVy = 80, $iLVw = 1100, $iLVh = 700 ; File to be read Global $sFilePath = @ScriptDir & "\wenote.txt" ; ListView Index with place holder value Global $lvI = 9999 ; Create GUI $Form1 = GUICreate("AForm1", 1201, 800, 193, 115) $Button1 = GUICtrlCreateButton("Rose ", 32, 16, 75, 25, 0) $btest = GUICtrlCreateButton("Dahliah", 128, 16, 75, 25, 0) $btest1 = GUICtrlCreateButton("Peony", 216, 16, 75, 25, 0) $btest2 = GUICtrlCreateButton("String2Array", 304, 16, 75, 25, 0) $Input1 = GUICtrlCreateInput("AInput1", 400, 16, 321, 21) $Label1 = GUICtrlCreateLabel("ALabel1", 752, 16, 139, 17) $idLV = GUICtrlCreateListView("", $iLVx, $iLVy, $iLVw, $iLVh) _GUIListViewEx_MsgRegister() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btest2 $a2d = s2l() ; Read file to arrau dellist() ; delete old listview makelist($a2d) ; Create new one EndSwitch ; Look for edits $aRet = _GUIListViewEx_EditOnClick() If IsArray($aRet) Then x2n() EndIf WEnd Func x2n() ; Get current ListView content Local $aArray = _GUIListViewEx_ReturnArray($lvI) ; Convert all "|" to "," $sData = _ArrayToString($aArray, ",") ; Save to the file so it is loaded next time $hFile = FileOpen($sFilePath, $FO_OVERWRITE) FileWrite($hFile, $sData) FileClose($hFile) EndFunc ;==>x2n Func makelist($qa) Local $iRows = UBound($qa), $iCols = UBound($qa, 2) Local $iWidth = Int($iLVw / $iCols) - 5 ; Recreate ListView $idLV = GUICtrlCreateListView("", $iLVx, $iLVy, $iLVw, $iLVh) ; Create correct number of columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn($idLV, "", $iWidth) Next ; Load data array _GUICtrlListView_AddArray($idLV, $qa) ; ListView initialise $lvI = _GUIListViewEx_Init($idLV, $qa, 0, 0, False, 32 + 512) ; All columns editable _GUIListViewEx_SetEditStatus($lvI, "*") ; Colour a specific cell _GUIListViewEx_SetColour($lvI, ";0x00FF00", 1, 1) EndFunc ;==>makelist Func s2l() ;string 2 array Local $aArray _FileReadToArray($sFilePath, $aArray, $FRTA_NOCOUNT, ",") ;_ArrayDisplay($aArray, @error, Default, 8) Return $aArray EndFunc ;==>s2l Func dellist() ; Remove from UDF _GUIListViewEx_Close($lvI) ; Delete ListView GUICtrlDelete($idLV) EndFunc ;==>dellist I hope the comments are self-explanatory, but please do ask if you have any questions. M23 Edited October 7, 2016 by Melba23 Typo 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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