well i have one last question on my program like before. the idea of it is to type in a child's last name and it will read from a txt file with all its info and bring out the info in a rich txt box. otherwise it will say "child not found". well right now no matter what i put in im getting "child not found"
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strChildFirstName As String
Dim strChildLastName As String
Dim chrChildGender As Char
Dim strParentLastName As String
Dim strParentFirstName As String
Dim chrParentRelationship As Char
Dim decAnnualIncome As Decimal
Dim intParentAge As Integer
Dim intNumberOfKids As Integer
Dim Readfile As System.IO.StreamReader
Dim intCounter As Integer
Dim blnErrorFound As Boolean
Dim blnFound As Boolean
'blnErrorFound = foundError()
'If blnIsError = True Then
' Exit Sub
'End If
Readfile = New System.IO.StreamReader("parentData.txt")
strChildLastName = txtLastName.Text
Do While Readfile.Peek() > -1
For intCounter = 0 To 1
Readfile.ReadLine()
Next
strChildLastName = Readfile.ReadLine
If blnFound = True Then
strChildFirstName = Readfile.ReadLine
chrChildGender = Readfile.ReadLine
strParentFirstName = Readfile.ReadLine
strParentLastName = Readfile.ReadLine
chrParentRelationship = Readfile.ReadLine
intParentAge = Readfile.ReadLine
decAnnualIncome = Readfile.ReadLine
intNumberOfKids = Readfile.ReadLine
ElseIf blnFound = False Then
MsgBox("Child's Name Cannot Be Found.", _
MsgBoxStyle.OkOnly, "Error Messages")
txtLastName.Text = ""
For intCounter = 1 To 9
Readfile.ReadLine()
Next
txtInformation.Text = strChildFirstName & vbNewLine & _
chrChildGender & vbNewLine & strParentFirstName & vbNewLine & _
strParentLastName & vbNewLine & chrParentRelationship & _
vbNewLine & intParentAge & vbNewLine & decAnnualIncome & _
vbNewLine & intNumberOfKids
End If
Loop
End Sub
the set up of the txt file is as follows
child's last name (for example im using the first name in the file "Jones"
child's first name
gender (b or g)
parent's last name
parent's first name
parents relation to child (f or m)
number of children in family
family income
im gonna work on the idea of setting the blnFound = strChildFirstName
not sure if thats what i need but ill try
quick update....the above didnt work gave me error of: "Conversion from string "B" to type 'Boolean' is not valid."
thanks

