Jump to content

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.

Link to comment
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 2022-02-19 - Version 1.6.1.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 (NEW 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

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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.

Link to comment
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
Link to comment
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
 Share

×
×
  • Create New...