Page 1 of 1 1
Topic Options
#139553 - 2005-05-11 11:42 AM Need Help: Array
viking Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 12
Hello

from my MAIN-Routine the script calls a function to build an array from an input file. In the function are some print commands to the console to show the values of the array and the counter for the array index. This so far works fine. In the MAIN-Routine (after the function call) I do also a print command to the console and can see that the array does not show the expected value; also the array lost 2 entries. Have no idea what this could be. Any help is very appreciated.
Bjoern



Code:
 
;******* Build the Kategories Array **************************************************************
Global $KatArray[100]
BuildArray()

? $KatArray[0]


;******* Functions: General **********************************************************************
; (F01) BuildArray
;
;
;
;*************************************************************************************************

;******* Functions: (F01) Build Array ************************************************************
;
;*************************************************************************************************

Function BuildArray()

Dim $F01Handle
Dim $F01RC
Dim $F01Line
Dim $F01Index

$F01Handle = FreeFileHandle ()

$F01RC = Open($F01Handle, "BLOCKED-KATEGORIEN.TXT",2)

$F01Index = 0

$F01Line = ReadLine($F01Handle)
$KatArray[$F01Index] = $F01Line

? $KatArray[$F01Index]

While $F01Line <> "" And @ERROR = 0

$F01Line = ReadLine($F01Handle)
$KatArray[$F01Index] = $F01Line
? $KatArray[$F01Index]
$F01Index = $F01Index + 1

Loop

? $F01Index

ReDim Preserve $KatArray[$F01Index]

$F01RC = Close($F01Handle)

EndFunction


Top
#139554 - 2005-05-11 02:49 PM Re: Need Help: Array
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try this:
Code:
Break on
Global $KatArray[0]

Function BuildArray()

Dim $F01Handle
Dim $F01RC
Dim $F01Line
Dim $F01Index
Dim $ReadError

$F01Handle = FreeFileHandle ()

$F01RC = Open($F01Handle, "c:\data\scripts\junk.kix",2)
$F01Line = ReadLine($F01Handle)
$ReadError = @ERROR

$F01Index = 0
$KatArray[$F01Index] = $F01Line

While Not $ReadError

? $KatArray[$F01Index]
$F01Line = ReadLine($F01Handle)
$ReadError = @ERROR
if Not $ReadError
$F01Index = $F01Index + 1
ReDim Preserve $KatArray[Ubound($KatArray) +1]
$KatArray[$F01Index] = $F01Line
endif
Loop

? "Index Value = " + $F01Index

$F01RC = Close($F01Handle)

EndFunction

BuildArray()

for each $Item in $KatArray
? $Item
next



Edited by Howard Bullock (2005-05-11 02:52 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#139555 - 2005-05-12 11:51 AM Re: Need Help: Array
viking Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 12
Hello Howard,
thanks a lot for the link. I've seen that there are a lot of great UFs for KIXTART. Well, as a KIXTART beginner I would like to understand the Kixtart language better; and would like to understand why in my script 2 array elements are gone. Thanks. Bjoern

Top
#139556 - 2005-05-12 02:01 PM Re: Need Help: Array
viking Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 12
Hello Howard,
thanks a lot for your help!
I tried before the following code; and now it works fine. I have no clue what the problem was, because the only thing I did was to delete the first read of the file and the first put to the array in the loop; and therefore a change in the loop conditions from a check of an empty input string and the error to only the error check.

Code:

Dim $F01Handle
Dim $F01RC
Dim $F01Line
Dim $F01Index
Global $KatArray[100]

$F01Handle = FreeFileHandle ()

$F01RC = Open($F01Handle, "BLOCKED-KATEGORIEN.TXT",2)

$F01Index = 0

While @ERROR = 0

$F01Line = ReadLine($F01Handle)
$KatArray[$F01Index] = $F01Line
$F01Index = $F01Index + 1

Loop

ReDim Preserve $KatArray[$F01Index]

$F01RC = Close($F01Handle)

EndFunction


Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.057 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org