Jump to content

Writing array of strings into a file


qwer85
 Share

Recommended Posts

I have foll script. Why my file is empty, when i use string in array?

Global $users[255][3]
For $i = 0 To UBound($users, 1) - 1
    For $k = 0 To UBound($users, 2) - 1
        $users[$i][$k] = 0
    Next
Next

$users[0][0] = "User1231" ; This expression doesn't work
;$users[0][0] = 1231 ; But this one WORKS FINE!

$users[0][1] = 12312382
Local $file = FileOpen("test.txt", 2)
For $i = 0 To UBound($users) - 1
    If $users[$i][0] = 0 Then ContinueLoop
    FileWriteLine($file, $users[$i][0] & " | " & $users[$i][1])
Next
FileClose($file)
Link to comment
Share on other sites

Ok I found out why it's not writing in file - If $users[$i][0] = 0 Then ContinueLoop is activated and it's exiting the loop. But... wtf? Why after $users[0][0] = "User1231" the If statement shows true on $users[$i][0] = 0 expression?

Edited by qwer85
Link to comment
Share on other sites

But I can't undersand why string = 0 in arrays.

Not just in arrays:

MsgBox(0,"TEST","STRING" = 0)

From the helpfile under "Language Reference - Datatypes"

A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.

...

If a string is used as a number, an implicit call to Number() function is done. So if it doesn't contain a valid number, it will be assumed to equal 0. For example,

10 * "fgh" equals the number 0.

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