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:
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?
Here's my code in short:
Code:
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?