Craz Posted December 26, 2003 Posted December 26, 2003 Hi I'm trying to fill 2 array vars but after filling all values come out empty, and i don't have a clue why. Here's my code in short: Module Functions Const lineSize = 80 Dim fsoScan As New FileSystemObject Dim myStreamTarget As TextStream Dim myDatFile = Application.StartupPath & "\data.dat" Dim myLeftBorder(0) As String Dim myRightBorder(0) As String Dim arrayTeller As Integer Public Sub initialize() myRightBorder.Initialize() myLeftBorder.Initialize() MsgBox("left length = " & myLeftBorder.Length & vbLf & "right length = " & myRightBorder.Length) FillArray(1, "[border_left]") 'filling left borderarray FillArray(2, "[border_right]") 'filling right borderarray MsgBox("left length = " & myLeftBorder.Length & vbLf & "right length = " & myRightBorder.Length) MsgBox("1st left = " & myLeftBorder(0) & vbLf & "1st right = " & myRightBorder(0)) End Sub Private Sub FillArray(ByVal borderArray As Integer, ByVal headerString As String) Dim myStreamSource As TextStream Dim myFile As File Dim lijn As String Dim startWrite As Boolean Dim stopRead As Boolean arrayTeller = 0 myFile = fsoScan.GetFile(myDatFile) myStreamSource = myFile.OpenAsTextStream(IOMode.ForReading) startWrite = False stopRead = False Do While Not myStreamSource.AtEndOfStream And stopRead = False lijn = myStreamSource.ReadLine If (lijn.Equals(headerString)) Then startWrite = True arrayTeller = 0 ElseIf (startWrite = True And lijn.Equals("")) Then stopRead = True ElseIf (startWrite = True) Then If borderArray = 1 Then ReDim myLeftBorder(arrayTeller + 1) myLeftBorder(arrayTeller) = lijn MsgBox("line " & arrayTeller & " added: " & lijn & vbLf & "--> " & myLeftBorder.GetValue(arrayTeller)) Else ReDim myRightBorder(arrayTeller + 1) myRightBorder(arrayTeller) = lijn MsgBox("line " & arrayTeller & " added: " & lijn & vbLf & "--> " & myRightBorder.GetValue(arrayTeller)) End If arrayTeller = arrayTeller + 1 End If Loop myStreamSource.Close() myStreamSource = Nothing myFile = Nothing End Sub Now what happens: When I initialize i fill up 2 arrays from a congig file. The array itself will be filled with strings. The config file is build like: [item1] value1 value2 [item2] values ... first msgbox returns: left length = 1 & right length = 1 then FillArray is called to fill up both arrays in that sub i have a msgbox saying what line it will enter in the array: e.g. line bleh added --> bleh So that seems to be all ok. But after the 2 calls to fill up the arrays it goes wrong. length msgbox gives me: left length = 17 & right length = 17 (= ok) but then when i want to msg the first values it gives me nothing: 1st left = 1st right = Where do i go wrong with this? Quote
*Experts* Bucky Posted December 27, 2003 *Experts* Posted December 27, 2003 The ReDim statement does, in fact, clear the array in addition to resizing it. To maintain the values of the array when resizing, use ReDim Preserve. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Craz Posted December 27, 2003 Author Posted December 27, 2003 ow yes, i forgot that one. Thanks for reminding me! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.