Jump to content

Why is this returning an error?


Recommended Posts

Func SplitVariables()
        Local $Accounts[999]
        $SplitAccounts = StringSplit('a=b/c=d', '/')
        
        For $i = 1 To $SplitAccounts[0]
            $Accounts[$i] = StringSplit($SplitAccounts[$i], '=')
        Next

        MsgBox(0, 'Accounts:', $Accounts[1][1])
    EndFunc

Please help, I'm not sure why but $Accounts[1][1] should be returning 'a' but it isn't :D

Thanks in advance! :D

Link to comment
Share on other sites

  • Developers

You cannot have a receiving one dimensional Array and then expect it to become 2 dimensional after doing a stringsplit.

try

Local $Accounts[999]
$SplitAccounts = StringSplit('a=b/c=d', '/')

For $i = 1 To $SplitAccounts[0]
    $tAccounts = StringSplit($SplitAccounts[$i], '=')
    MsgBox(0, 'Accounts:', $Accounts[1] & "<=>" & $Accounts[2] )
Next

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Please look at your code again, starting with declaring a single dimension array and calling it as a 2D array... Doesn't work like that. What I think you meant to do:

SplitVariables()

Func SplitVariables()
    Local $Accounts[999][99]
    $SplitAccounts = StringSplit('a=b/c=d', '/')

    For $i = 1 To $SplitAccounts[0]
        $split = StringSplit($SplitAccounts[$i], '=')
        For $x = 1 to $split[0]
            $Accounts[$i][$x] = $split[$x]
        Next
    Next
    MsgBox(0, 'Accounts:', $Accounts[1][1])
EndFunc  ;==>SplitVariables

Cheers,

Brett

Link to comment
Share on other sites

You cannot have a receiving one dimensional Array and then expect it to become 2 dimensional after doing a stringsplit.

try

Local $Accounts[999]
$SplitAccounts = StringSplit('a=b/c=d', '/')

For $i = 1 To $SplitAccounts[0]
    $tAccounts = StringSplit($SplitAccounts[$i], '=')
    MsgBox(0, 'Accounts:', $Accounts[1] & "<=>" & $Accounts[2] )
Next

Jos

Thanks, but this isn't quite what I was looking for, in this script, $Accounts[1] and $Accounts[2] are replaced every time it loops.

Please look at your code again, starting with declaring a single dimension array and calling it as a 2D array... Doesn't work like that. What I think you meant to do:

SplitVariables()

Func SplitVariables()
    Local $Accounts[999][99]
    $SplitAccounts = StringSplit('a=b/c=d', '/')

    For $i = 1 To $SplitAccounts[0]
        $split = StringSplit($SplitAccounts[$i], '=')
        For $x = 1 to $split[0]
            $Accounts[$i][$x] = $split[$x]
        Next
    Next
    MsgBox(0, 'Accounts:', $Accounts[1][1])
EndFunc ;==>SplitVariables

Cheers,

Brett

Thanks, this worked perfect :D

Irrelevant, but I live near Brisbane too :D

Go Australia ;)

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...