Calling a function problem

straight_edge

Member
Joined
Feb 21, 2007
Messages
13
Programming Experience
Beginner
Hi

I'm having a problem with a function, I have a function that reads from a text file and then uses that data to create a 2D array but when I call that function from the same class it doesn't recognise the array.

This is my function:

VB.NET:
Function FillAppointmentsArray()
 
Dim appointmentsFields() As String
Dim appointmentsArray(10, 3) As String
Dim n As Integer
Dim inLine As String
Dim noOfLines As Integer
Dim countRows As Integer = 0
Dim inputStream As StreamReader
 
inputStream = File.OpenText("N:\Yr3\Programming\Assignment 2\appointmentFile.txt") 'open the input stream
inLine = inputStream.ReadLine() 'read line in text file
While inLine <> Nothing 'if the line in the text file is not equal to nothing
noOfLines = noOfLines + 1 'increment number of lines
inLine = inputStream.ReadLine() 'move on to next line
End While
inputStream.Close()
 
Dim i As Integer = 0
inputStream = File.OpenText("N:\Yr3\Programming\Assignment 2\appointmentFile.txt")
For i = 0 To noOfLines - 1
inLine = inputStream.ReadLine()
appointmentsFields = inLine.Split(",")
For n = 0 To appointmentsFields.Length - 1
appointmentsArray(i, n) = (appointmentsFields(n))
Next
Array.Clear(appointmentsFields, 0, appointmentsFields.Length)
Next
inputStream.Close()
 
Return appointmentsArray
End Function

I then call the function in the same class using:

FillAppointmentsArray()

But it doesn't work, if anyone can see what I'm doing wrong that would be great.

Thanks
 
Sorry, what I meant was it underlines the array name when I try to use it and says its not declared even though it is declared and created in the function
 
Please take a screenshot of this problem, saved as PNG (NOT JPEG) and attach it to your post
 
Screenshot is attached
 

Attachments

  • screenshot.PNG
    screenshot.PNG
    79.9 KB · Views: 26
VB.NET:
Dim appointmentsArray() As String = FillAppointmentsArray()
 
Back
Top