jchd Posted March 26, 2019 Share Posted March 26, 2019 You can as well get rid of the individual variables names. #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> Local $m1k = IniReadSection("illogic3.ini", "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) MsgBox(0, 0, $m1k[0] & " " & $m1k[1] & " " & $m1k[2] & " " & $m1k[3] & " " & $m1k[4] & @CRLF & _ $m1k[5] & " " & $m1k[6] & " " & $m1k[7] & " " & $m1k[8] & " " & $m1k[9]) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
roeselpi Posted March 26, 2019 Author Share Posted March 26, 2019 @nine oh, okay i get the hang slowly now. that is the kind of automation i am talking about. let me look at that a while and then i will come back with results or more questions. but: thanks a lot. that looks great, now i must find out how to use it. Link to comment Share on other sites More sharing options...
Bilgus Posted March 26, 2019 Share Posted March 26, 2019 Don't forget Enum that way you can call the element by a name if you so desire #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> Enum #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> Enum m1k_00 = 0, m1k_01, m1k_02, m1k_03, m1k_04, m1k_05, m1k_06, m1k_07, m1k_08, m1k_09 Local $m1k = IniReadSection("illogic3.ini", "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) MsgBox(0, 0, $m1k[0] & " " & $m1k[1] & " " & $m1k[2] & " " & $m1k[3] & " " & $m1k[4] & @CRLF & _ $m1k[5] & " " & $m1k[6] & " " & $m1k[7] & " " & $m1k[8] & " " & $m1k[9]) ;Equivalent MsgBox(0, 0, $m1k[m1k_00] & " " & $m1k[m1k_01] & " " & $m1k[m1k_02] & " " & $m1k[m1k_03] & " " & $m1k[m1k_04] & @CRLF & _ $m1k[m1k_05] & " " & $m1k[m1k_06] & " " & $m1k[m1k_07] & " " & $m1k[m1k_08] & " " & $m1k[m1k_09]) Link to comment Share on other sites More sharing options...
jchd Posted March 26, 2019 Share Posted March 26, 2019 You forgot the $ everywhere in your Enum. Also how $m1k[$m1k_00] is simpler or clearer than $m1k[0]? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Bilgus Posted March 26, 2019 Share Posted March 26, 2019 (edited) @jchd good point on the $, as far as being clearer in this case perhaps not but it is clearer when you start fleshing out the code for the actual use I can't imagine m1k00 = 0 is much more than* a test Edited March 26, 2019 by Bilgus Link to comment Share on other sites More sharing options...
roeselpi Posted March 26, 2019 Author Share Posted March 26, 2019 hello, after testing and going through all of the codes, i think i am going to go with the one from jchd because it is only two lines of code to achieve what i want it to do. i can now get the ini data into the script and use it in different places. thanks a million times for that. the thanks does however go out to all the people who tried to help me here. it is greatly apreciated. i have one question now concerning a loop or lets just call it a check. if the script can check how many modes (categories) there are and act accordingly to that. in other words, i did this manually: Local $m1k = IniReadSection("illogic3.ini", "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) ;_ArrayDisplay($m1k) MsgBox(0, 0, $m1k[0] & " " & $m1k[1] & " " & $m1k[2] & " " & $m1k[3] & " " & $m1k[4] & @CRLF & _ $m1k[5] & " " & $m1k[6] & " " & $m1k[7] & " " & $m1k[8] & " " & $m1k[9]) Local $m2k = IniReadSection("illogic3.ini", "mode 2") $m2k = _ArrayExtract($m2k, 1, -1, 1, 1) ;_ArrayDisplay($m2k) MsgBox(0, 0, $m2k[0] & " " & $m2k[1] & " " & $m2k[2] & " " & $m2k[3] & " " & $m2k[4] & @CRLF & _ $m2k[5] & " " & $m2k[6] & " " & $m2k[7] & " " & $m2k[8] & " " & $m2k[9]) i know there are two ore three or how ever many modes, but the script does not. my best guess would now be something like this: For $i = 1 To 10 Step 1 $a = "mode 1" If $a = "mode 1" Then Local $m1k = IniReadSection("illogic3.ini", "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) If $a = "mode 2" Then Local $m2k = IniReadSection("illogic3.ini", "mode 2") $m2k = _ArrayExtract($m2k, 1, -1, 1, 1) If $a = "mode n" Then Local $mnk = IniReadSection("illogic3.ini", "mode 2") $mnk = _ArrayExtract($mnk, 1, -1, 1, 1) Next EndIf so can i do something like that? check to see how many categories there are and read the values into an array from all of them? even if that should not be possible, it would not really matter. the solution is fine the way it is and i am more than happy with it. kind regards Link to comment Share on other sites More sharing options...
jchd Posted March 26, 2019 Share Posted March 26, 2019 IniReadSectionNames() will tell you which are the sections in your .INI This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
BrewManNH Posted March 26, 2019 Share Posted March 26, 2019 Just an FYI, don't forget that INI functions are not guaranteed to be created in any particular order, so if things get changed in the INI file, your values may end up in the wrong place in the array. 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! 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 Link to comment Share on other sites More sharing options...
roeselpi Posted March 27, 2019 Author Share Posted March 27, 2019 Quote Just an FYI, don't forget that INI functions are not guaranteed to be created in any particular order, so if things get changed in the INI file, your values may end up in the wrong place in the array. but as long as the order in the ini file does not change, it should be okay or not? meaning if i just change the values in the ini file then everything should reamain in place, right? of course i can understand that if other features are additionally placed in the ini, then the whole system would collapse but if i just change the values then it should be good. (i hope). Quote IniReadSectionNames() will tell you which are the sections in your .INI thanks. that will get me well on my way. okay, i guess that concludes my questions. thank you all very much for your help. it is much appreciated. kind regards Link to comment Share on other sites More sharing options...
roeselpi Posted April 3, 2019 Author Share Posted April 3, 2019 (edited) hello, hold on, there still is a bug. i can read and display the ini values in a message box, but i can not use all of them. it only always uses the first value. when used then it transforms the editbox text from: Quote This is a Test entry! only always to the first possibility of each mode: Quote b0bTb0bhb0bib0bsb0b_b0bib0bsb0b_b0bab0b_b0bTb0beb0bsb0btb0b_b0beb0bnb0btb0brb0byb0b!b0b it should however look something like this: Quote b0bTb1bhb2bib3bsb0b_b1bib2bsb3b_b0bab1b_b2bTb3beb0bsb1btb2b_b3beb0bnb1btb2brb3byb0b!b1b because there are 4 values in each ini-mode but it always only uses the first. strange. i have made a smaller version without much design, just as demontration: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> #include <ComboConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 259, 216, -1, -1) Global $Edit1 = GUICtrlCreateEdit("", 16, 80, 225, 113, $ES_WANTRETURN + $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE) GUICtrlSetData(-1, "This is a Test entry!") Global $Radio1 = GUICtrlCreateRadio("ini-file", 16, 8, 113, 17) Global $Button1 = GUICtrlCreateButton("Button1", 168, 8, 75, 17) Global $Group1 = GUICtrlCreateGroup("mode selection", 16, 32, 225, 41) Global $Radio2 = GUICtrlCreateRadio("mode 1", 24, 48, 60, 17) Global $Radio3 = GUICtrlCreateRadio("mode 2", 88, 48, 60, 17) Global $Radio4 = GUICtrlCreateRadio("mode 3", 168, 48, 60, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Radio1 $file1 = "test.ini" Case $Radio2 If GUICtrlRead($Radio1) = 1 Then $m1k = IniReadSection($file1, "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) $m1k00 = $m1k[0] $m1k01 = $m1k[1] $m1k02 = $m1k[2] $m1k03 = $m1k[3] Global $Mode1Array = [$m1k[0], $m1k[1], $m1k[2], $m1k[3]] ; Mode 1 ;Global $Mode1Array = [$m1k00, $m1k01, $m1k02, $m1k03] ; Mode 1 MsgBox(0, 0, $m1k[0] & " " & $m1k[1] & " " & $m1k[2] & " " & $m1k[3]) EndIf Case $Radio3 If GUICtrlRead($Radio1) = 1 Then $m2k = IniReadSection($file1, "mode 2") $m2k = _ArrayExtract($m2k, 1, -1, 1, 1) $m2k00 = $m2k[0] $m2k01 = $m2k[1] $m2k02 = $m2k[2] $m2k03 = $m2k[3] Global $Mode2Array = [$m2k[0], $m2k[1], $m2k[2], $m2k[3]] ; Mode 2 ;Global $Mode2Array = [$m2k00, $m2k01, $m2k02, $m2k03] ; Mode 2 MsgBox(0, 0, $m2k[0] & " " & $m2k[1] & " " & $m2k[2] & " " & $m2k[3]) EndIf Case $Radio4 If GUICtrlRead($Radio1) = 1 Then $m3k = IniReadSection($file1, "mode 3") $m3k = _ArrayExtract($m3k, 1, -1, 1, 1) $m3k00 = $m3k[0] $m3k01 = $m3k[1] $m3k02 = $m3k[2] $m3k03 = $m3k[3] Global $Mode3Array = [$m3k[0], $m3k[1], $m3k[2], $m3k[3]] ; Mode 3 ;Global $Mode3Array = [$m3k00, $m3k01, $m3k02, $m3k03] ; Mode 3 MsgBox(0, 0, $m3k[0] & " " & $m3k[1] & " " & $m3k[2] & " " & $m3k[3]) EndIf Case $Button1 $text = GUICtrlRead($Edit1) ConsoleWrite($text) $gaps = StringReplace($text, " ", "_") ConsoleWrite($gaps) GUICtrlSetData($Edit1, $gaps) $text = GUICtrlRead($Edit1) ConsoleWrite($text) $Str = $text $Arr = StringSplit($Str, "") _ArrayDisplay($Arr) $Arr[0] = "" ; ============================================================ Mode 1: If GUICtrlRead($Radio2) = 1 Then $FirstIndex = $Mode1Array Global $NewString = "" Global $a = $FirstIndex $Raws = UBound($Arr) For $i = 1 To $Raws Step 1 $a -= 1 If $a = 0 Then $a = $FirstIndex $NewString = $NewString & $Arr[$i - 1] & $Mode1Array[$a - 1] Next ; ============================================================ Mode 2: ElseIf GUICtrlRead($Radio3) = 1 Then $SecondIndex = $Mode2Array Global $NewString = "" Global $b = $SecondIndex $Raws = UBound($Arr) For $i = 1 To $Raws Step 1 $b -= 1 If $b = 0 Then $b = $SecondIndex $NewString = $NewString & $Arr[$i - 1] & $Mode2Array[$b - 1] Next ; ============================================================ Mode 3: ElseIf GUICtrlRead($Radio4) = 1 Then $ThirdIndex = $Mode3Array Global $NewString = "" Global $c = $ThirdIndex $Raws = UBound($Arr) For $i = 1 To $Raws Step 1 $c -= 1 If $c = 0 Then $c = $ThirdIndex $NewString = $NewString & $Arr[$i - 1] & $Mode3Array[$c - 1] Next EndIf If GUICtrlRead($Radio2) = 1 Then GUICtrlSetData($Edit1, $NewString) If GUICtrlRead($Radio3) = 1 Then GUICtrlSetData($Edit1, $NewString) If GUICtrlRead($Radio4) = 1 Then GUICtrlSetData($Edit1, $NewString) EndSwitch WEnd as far as i can tell from testing a whole lot, the problem lies here in this part: If GUICtrlRead($Radio2) = 1 Then $FirstIndex = $Mode1Array Global $NewString = "" Global $a = $FirstIndex $Raws = UBound($Arr) For $i = 1 To $Raws Step 1 $a -= 1 If $a = 0 Then $a = $FirstIndex $NewString = $NewString & $Arr[$i - 1] & $Mode1Array[$a - 1] Next whatever the problem is there, it is for all modes the same. somehow it only takes the first value and not the other values. has anybody got an idea where the error might be and would take the time to show me where (and possibly: why) the error is and give me an idea on how to correct it. it does not matter to me if it works in a chronological/numericle or randomized manner. the only thing that is important, is that it uses all values from the mode that is active. help me please. kind regards test.ini test.au3 Edited April 3, 2019 by roeselpi made one minor error. corrected it. Link to comment Share on other sites More sharing options...
roeselpi Posted April 3, 2019 Author Share Posted April 3, 2019 the problem does not lie where i thought it does, it seems to be this line: Global $Mode1Array = [$m1k[0], $m1k[1], $m1k[2], $m1k[3]] ; Mode 1 ;Global $Mode1Array = [$m1k00, $m1k01, $m1k02, $m1k03] ; Mode 1 because a second msgbox i tested: MsgBox(0, 0, $Mode1Array) did not result in anything at all. now i have to figure out how to get the extracted data from the ini into the replace (mode) array. any ideas? Link to comment Share on other sites More sharing options...
roeselpi Posted April 4, 2019 Author Share Posted April 4, 2019 hi, okay i have done a lot of changes and am one or two steps further now: i have narrowed the problem down to one for-loop which does not cycle through the ini values more than once and that is the problem. i have edited the script to make it very short and marked the error in the comment section very near to the end of the script: any help on fixing the for-loop would be much apreciated: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> #include <ComboConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 259, 216, -1, -1) Global $Edit1 = GUICtrlCreateEdit("", 16, 80, 225, 113, $ES_WANTRETURN + $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_MULTILINE) GUICtrlSetData(-1, "This is a Test entry!") Global $Radio1 = GUICtrlCreateRadio("ini-file", 16, 8, 113, 17) Global $Button1 = GUICtrlCreateButton("Button1", 168, 8, 75, 17) Global $Group1 = GUICtrlCreateGroup("mode selection", 16, 32, 225, 41) Global $Radio2 = GUICtrlCreateRadio("mode 1", 24, 48, 60, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Radio1 $file1 = "test.ini" Case $Radio2 If GUICtrlRead($Radio1) = 1 Then $m1k = IniReadSection($file1, "mode 1") $m1k = _ArrayExtract($m1k, 1, -1, 1, 1) $m1k00 = $m1k[0] $m1k01 = $m1k[1] $m1k02 = $m1k[2] $m1k03 = $m1k[3] Global $Mode1Array[4] = [$m1k00, $m1k01, $m1k02, $m1k03] EndIf Case $Button1 $text = GUICtrlRead($Edit1) $gaps = StringReplace($text, " ", "_") GUICtrlSetData($Edit1, $gaps) $text = GUICtrlRead($Edit1) $Str = $text $Arr = StringSplit($Str, "") $Arr[0] = "" If GUICtrlRead($Radio2) = 1 Then $FirstIndex = $Mode1Array Global $NewString = "" Global $a = $FirstIndex For $Raws = 1 To (UBound($Arr) - 1) ;ConsoleWrite($Raws & @CRLF) Next For $a = 0 To (UBound($FirstIndex) - 1) ;ConsoleWrite($FirstIndex[$a] & @CRLF) Next #comments-start in the next part below is where the fault is: at the moment it outputs the data like this: a2aTa1aha0aia0asa0a_a0aia0asa0a_a0aaa0a_a0aTa0aea0asa0ata0a_a0aea0ana0ata0ara0aya0a!a0a for some reason it starts with a2a, then goes to a1a and then to a0a and then it just stays on a0a all the rest of the time. it should however cycle through all the time: a0a -> a1a -> a2a -> a3a -> a0a -> a1a -> etc. the code below has the error, but i do not understand where the error is? help please. #comments-end For $i = 1 To $Raws Step 1 $a -= 1 If $a = 1 Then $a = $FirstIndex $NewString = $NewString & $Arr[$i - 1] & $Mode1Array[$a - 1] Next EndIf If GUICtrlRead($Radio2) = 1 Then GUICtrlSetData($Edit1, $NewString) EndSwitch WEnd kind regards PS: ini-file: [mode 1] m1k00=a0a m1k01=a1a m1k02=a2a m1k03=a3a it is a very light version. i only need it to work once and then can adapt it to my needs later. 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