one last question with a boolean
arkiboys
Well, my code 'comes out even'.
Just because the prof made the file, doesn't mean
it's right.
Open it in Notepad and double check it.
game-maniac
If Readfile.ReadLine = txtLastName.Text Then
blnFound = True
and that worked until i got to
intParentAge = Readfile.ReadLine
and then i got "Conversion from string "" to type 'Integer' is not valid."
so i have a feeling that the counting is off which i dont c how that possible since im just reading lines in a row but whatever....im just that much closer
update: k i always hated counting lines and when i do a watch it says that the very first readline is equal to "B"
so.....
For intCounter = 0 To 1
Readfile.ReadLine()
Next
strChildLastName = Readfile.ReadLine <------the strchildLastName is equal to "B"
how is this possible. the txt file is set up like i said 1)last name 2)first name 3)gender
well if i said 0 To 1 isnt that reading the very first line like the kids last name in this case "Jones"
wtf
Dual Cortex
off topic but would
Readfile.ReadLine.Equals(strChildLastName) then
be the same as
Readfile.ReadLine = strChildLastName then
Xadja
thanks for the help guys
Rajesh Nagpal - MSFT
13117
This may have been a good way to accomplish this in 1976. But a flat file is not a good design for an application like this.
Bhavna_sharma
Some suggested code:
Option Strict Off
Public Class Form1
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Dim strChildFirstName As String
Dim strChildLastName As String
Dim chrChildGender As Char
Dim strParentLastName As String
Dim strParentFirstName As String
Dim chrParentRelationship As Char
Dim decAnnualIncome As Decimal
Dim intParentAge As Integer
Dim intNumberOfKids As Integer
Dim Readfile As System.IO.StreamReader
Dim intCounter As Integer
' Dim blnErrorFound As Boolean
Dim blnFound As Boolean = False
'blnErrorFound = foundError()
'If blnIsError = True Then
' Exit Sub
'End If
TxtInformation.Text = ""
Readfile = New System.IO.StreamReader("c:\parentData.txt")
' strChildLastName = txtLastName.Text
Do While Readfile.Peek() > -1
strChildLastName = Readfile.ReadLine
blnFound = Trim(strChildLastName.ToUpper) = _
Trim(TxtLastName.Text.ToUpper)
If blnFound = True Then
strChildFirstName = Readfile.ReadLine
chrChildGender = Readfile.ReadLine
strParentFirstName = Readfile.ReadLine
strParentLastName = Readfile.ReadLine
chrParentRelationship = Readfile.ReadLine
intParentAge = Readfile.ReadLine
decAnnualIncome = Readfile.ReadLine
intNumberOfKids = Readfile.ReadLine
TxtInformation.Text = strChildLastName & vbNewLine & _
strChildFirstName & vbNewLine & _
chrChildGender & vbNewLine & strParentFirstName & vbNewLine & _
strParentLastName & vbNewLine & chrParentRelationship & _
vbNewLine & intParentAge & vbNewLine & decAnnualIncome & _
vbNewLine & intNumberOfKids
Exit Sub
Else
For intCounter = 1 To 8
Readfile.ReadLine()
Next
End If
Loop
MsgBox("Child's Name Cannot Be Found.", _
MsgBoxStyle.OkOnly, "Error Messages")
TxtLastName.Text = ""
End Sub
End Class
Sarosh79
If things are not 'coming out even', make sure
that the source file parentData.txt is correctly
created.
That each individual has 9 lines in the
right sequence, with the right data, and
there are no extra blank lines.
Prabagarane
its because you have not set the boolean value to true wherever you find that childs name. It's always going to be false. It's not magically going to be true :-)
something like...
strChildLastName = txtLastName.Text
Do While Readfile.Peek() > -1
For intCounter = 0 To 1
Readfile.ReadLine()
Next
if Readfile.ReadLine.Equals(strChildLastName) then
If blnFound = True
end if
now blnFound will be true because the child name in the textfile/current line we read does match the text from the textbox.
CHEN YU-TIEN
Trim(strChildLastName.ToUpper) = _
Trim(TxtLastName.Text.ToUpper)
Trim is used to cut off preceding and leading spaces of strChildLastName value and TxtLastName value
This statement is useful to make sure that you get the exact comparison on your statement's condition
cikitani
Trim(strChildLastName.ToUpper) = _
Trim(TxtLastName.Text.ToUpper)
also im still getting a counting error when it hits intParentAge as its saying it is = to "M"
if ne one can help out with the line counting that would be awsome because thats the only problem with it
EnterBS
blnfound is a boolean value that we need to set to true
or false by looking at a condition.
The basic condition starts out:
strChildLastName, has just been read from the file.
TxtLastName.Text, has been input by the user.
Say the file reads "JOHNSON" and the user types
"Johnson". These are not equal.
Taking both values and changing them both to uppercase
(for evaluation purposes,) allows them to come out equal.
'TRIM' gets rid of any leading spaces that may cause
differences. Trimmed "Johnson" and " Johnson" will
now be equal.
furjaw
not quite. .Equals() would be the way to go as it checks objects to see if they are the same, = is more referencing.
Of course, setting a boolean value to a string would return in a conversion error - you can't convert a string value to a boolean value :-) And this is not what you want anyway. To be honest, you are better using a database to store and read this stuff, far better!
Readfile = New System.IO.StreamReader("parentData.txt")
strChildLastName = txtLastName.Text
Do While Readfile.Peek() > -1
For intCounter = 0 To 1
Readfile.ReadLine()
Next
Dim currentLine as String = Readfile.ReadLine
if currentLine.Equals(strChildLastName) then
blnFound = True
strChildFirstName = Readfile.ReadLine
chrChildGender = Readfile.ReadLine
strParentFirstName = Readfile.ReadLine
strParentLastName = Readfile.ReadLine
chrParentRelationship = Readfile.ReadLine
intParentAge = Readfile.ReadLine
decAnnualIncome = Readfile.ReadLine
intNumberOfKids = Readfile.ReadLine
Else 'well the childname wasnt found so no need to check the boolean value. It's either it has or it hasnt - if...else...end if
MsgBox("Child's Name Cannot Be Found.", _
MsgBoxStyle.OkOnly, "Error Messages")
txtLastName.Text = ""
For intCounter = 1 To 9
Readfile.ReadLine()
Next
txtInformation.Text = strChildFirstName & vbNewLine & _
chrChildGender & vbNewLine & strParentFirstName & vbNewLine & _
strParentLastName & vbNewLine & chrParentRelationship & _
vbNewLine & intParentAge & vbNewLine & decAnnualIncome & _
vbNewLine & intNumberOfKids
End If
Loop