Jump to content

Problem With Array


Recommended Posts

What it's suppost todo: Read Ini file to find out the length of the array.

Then Declare 0-Length of array, with whatever is in the Settings.ini file

Error:

Global $Descriptions[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
Global $Descriptions[^ERROR

Error: Array variable subscript badly formatted.

Some of the code from my script:

Global $ini = @HomeDrive & "\Settings.ini"
$Arrays = IniRead($ini,"B","User","")
If Not $Arrays = "" Then
    For $i = 0 to $Arrays
        $Read = IniRead($ini,"C","User" & $i,"")
        Global $Descriptions[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
        $Read = IniRead($ini,"D","User" & $i,"")
        Global $Usernames[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
        $Read = IniRead($ini,"E","User" & $i,"")
        Global $Passwords[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
    Next
Else
    Global $Arrays = False
EndIf

Settings file:

[B]
User=0
[C]
User0=7E5999BB74C081B59C55BA5C946AB8399471754F5D62
[D]
User0=7F5A98BD73C680B29D22BA2D9367B938
[E]
User0=7F5D99C674C080B59C50BA5A9413B939

Thanks

Edited by will88
Link to comment
Share on other sites

What it's suppost todo: Read Ini file to find out the length of the array.

Then Declare 0-Length of array, with whatever is in the Settings.ini file

Error:

Global $Descriptions[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
   Global $Descriptions[^ERROR
   
   Error: Array variable subscript badly formatted.

Some of the code from my script:

Global $ini = @HomeDrive & "\Settings.ini"
   $Arrays = IniRead($ini,"B","User","")
   If Not $Arrays = "" Then
       For $i = 0 to $Arrays
           $Read = IniRead($ini,"C","User" & $i,"")
           Global $Descriptions[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
           $Read = IniRead($ini,"D","User" & $i,"")
           Global $Usernames[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
           $Read = IniRead($ini,"E","User" & $i,"")
           Global $Passwords[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
       Next
   Else
       Global $Arrays = False
   EndIf

Settings file:

[B]
   User=0
   [C]
   User0=7E5999BB74C081B59C55BA5C946AB8399471754F5D62
   [D]
   User0=7F5A98BD73C680B29D22BA2D9367B938
   [E]
   User0=7F5D99C674C080B59C50BA5A9413B939

Thanks

You cannot set the element of an array which hasn't been declared, unlike like non-array variables.

I haven't tested this but it might fix your problem-

Global $ini = @HomeDrive & "\Settings.ini"
;we are going to use the value of $Arrays as an integer so cast it as a number (IniRead returns a string)
  Global $Arrays = Number(IniRead($ini,"B","User",""))
  If $Arrays <> 0 Then
;first declare the array with $Arrays elements 
      Global $Descriptions[$Arrays]
      For $i = 0 to $Arrays-1
          $Read = IniRead($ini,"C","User" & $i,"")
          Global $Descriptions[$i] =_StringEncrypt(0,$Read,"Password",$Encrypt_Level)
          $Read = IniRead($ini,"D","User" & $i,"")
          Global $Usernames[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
          $Read = IniRead($ini,"E","User" & $i,"")
          Global $Passwords[$i] = _StringEncrypt(0,$Read,"Password",$Encrypt_Level)
      Next
  Else
       $Arrays = False
  EndIf

Note that if $Arrays is 12 it means you want 12 elements. Arrays have the first element at 0 so your For $i loop must goi from 0 to $Array -1.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...