Sign in to follow this  
Followers 0
gcue

"subscript used with non-array variable" ?

7 posts in this topic

hello.

i am trying to process an INI file that has multiple sections. within each section a list of devices with their ips. as such:

[location1]

printer1=29.1.12.1

computer1=292.21.21.1

[location2]

printer1=292.1.12.1

server=21.1.1.1.

you get the idea...

heres what i have (at this point im just trying to sort out the variable part):

$location = IniReadSectionNames(@ScriptDir & "\devices.ini")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    
    For $i = 1 To $location[0]

      $device = IniReadSection(@scriptdir & "\devices.ini", "$location[i]")

      For $p = 1 To $device[0][0]
        MsgBox(4096, "", "Location: " & $location[$i][0] &  @CRLF & "Key: " & $device[$p][0] & @CRLF & "Value: " & $device[$p][1])
      Next

  Next
EndIf

Share this post


Link to post
Share on other sites



$device = IniReadSection(@scriptdir & "\devices.ini", $location)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Try this. I think I fixed the errors but I'm just winging it so it's untested.

$location = IniReadSectionNames(@ScriptDir & "\devices.ini")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    
    For $i = 1 To $location[0]

      $device = IniReadSection(@scriptdir & "\devices.ini", "$location[$i]")

      For $p = 1 To $device[0][0]
        MsgBox(4096, "", "Location: " & $location[$i] &  @CRLF & "Key: " & $device[$p][0] & @CRLF & "Value: " & $device[$p][1])
      Next

  Next
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

thanks for the quick response.

now im getting a different error:

error in parsing function call

not sure where thats coming from...any idea?

$device = IniReadSection(@scriptdir & "\devices.ini", $location)

Share this post


Link to post
Share on other sites

thanks for trying.. i still get the error...

Try this. I think I fixed the errors but I'm just winging it so it's untested.

$location = IniReadSectionNames(@ScriptDir & "\devices.ini")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    
    For $i = 1 To $location[0]

      $device = IniReadSection(@scriptdir & "\devices.ini", "$location[$i]")

      For $p = 1 To $device[0][0]
        MsgBox(4096, "", "Location: " & $location[$i] &  @CRLF & "Key: " & $device[$p][0] & @CRLF & "Value: " & $device[$p][1])
      Next

  Next
EndIf

Share this post


Link to post
Share on other sites

Local $location, $i, $device, $p
$location = IniReadSectionNames(@ScriptDir & "\devices.ini")
If IsArray($location) Then
    For $i = 1 To $location[0]
        $device = IniReadSection(@scriptdir & "\devices.ini", $location[$i])
        If IsArray($device) Then
            For $p = 1 To $device[0][0]
                MsgBox(4096, "", "Location: " & $location[$i] &  @CRLF & "Key: " & $device[$p][0] & @CRLF & "Value: " & $device[$p][1])
            Next
        Else
            MsgBox(16, "Error", "There was an error reading section: " & $location[$i] & @CRLF & "Section Number was: " & $i)
        EndIf
    Next
Else
    MsgBox(16, "", "Error occurred, probably no INI file.")
EndIf
Always best to error check so you can see the error for yourself.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

brilliant!!!

thank you so much!!!

Local $location, $i, $device, $p
$location = IniReadSectionNames(@ScriptDir & "\devices.ini")
If IsArray($location) Then
    For $i = 1 To $location[0]
        $device = IniReadSection(@scriptdir & "\devices.ini", $location[$i])
        If IsArray($device) Then
            For $p = 1 To $device[0][0]
                MsgBox(4096, "", "Location: " & $location[$i] &  @CRLF & "Key: " & $device[$p][0] & @CRLF & "Value: " & $device[$p][1])
            Next
        Else
            MsgBox(16, "Error", "There was an error reading section: " & $location[$i] & @CRLF & "Section Number was: " & $i)
        EndIf
    Next
Else
    MsgBox(16, "", "Error occurred, probably no INI file.")
EndIf
Always best to error check so you can see the error for yourself.

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  
Followers 0