|
-
May 17th, 2012, 01:33 PM
#1
Thread Starter
New Member
[RESOLVED] file to custom class array, small problem
i have made a custom class "lln" (student) and i got a file which contains data which should be read to an lln-array: dblln (student-array)
it works but if the file contains 3 students, then the array will contain 3 students which are all the same: the last student.
i really dont see why the 1st student gets replaced by the second when the second is read.
example file:
keith
13 years
male
sophie
16years
female
the data will be read correctly but array will look like this:
sophie (dblln(0).name)
16years (dblln(0).age)
female (dblln(0).sex)
sophie (dblln(1).name)
16years (dblln(1).age)
female (dblln(1).sex
here is the code i use to read the data in dblln (the student-array)
plln is an integer which indicates the position (you will see)
Code:
Dim ifile As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(_dblln)
While (Not ifile.EndOfStream)
tlln.hallo(ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine)
ReDim Preserve dblln(plln)
dblln(plln) = tlln
plln += 1
End While
ifile.Close()
i have also tried it reading it into a list(of T) and then converting it to the array but it gave me the same results
-
May 17th, 2012, 02:20 PM
#2
Re: file to custom class array, small problem
I could help if I knew what this was:
"
vb Code:
tlln.hallo(ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine)
"
What is tlln.hallo?
This is what separates the men from the boys in here. I really should know what this is but it just looks like an expression to me, with no real value.
-
May 17th, 2012, 02:31 PM
#3
Thread Starter
New Member
Re: file to custom class array, small problem
sorry forgot to post, here is the full code for the lln class
names look strange because i need to do it in dutch
Code:
Public Class lln
Private _naam As String
Private _klas As String
Private _bedr As String
Private _docs As Boolean
Private _eval As String
Public Sub New()
_naam = ""
_klas = ""
_bedr = ""
_docs = False
_eval = ""
End Sub
Public Sub hallo(ByVal naam, ByVal klas, ByVal bedr, ByVal docs, ByVal eval)
_naam = naam
_klas = klas
_bedr = bedr
_docs = docs
_eval = eval
End Sub
Public Property Naam() As String
Get
Return _naam
End Get
Set(ByVal Value As String)
_naam = Value
End Set
End Property
Public Property Klas() As String
Get
Return _klas
End Get
Set(ByVal Value As String)
_klas = Value
End Set
End Property
Public Property Bedrijf() As String
Get
Return _bedr
End Get
Set(ByVal Value As String)
_bedr = Value
End Set
End Property
Public Property Documenten() As Boolean
Get
Return _docs
End Get
Set(ByVal Value As Boolean)
_docs = Value
End Set
End Property
Public Property Evaluatie() As String
Get
Return _eval
End Get
Set(ByVal Value As String)
_eval = Value
End Set
End Property
End Class
-
May 17th, 2012, 02:39 PM
#4
Re: file to custom class array, small problem
Ok so 5 properties line up with all the Readline methods being returned. Gotchya.
Let me think about this a moment first...
I'll BBL
-
May 17th, 2012, 02:40 PM
#5
Re: file to custom class array, small problem
I think what we see in your Writing methods we could better determine why your code is causing this mess.
-
May 17th, 2012, 02:42 PM
#6
Re: file to custom class array, small problem
Should it not be Public Class tlln instead of what you have Public Class lln?
tlln.hallo()
or have you declared tlln As New lln somewhere in code?
-
May 17th, 2012, 02:45 PM
#7
Thread Starter
New Member
Re: file to custom class array, small problem
ooh another thing i forgot. no, its correct like that, here is tlln
Public tlln As lln = New lln
-
May 17th, 2012, 02:49 PM
#8
Thread Starter
New Member
Re: file to custom class array, small problem
-
May 17th, 2012, 04:33 PM
#9
Re: file to custom class array, small problem
Just create a New instance of that class and it works fine
vb Code:
If System.IO.File.Exists(_dblln) = True Then Dim ifile As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(_dblln) While (Not ifile.EndOfStream) tlln = New lln ''--<< right here create new instance tlln --\\ tlln.hallo(ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine, ifile.ReadLine) ReDim Preserve dblln(plln) dblln(plln) = tlln plln += 1 End While ifile.Close() Else dblln(0) = tlln End If
-
May 17th, 2012, 06:29 PM
#10
Thread Starter
New Member
Re: file to custom class array, small problem
what a stupid thing to miss.
THANKS SO MUCH FOR HELPING ME
-
May 17th, 2012, 06:48 PM
#11
Re: file to custom class array, small problem
 Originally Posted by arijspieter
what a stupid thing to miss.
THANKS SO MUCH FOR HELPING ME

I don't know how these Ratings work, but could you please rate my post to resolve, and then Enter Resolved for this thread -from your control panel.
It makes me feel good when I can help.
It is a reason I do come in and help when I can.
There are not many people these days that express gratitude, but you will find programmers are among the most gratuitous people on the planet.
So says I 
I see you resolved and did what I asked.
Thank you so much too
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|