Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Reading dat file into textboxes


Reading dat file into textboxes

Author
Message
ladytexasbear
ladytexasbear
Forum God
Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)

Group: Forum Members
Posts: 3, Visits: 8
I have been really stumped by this one.  Can anyone help me to read in a dat file and put the data (each one field) into textboxes.  I will be comparing this file to a "master file" I will already have read into an array.

Thank you for any help!

Joey
Joey
Forum God
Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)Forum God (16K reputation)

Group: Forum Members
Posts: 72, Visits: 46
Have you successfully read the data into an array? If so, all you'd need to do is loop through the array to load the textboxes.



Let's see what code you already have.
ladytexasbear
ladytexasbear
Forum God
Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)

Group: Forum Members
Posts: 3, Visits: 8
Thank you....I got that going...now I'm just running into a problem when I try to compare the arrays.  I don't get to the point of having the textboxes load because of an exception handling error.  I don't understand what instance I'm missing.  Here's the program:

Public Class MainForm

Private Answers() As Char

Private Tested() As Char

Private Index As Int16

Private UIControl As Control

Private ThisTextBox As Control

Private IncorrectAnswers As Int16 = 0

Private TextBox(19) As TextBox

 

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim DataIn As StreamReader

Dim IntegerCnt As Int16 = 1

Dim Record As String

Dim Field() As String

TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, _

TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, TextBox12, _

TextBox13, TextBox14, TextBox15, TextBox16, TextBox17, TextBox18, _

TextBox19, TextBox20}

DataIn = New StreamReader(Application.StartupPath & "\Data\RMV Answers.dat")

' Read in Answers file

Do While DataIn.Peek() <> -1

Record = DataIn.ReadLine()

Field = Record.Split()

Answers(Index) = Field(0)

Index += 1 'Increment the subscript value

Loop

DataIn.Close()

Index = 0 'Reinitialize Index

'Read in tested file

DataIn = New StreamReader(Application.StartupPath & "\Data\RMV001.dat")

Do While DataIn.Peek() <> -1

Record = DataIn.ReadLine()

Field = Record.Split()

Tested(Index) = Record(0)

Index += 1 'Increment the subscript value

Loop

DataIn.Close()

End Sub

Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

Dim UIControl As Control

For Each UIControl In Me.Controls

If TypeOf UIControl Is TextBox Then

ThisTextBox = CType(UIControl, TextBox)

ThisTextBox.Text = ""

TextBox1.Focus()

ResultsLabel.Text = ""

End If

Next

End Sub

Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

Dim Response As DialogResult

Response = MessageBox.Show("Do you really want to quit?", _

"Confirmation required..", _

MessageBoxButtons.YesNo, _

MessageBoxIcon.Stop)

If Response = Windows.Forms.DialogResult.Yes Then

' When condition is TRUE, close the form.

Me.Close()

Else

'When condition is FALSE, stay in the application.

End If

End Sub

Private Sub ScoreButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScoreButton.Click

Const MAX As Int16 = 19

Dim Index As Int16

For Index = 0 To MAX

If Answers(Index) = Tested(Index) Then

TextBox(Index).Text = Tested(Index).ToString()

TextBox(Index).BackColor = Color.LawnGreen

IncorrectAnswers += 1

Else

TextBox(Index).Text = Tested(Index).ToString()

TextBox(Index).BackColor = Color.Tomato

End If

Index += 1

Next

End Sub

Private Sub ResultsLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResultsLabel.Click

If IncorrectAnswers > 5 Then

ResultsLabel.Text = "Sorry. You did not pass the test. Try again in the future!"

Else

ResultsLabel.Text = "Congratulations! You passed!"

End If

End Sub

End Class


ladytexasbear
ladytexasbear
Forum God
Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)Forum God (957 reputation)

Group: Forum Members
Posts: 3, Visits: 8
Thank you...there were multiple issues...but taken care of and working great now!
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search