Jump to content
Sign in to follow this  
JetlagJad

Why is this returning an error?

Recommended Posts

JetlagJad

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

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
BrettF

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

Share this post


Link to post
Share on other sites
JetlagJad

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 ;)

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  

×