Jump to content
Sign in to follow this  
Jibsbrown

Need some help understanding...

Recommended Posts

Need some help understanding why the ConsoleWrite works inside 2nd For loop but not out side. Between Audit Wiki, Help file , Forum searching (lots of code reading), and YouTube ( shout out to TutsTeach), I have not been able to find the reason why. 

$sIniPath = "installLog.ini"

; - Get section name
 $iniSctionNames = IniReadSectionNames($sIniPath)


; - Get Keys and Vaules
For $a = 1 to UBound($iniSctionNames) - 1
    $keys = IniReadSection($sIniPath , $iniSctionNames[$a])
    For $b = 1 to UBound($keys) - 1
        $oldSysInfo = IniRead($sIniPath , $iniSctionNames[1], $keys[$b][0], "")
        $PntIPInfo = IniRead($sIniPath , $iniSctionNames[2], $keys[$b][0], "")
        $NewPCInfor = IniRead($sIniPath , $iniSctionNames[3], $keys[$b][0], "")

        ;ConsoleWrite($oldSysInfo & @LF)
    Next
;ConsoleWrite($oldSysInfo & @LF)
Next


ConsoleWrite($oldSysInfo)

My intention is to use the variables later for Listboxes. Any explanation, forum post links or whatever would help. Sorry also very very new to Autoit.

Also here's the ini file.

[OldSysInfo]
4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8
5=192.168.0.5|SD0123456789101|R9WGP9P
6=192.168.0.6|SD0123456789102|R9WGP9PT
3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P
23=192.168.0.23|SD0123456789102|MXL1234P5I

[PrinterIp]
50=192.168.0.50
48=192.168.0.48
47=192.168.0.47

[NewSysInfo]
newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR

Thank you for your time.

Share this post


Link to post
Share on other sites

Make sure that $oldSysInfo isn't empty at that time:

ConsoleWrite(">" & $oldSysInfo & "<" & @CRLF)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Taks Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

also, you are trying to read from a sectionName with keys that are not present in that sections, so you get empty values.
In the last read you make to set the $oldSysInfo variable, you are trying to find  the key 'newPC' within the [OldSysInfo] section, and since this key is not found there, you get an empty value. Try this snippet to "see" what happens

#include <array.au3>
$sIniPath = "installLog.ini"

; - Get section name
$iniSctionNames = IniReadSectionNames($sIniPath)
; _ArrayDisplay($iniSctionNames, "$iniSctionNames")

; - Get Keys and Vaules
For $a = 1 To UBound($iniSctionNames) - 1
    $keys = IniReadSection($sIniPath, $iniSctionNames[$a])
    ; _ArrayDisplay($keys, "$keys")
    For $b = 1 To UBound($keys) - 1
        $oldSysInfo = IniRead($sIniPath, $iniSctionNames[1], $keys[$b][0], "(?) key " & $keys[$b][0] & " not found in " & $iniSctionNames[1])
        $PntIPInfo = IniRead($sIniPath, $iniSctionNames[2], $keys[$b][0], "(?) key " & $keys[$b][0] & " not found in " & $iniSctionNames[2])
        $NewPCInfor = IniRead($sIniPath, $iniSctionNames[3], $keys[$b][0], "(?) key " & $keys[$b][0] & " not found in " & $iniSctionNames[3])

        ConsoleWrite("[" & $iniSctionNames[1] & '] ' & $keys[$b][0] & '=' & $oldSysInfo & @TAB & "[" & $iniSctionNames[2] & '] ' & $keys[$b][0] & '=' & $PntIPInfo & @TAB & "[" & $iniSctionNames[3] & '] ' & $keys[$b][0] & '=' & $NewPCInfor & @LF)
    Next
    ConsoleWrite("------------------------" & @CRLF & $oldSysInfo & @CRLF & "========================" & @CRLF) ; $oldSysInfo & @LF)
Next

ConsoleWrite("> " & $oldSysInfo & " <" & @CRLF & @CRLF)

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Thank you Water and Chimp, the logic check helped. Realize now that what I wanted to do was this... 

Global $sIniPath = "installLog.ini"
;ConsoleWrite($sIniPath)

$iniSctionNames = IniReadSectionNames($sIniPath)
; _ArrayDisplay($iniSctionNames, "$iniSctionNames")
$keys1 = IniReadSection($sIniPath, $iniSctionNames[1])
$keys2 = IniReadSection($sIniPath, $iniSctionNames[2])
$keys3 = IniReadSection($sIniPath, $iniSctionNames[3])
;_ArrayDisplay($keys1, "$keys")
ConsoleWrite($keys1[1][1])

And Chimp thank you for code below..

;_ArrayDisplay($keys1, "$keys")

Just could not get my brain to understand what the Help file was talking about. Let alone make it do anything.

Share this post


Link to post
Share on other sites

Don't know if I can add to this topic or not. So if I'm wrong please advise proper etiquette.

Need to ask for some additional understanding. 

What have I gotten wrong with the below code? ArrayDisplays shows that $keys2 has data and ConsoleWrite write the correct text, but the ListView is blank. Still using the same Ini file posted at the top of the topic.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#include <File.au3>


