#34591 - 2002-12-21 10:12 PM
Reading an array
|
Jair
Fresh Scripter
Registered: 2002-08-13
Posts: 8
|
Hello. I'm new to kix, and am having trouble reading from an array. I think I've got it set up correctly, but when I try to display the contents element by element, UBound returns -1, so I cannot display anything. What am I doing wrong?
code:
Break on
$sUserText = "users.txt"
$iUserNum = 0 If Open(2, $sUserText, 2) = 0 Dim $aUserArray[0] While $Error = 0 $sLine = ReadLine(2) $error = @error if $sLine <> "" ReDim preserve $aUserArray[UBound($aUserArray)+1] $aUserArray[UBound($aUserArray)] = $sLine endif Loop Close(2) Endif
MessageBox(UBound($aUserArray), "debug", 0)
for $iCurrentNum = 0 TO UBound($aUserArray) MessageBox($aUserArray[$iCurrentNum], "debug", 0) next
Users.txt is simply a text file with a user name on each line. Any help would be greatly appreciated. Thanks!
_________________________
Lost: [i]/dev/sanity
|
|
Top
|
|
|
|
#34592 - 2002-12-21 10:29 PM
Re: Reading an array
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
If UBOUND returns -1 then it's not an array.
The code looks okay, so beef up the code with more erro coecing like this:
code:
Break on
Dim $aUserArray[0]
$sUserText = "users.txt"
$iUserNum = 0 If Open(2, $sUserText, 2) = 0 Dim $aUserArray[0] While $Error = 0 $sLine = ReadLine(2) ? 'line = '+$sLine $error = @error if $sLine <> "" ? 'Ubound = '+ubound($aUserArray) ReDim preserve $aUserArray[UBound($aUserArray)+1] $aUserArray[UBound($aUserArray)] = $sLine endif Loop Close(2) Endif
MessageBox(UBound($aUserArray), "debug", 0)
for $iCurrentNum = 0 TO UBound($aUserArray) MessageBox($aUserArray[$iCurrentNum], "debug", 0) next
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#34593 - 2002-12-21 10:38 PM
Re: Reading an array
|
Jair
Fresh Scripter
Registered: 2002-08-13
Posts: 8
|
Thanks for the help! Everything looks ok to me when I make those changes. Now the first box reports ubound as being 0, and the second fires with nothing in it.
_________________________
Lost: [i]/dev/sanity
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|