Global $sIniPath = "installLog.ini"
;ConsoleWrite($sIniPath)

$iniSctionNames = IniReadSectionNames($sIniPath)
 ;_ArrayDisplay($iniSctionNames, "$iniSctionNames")
 $keys2 = IniReadSection($sIniPath, $iniSctionNames[2])
_ArrayDisplay($keys2 , "$keys2")


; Create GUI
$hGUI = GUICreate("Test", 600, 500)

; Create ListView

$cLV = GUICtrlCreateListView("", 10, 10, 580, 300)

For $i = 1 To UBound($keys2) - 1
ConsoleWrite($keys2[$i][1] & @CRLF)

_GUICtrlListView_AddArray($cLV, $keys2[$i][0])
    
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

And I did try it with GUICtrlListView_AddArray($cLV, $Keys2[$i][1]) with the same result.

Edited by Jibsbrown

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By jmp
      Script running good but error in line 7.
      When i run this script :
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData = _IETableWriteToArray ($oTable) For $inumber = 1 To UBound($aTableData) -1 $table = $aTableData[4][$inumber] MsgBox(0, "", $table) Next I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
    • By nacerbaaziz
      hello sirs, please help me
      i tried to create a function that read a folder files to 3d array
      e.g
      $array[n][0][0] = ctName
      $array[n][0][1] = ctFilePath
      $array[n][0][2] = crtsections number
      $array[n][m][0] = KeyName
      $array[n][m][1] = KeyVal
      $array[n][m][2] = keySectionName
       
      that the array
      when i put one file into the folder all things work fine
      but when i put more than one file
      the last file worked fine but the others only the first key is showing
      please can you help me to correct this problem
      here is the example with the folder
      please accept my greetings
      and thanks in advance
       
      array3d.zip
    • By argumentum
      There is a _ArrayToString() but no _ArrayFromString().  ( searched in the forum and google )
      The example is based on the _ArrayToString() help file, to show the reconstruction of the array.
      #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[20] For $i = 0 To 19 $aArray[$i] = $i Next _ArrayDisplay($aArray, "1D Array") MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7)) ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString") Local $aArray[10][10] For $i = 0 To 9 For $j = 0 To 9 $aArray[$i][$j] = $i & "-" & $j Next Next _ArrayDisplay($aArray, "2D Array") MsgBox($MB_SYSTEMMODAL, "Rows 4-7, cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5)) ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString") ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|" If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF $iForce2D = Int($iForce2D) Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 And Not $iForce2D Then Return $b Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString
      PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies )
      #include <Array.au3>; For _ArrayDisplay() ; if you declare it, it will use it, else, use default ;Global $g_iniFile = @ScriptDir & "\ThisTest.ini" Example() Func Example() Local $n, $aTest, $aArray[3] = ["00", "one", "2"] ; if is not in the INI file, it will save it $aTest = IniGet("Test", $aArray) _ArrayDisplay($aTest, "1st") ; since is saved, it'll recall it $aTest = IniGet("Test") For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1) Next _ArrayDisplay($aTest, "2nd") EndFunc ;==>Example Func IniGet($sKey, $vDefault = Default, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1)) If $s = Chr(1) Then If $vDefault == Default Then Return SetError(1, 0, "") Else IniSet($sKey, $vDefault, $sSection) Return $vDefault EndIf EndIf $v = StringLeft($s, 1) Switch $v Case "i" Return Int(StringTrimLeft($s, 2)) Case "a" Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2)) Case "d" Return Binary(StringTrimLeft($s, 2)) Case Else Return String(StringTrimLeft($s, 2)) EndSwitch EndFunc ;==>IniGet Func IniSet($sKey, $vValue, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" If IsInt($vValue) Then $vValue = "i:" & $vValue ElseIf IsArray($vValue) Then $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2))) ElseIf IsBinary($vValue) Then $vValue = "d:" & $vValue Else $vValue = "s:" & $vValue EndIf $vValue = IniWrite($ini, $sSection, $sKey, $vValue) Return SetError(@error, @extended, $vValue) EndFunc ;==>IniSet ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() Func _ArrayFromString($sString, $sDelim_Col = "|", $sDelim_Row = @CRLF, $iForce2D = 0,) ; https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ If $sDelim_Col = Default Or String($sDelim_Col) = "" Then $sDelim_Col = "|" If $sDelim_Row = Default Or String($sDelim_Row) = "" Then $sDelim_Row = @CRLF $iForce2D = Int($iForce2D) Local $m, $n, $b, $c = StringSplit($sString, $sDelim_Row, 3) ; $STR_ENTIRESPLIT + $STR_NOCOUNT $b = StringSplit($c[0], $sDelim_Col, 3) If UBound($c) = 1 And Not $iForce2D Then Return $b Local $a[UBound($c)][UBound($b)] For $n = 0 To UBound($c) - 1 $b = StringSplit($c[$n], $sDelim_Col, 3) If UBound($b) > UBound($a, 2) Then Return SetError(1) For $m = 0 To UBound($b) - 1 $a[$n][$m] = $b[$m] Next Next Return $a EndFunc ;==>_ArrayFromString
      PS2: https://www.autoitscript.com/trac/autoit/ticket/3696#ticket
×
×
  • Create New...