473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IO.File.AppendText error

I am trying to write an application, taking input from various text
boxes and appending it to a text file.... it was working, then I had to
create various sub procedures to reflect limits set in place (class: A
through C), (type: X, I, S), grade (4 through 6)

Ive tried everything and it still wont work, anyone have any ideas?

heres my code

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblLastName1 As System.Windows.Forms.Label
Friend WithEvents lblLastName2 As System.Windows.Forms.Label
Friend WithEvents lblFirstNameStudent1 As
System.Windows.Forms.Label
Friend WithEvents LblFirstNameStudent2 As
System.Windows.Forms.Label
Friend WithEvents txtLastNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtLastNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtProjectName As System.Windows.Forms.TextBox
Friend WithEvents lblProjectName As System.Windows.Forms.Label
Friend WithEvents lblGrade As System.Windows.Forms.Label
Friend WithEvents lblClass As System.Windows.Forms.Label
Friend WithEvents txtGrade As System.Windows.Forms.TextBox
Friend WithEvents txtClass As System.Windows.Forms.TextBox
Friend WithEvents lblType As System.Windows.Forms.Label
Friend WithEvents txtType As System.Windows.Forms.TextBox
Friend WithEvents btnAddtoRecord As System.Windows.Forms.Button
Friend WithEvents dlgSaveFile As
System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.lblLastName1 = New System.Windows.Forms.Label
Me.lblLastName2 = New System.Windows.Forms.Label
Me.lblFirstNameStudent1 = New System.Windows.Forms.Label
Me.LblFirstNameStudent2 = New System.Windows.Forms.Label
Me.txtLastNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent2 = New System.Windows.Forms.TextBox
Me.txtLastNameStudent2 = New System.Windows.Forms.TextBox
Me.txtProjectName = New System.Windows.Forms.TextBox
Me.lblProjectName = New System.Windows.Forms.Label
Me.lblGrade = New System.Windows.Forms.Label
Me.txtGrade = New System.Windows.Forms.TextBox
Me.lblClass = New System.Windows.Forms.Label
Me.txtClass = New System.Windows.Forms.TextBox
Me.lblType = New System.Windows.Forms.Label
Me.txtType = New System.Windows.Forms.TextBox
Me.btnAddtoRecord = New System.Windows.Forms.Button
Me.dlgSaveFile = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'lblLastName1
'
Me.lblLastName1.Location = New System.Drawing.Point(8, 48)
Me.lblLastName1.Name = "lblLastName1"
Me.lblLastName1.Size = New System.Drawing.Size(128, 23)
Me.lblLastName1.TabIndex = 0
Me.lblLastName1.Text = "Last Name of Student 1:"
Me.lblLastName1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblLastName2
'
Me.lblLastName2.Location = New System.Drawing.Point(8, 112)
Me.lblLastName2.Name = "lblLastName2"
Me.lblLastName2.Size = New System.Drawing.Size(128, 23)
Me.lblLastName2.TabIndex = 1
Me.lblLastName2.Text = "Last Name of Student 2:"
Me.lblLastName2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblFirstNameStudent1
'
Me.lblFirstNameStudent1.Location = New System.Drawing.Point(8,
16)
Me.lblFirstNameStudent1.Name = "lblFirstNameStudent1"
Me.lblFirstNameStudent1.Size = New System.Drawing.Size(128, 23)
Me.lblFirstNameStudent1.TabIndex = 2
Me.lblFirstNameStudent1.Text = "First Name of Student 1:"
Me.lblFirstNameStudent1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'LblFirstNameStudent2
'
Me.LblFirstNameStudent2.Location = New System.Drawing.Point(8,
80)
Me.LblFirstNameStudent2.Name = "LblFirstNameStudent2"
Me.LblFirstNameStudent2.Size = New System.Drawing.Size(128, 23)
Me.LblFirstNameStudent2.TabIndex = 3
Me.LblFirstNameStudent2.Text = "First Name of Student 2:"
Me.LblFirstNameStudent2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtLastNameStudent1
'
Me.txtLastNameStudent1.Location = New System.Drawing.Point(144,
48)
Me.txtLastNameStudent1.Name = "txtLastNameStudent1"
Me.txtLastNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent1.TabIndex = 4
Me.txtLastNameStudent1.Text = ""
'
'txtFirstNameStudent1
'
Me.txtFirstNameStudent1.Location = New
System.Drawing.Point(144, 16)
Me.txtFirstNameStudent1.Name = "txtFirstNameStudent1"
Me.txtFirstNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent1.TabIndex = 5
Me.txtFirstNameStudent1.Text = ""
'
'txtFirstNameStudent2
'
Me.txtFirstNameStudent2.Location = New
System.Drawing.Point(144, 80)
Me.txtFirstNameStudent2.Name = "txtFirstNameStudent2"
Me.txtFirstNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent2.TabIndex = 6
Me.txtFirstNameStudent2.Text = ""
'
'txtLastNameStudent2
'
Me.txtLastNameStudent2.Location = New System.Drawing.Point(144,
112)
Me.txtLastNameStudent2.Name = "txtLastNameStudent2"
Me.txtLastNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent2.TabIndex = 7
Me.txtLastNameStudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectName.Location = New System.Drawing.Point(144, 144)
Me.txtProjectName.Name = "txtProjectName"
Me.txtProjectName.Size = New System.Drawing.Size(160, 20)
Me.txtProjectName.TabIndex = 8
Me.txtProjectName.Text = ""
'
'lblProjectName
'
Me.lblProjectName.Location = New System.Drawing.Point(8, 144)
Me.lblProjectName.Name = "lblProjectName"
Me.lblProjectName.Size = New System.Drawing.Size(128, 23)
Me.lblProjectName.TabIndex = 9
Me.lblProjectName.Text = "Project Name:"
Me.lblProjectName.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblGrade
'
Me.lblGrade.Location = New System.Drawing.Point(8, 176)
Me.lblGrade.Name = "lblGrade"
Me.lblGrade.Size = New System.Drawing.Size(128, 23)
Me.lblGrade.TabIndex = 10
Me.lblGrade.Text = "Grade:"
Me.lblGrade.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtGrade
'
Me.txtGrade.Location = New System.Drawing.Point(144, 176)
Me.txtGrade.Name = "txtGrade"
Me.txtGrade.Size = New System.Drawing.Size(160, 20)
Me.txtGrade.TabIndex = 11
Me.txtGrade.Text = ""
'
'lblClass
'
Me.lblClass.Location = New System.Drawing.Point(8, 208)
Me.lblClass.Name = "lblClass"
Me.lblClass.Size = New System.Drawing.Size(128, 23)
Me.lblClass.TabIndex = 12
Me.lblClass.Text = "Class:"
Me.lblClass.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtClass
'
Me.txtClass.Location = New System.Drawing.Point(144, 208)
Me.txtClass.Name = "txtClass"
Me.txtClass.Size = New System.Drawing.Size(160, 20)
Me.txtClass.TabIndex = 13
Me.txtClass.Text = ""
'
'lblType
'
Me.lblType.Location = New System.Drawing.Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing.Size(128, 23)
Me.lblType.TabIndex = 14
Me.lblType.Text = "Type:"
Me.lblType.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'txtType
'
Me.txtType.Location = New System.Drawing.Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing.Size(160, 20)
Me.txtType.TabIndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoRecord.Location = New System.Drawing.Point(160, 272)
Me.btnAddtoRecord.Name = "btnAddtoRecord"
Me.btnAddtoRecord.Size = New System.Drawing.Size(120, 24)
Me.btnAddtoRecord.TabIndex = 16
Me.btnAddtoRecord.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile.Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(384, 318)
Me.Controls.Add(Me.btnAddtoRecord)
Me.Controls.Add(Me.txtType)
Me.Controls.Add(Me.lblType)
Me.Controls.Add(Me.txtClass)
Me.Controls.Add(Me.lblClass)
Me.Controls.Add(Me.txtGrade)
Me.Controls.Add(Me.lblGrade)
Me.Controls.Add(Me.lblProjectName)
Me.Controls.Add(Me.txtProjectName)
Me.Controls.Add(Me.txtLastNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent1)
Me.Controls.Add(Me.txtLastNameStudent1)
Me.Controls.Add(Me.LblFirstNameStudent2)
Me.Controls.Add(Me.lblFirstNameStudent1)
Me.Controls.Add(Me.lblLastName2)
Me.Controls.Add(Me.lblLastName1)
Me.Name = "Form1"
Me.Text = "Science Fair Entries"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnAddtoRecord_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAddtoRecord.Click
Dim x As Boolean
CheckClass(x)
If x Then
CheckGrade(x)
End If
If x Then
CheckType(x)
End If
Dim record As IO.StreamWriter =
IO.File.AppendText(dlgSaveFile.FileName)
record.WriteLine("")
record.WriteLine("Names:" & " " & txtFirstNameStudent1.Text & "
" & txtLastNameStudent1.Text & "," & " " & txtFirstNameStudent2.Text &
" " & txtLastNameStudent2.Text)
record.WriteLine("Type:" & " " & txtType.Text)
record.WriteLine("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLine("Project Title:" & " " & txtProjectName.Text)
record.WriteLine(" ")

record.WriteLine("================================ ======================")
record.Close()
txtFirstNameStudent1.Clear()
txtLastNameStudent1.Clear()
txtFirstNameStudent2.Clear()
txtLastNameStudent2.Clear()
txtClass.Clear()
txtGrade.Clear()
txtType.Clear()
txtProjectName.Clear()
End Sub
Function CheckClass(ByRef classanalyze As Boolean) As Boolean
Select Case txtClass.Text
Case "A"
classanalyze = True
Case "B"
classanalyze = True
Case "C"
classanalyze = True
Case Else
MsgBox("You have inputted an invalid Class. Please
select a Class between A and C")
classanalyze = False
End Select
Return classanalyze
End Function
Function CheckGrade(ByRef analyzegrade As Boolean) As Boolean
Select Case txtGrade.Text
Case "4"
txtGrade.Text = "4"
analyzegrade = True

Case "5"
txtGrade.Text = "5"
analyzegrade = True
Case "6"
txtGrade.Text = "6"
analyzegrade = True
Case Else
analyzegrade = False
MsgBox("You have inputted an invalid Grade. Please
select a Grade between 4 or 6")
Return analyzegrade
End Select
End Function
Function CheckType(ByRef typeanalyze As Boolean) As Boolean
Dim type As String
Select Case txtType.Text
Case "I"
txtType.Text = "Invention"
typeanalyze = True
Case "S"
txtType.Text = "Study"
typeanalyze = True
Case "X"
txtType.Text = "Experiment"
typeanalyze = True
Case Else
typeanalyze = False
MsgBox("You have inputted an invalid Project Type.
Please enter I for an invention, X for an experiment, or S for a
study")
Return typeanalyze
End Select
End Function

End Class

Apr 13 '06 #1
2 1863
Hi dc,

I have not tried your code, at first glance I can see at least a couple
of Returns (Return typeanalyze, Return analyzegrade) which are within a
CASE ELSE clause. Take them out of there ....

dc15 ha scritto:
I am trying to write an application, taking input from various text
boxes and appending it to a text file.... it was working, then I had to
create various sub procedures to reflect limits set in place (class: A
through C), (type: X, I, S), grade (4 through 6)

Ive tried everything and it still wont work, anyone have any ideas?

heres my code

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblLastName1 As System.Windows.Forms.Label
Friend WithEvents lblLastName2 As System.Windows.Forms.Label
Friend WithEvents lblFirstNameStudent1 As
System.Windows.Forms.Label
Friend WithEvents LblFirstNameStudent2 As
System.Windows.Forms.Label
Friend WithEvents txtLastNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtLastNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtProjectName As System.Windows.Forms.TextBox
Friend WithEvents lblProjectName As System.Windows.Forms.Label
Friend WithEvents lblGrade As System.Windows.Forms.Label
Friend WithEvents lblClass As System.Windows.Forms.Label
Friend WithEvents txtGrade As System.Windows.Forms.TextBox
Friend WithEvents txtClass As System.Windows.Forms.TextBox
Friend WithEvents lblType As System.Windows.Forms.Label
Friend WithEvents txtType As System.Windows.Forms.TextBox
Friend WithEvents btnAddtoRecord As System.Windows.Forms.Button
Friend WithEvents dlgSaveFile As
System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.lblLastName1 = New System.Windows.Forms.Label
Me.lblLastName2 = New System.Windows.Forms.Label
Me.lblFirstNameStudent1 = New System.Windows.Forms.Label
Me.LblFirstNameStudent2 = New System.Windows.Forms.Label
Me.txtLastNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent2 = New System.Windows.Forms.TextBox
Me.txtLastNameStudent2 = New System.Windows.Forms.TextBox
Me.txtProjectName = New System.Windows.Forms.TextBox
Me.lblProjectName = New System.Windows.Forms.Label
Me.lblGrade = New System.Windows.Forms.Label
Me.txtGrade = New System.Windows.Forms.TextBox
Me.lblClass = New System.Windows.Forms.Label
Me.txtClass = New System.Windows.Forms.TextBox
Me.lblType = New System.Windows.Forms.Label
Me.txtType = New System.Windows.Forms.TextBox
Me.btnAddtoRecord = New System.Windows.Forms.Button
Me.dlgSaveFile = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'lblLastName1
'
Me.lblLastName1.Location = New System.Drawing.Point(8, 48)
Me.lblLastName1.Name = "lblLastName1"
Me.lblLastName1.Size = New System.Drawing.Size(128, 23)
Me.lblLastName1.TabIndex = 0
Me.lblLastName1.Text = "Last Name of Student 1:"
Me.lblLastName1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblLastName2
'
Me.lblLastName2.Location = New System.Drawing.Point(8, 112)
Me.lblLastName2.Name = "lblLastName2"
Me.lblLastName2.Size = New System.Drawing.Size(128, 23)
Me.lblLastName2.TabIndex = 1
Me.lblLastName2.Text = "Last Name of Student 2:"
Me.lblLastName2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblFirstNameStudent1
'
Me.lblFirstNameStudent1.Location = New System.Drawing.Point(8,
16)
Me.lblFirstNameStudent1.Name = "lblFirstNameStudent1"
Me.lblFirstNameStudent1.Size = New System.Drawing.Size(128, 23)
Me.lblFirstNameStudent1.TabIndex = 2
Me.lblFirstNameStudent1.Text = "First Name of Student 1:"
Me.lblFirstNameStudent1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'LblFirstNameStudent2
'
Me.LblFirstNameStudent2.Location = New System.Drawing.Point(8,
80)
Me.LblFirstNameStudent2.Name = "LblFirstNameStudent2"
Me.LblFirstNameStudent2.Size = New System.Drawing.Size(128, 23)
Me.LblFirstNameStudent2.TabIndex = 3
Me.LblFirstNameStudent2.Text = "First Name of Student 2:"
Me.LblFirstNameStudent2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtLastNameStudent1
'
Me.txtLastNameStudent1.Location = New System.Drawing.Point(144,
48)
Me.txtLastNameStudent1.Name = "txtLastNameStudent1"
Me.txtLastNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent1.TabIndex = 4
Me.txtLastNameStudent1.Text = ""
'
'txtFirstNameStudent1
'
Me.txtFirstNameStudent1.Location = New
System.Drawing.Point(144, 16)
Me.txtFirstNameStudent1.Name = "txtFirstNameStudent1"
Me.txtFirstNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent1.TabIndex = 5
Me.txtFirstNameStudent1.Text = ""
'
'txtFirstNameStudent2
'
Me.txtFirstNameStudent2.Location = New
System.Drawing.Point(144, 80)
Me.txtFirstNameStudent2.Name = "txtFirstNameStudent2"
Me.txtFirstNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent2.TabIndex = 6
Me.txtFirstNameStudent2.Text = ""
'
'txtLastNameStudent2
'
Me.txtLastNameStudent2.Location = New System.Drawing.Point(144,
112)
Me.txtLastNameStudent2.Name = "txtLastNameStudent2"
Me.txtLastNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent2.TabIndex = 7
Me.txtLastNameStudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectName.Location = New System.Drawing.Point(144, 144)
Me.txtProjectName.Name = "txtProjectName"
Me.txtProjectName.Size = New System.Drawing.Size(160, 20)
Me.txtProjectName.TabIndex = 8
Me.txtProjectName.Text = ""
'
'lblProjectName
'
Me.lblProjectName.Location = New System.Drawing.Point(8, 144)
Me.lblProjectName.Name = "lblProjectName"
Me.lblProjectName.Size = New System.Drawing.Size(128, 23)
Me.lblProjectName.TabIndex = 9
Me.lblProjectName.Text = "Project Name:"
Me.lblProjectName.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblGrade
'
Me.lblGrade.Location = New System.Drawing.Point(8, 176)
Me.lblGrade.Name = "lblGrade"
Me.lblGrade.Size = New System.Drawing.Size(128, 23)
Me.lblGrade.TabIndex = 10
Me.lblGrade.Text = "Grade:"
Me.lblGrade.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtGrade
'
Me.txtGrade.Location = New System.Drawing.Point(144, 176)
Me.txtGrade.Name = "txtGrade"
Me.txtGrade.Size = New System.Drawing.Size(160, 20)
Me.txtGrade.TabIndex = 11
Me.txtGrade.Text = ""
'
'lblClass
'
Me.lblClass.Location = New System.Drawing.Point(8, 208)
Me.lblClass.Name = "lblClass"
Me.lblClass.Size = New System.Drawing.Size(128, 23)
Me.lblClass.TabIndex = 12
Me.lblClass.Text = "Class:"
Me.lblClass.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtClass
'
Me.txtClass.Location = New System.Drawing.Point(144, 208)
Me.txtClass.Name = "txtClass"
Me.txtClass.Size = New System.Drawing.Size(160, 20)
Me.txtClass.TabIndex = 13
Me.txtClass.Text = ""
'
'lblType
'
Me.lblType.Location = New System.Drawing.Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing.Size(128, 23)
Me.lblType.TabIndex = 14
Me.lblType.Text = "Type:"
Me.lblType.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'txtType
'
Me.txtType.Location = New System.Drawing.Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing.Size(160, 20)
Me.txtType.TabIndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoRecord.Location = New System.Drawing.Point(160, 272)
Me.btnAddtoRecord.Name = "btnAddtoRecord"
Me.btnAddtoRecord.Size = New System.Drawing.Size(120, 24)
Me.btnAddtoRecord.TabIndex = 16
Me.btnAddtoRecord.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile.Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(384, 318)
Me.Controls.Add(Me.btnAddtoRecord)
Me.Controls.Add(Me.txtType)
Me.Controls.Add(Me.lblType)
Me.Controls.Add(Me.txtClass)
Me.Controls.Add(Me.lblClass)
Me.Controls.Add(Me.txtGrade)
Me.Controls.Add(Me.lblGrade)
Me.Controls.Add(Me.lblProjectName)
Me.Controls.Add(Me.txtProjectName)
Me.Controls.Add(Me.txtLastNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent1)
Me.Controls.Add(Me.txtLastNameStudent1)
Me.Controls.Add(Me.LblFirstNameStudent2)
Me.Controls.Add(Me.lblFirstNameStudent1)
Me.Controls.Add(Me.lblLastName2)
Me.Controls.Add(Me.lblLastName1)
Me.Name = "Form1"
Me.Text = "Science Fair Entries"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnAddtoRecord_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAddtoRecord.Click
Dim x As Boolean
CheckClass(x)
If x Then
CheckGrade(x)
End If
If x Then
CheckType(x)
End If
Dim record As IO.StreamWriter =
IO.File.AppendText(dlgSaveFile.FileName)
record.WriteLine("")
record.WriteLine("Names:" & " " & txtFirstNameStudent1.Text & "
" & txtLastNameStudent1.Text & "," & " " & txtFirstNameStudent2.Text &
" " & txtLastNameStudent2.Text)
record.WriteLine("Type:" & " " & txtType.Text)
record.WriteLine("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLine("Project Title:" & " " & txtProjectName.Text)
record.WriteLine(" ")

record.WriteLine("================================ ======================")
record.Close()
txtFirstNameStudent1.Clear()
txtLastNameStudent1.Clear()
txtFirstNameStudent2.Clear()
txtLastNameStudent2.Clear()
txtClass.Clear()
txtGrade.Clear()
txtType.Clear()
txtProjectName.Clear()
End Sub
Function CheckClass(ByRef classanalyze As Boolean) As Boolean
Select Case txtClass.Text
Case "A"
classanalyze = True
Case "B"
classanalyze = True
Case "C"
classanalyze = True
Case Else
MsgBox("You have inputted an invalid Class. Please
select a Class between A and C")
classanalyze = False
End Select
Return classanalyze
End Function
Function CheckGrade(ByRef analyzegrade As Boolean) As Boolean
Select Case txtGrade.Text
Case "4"
txtGrade.Text = "4"
analyzegrade = True

Case "5"
txtGrade.Text = "5"
analyzegrade = True
Case "6"
txtGrade.Text = "6"
analyzegrade = True
Case Else
analyzegrade = False
MsgBox("You have inputted an invalid Grade. Please
select a Grade between 4 or 6")
Return analyzegrade
End Select
End Function
Function CheckType(ByRef typeanalyze As Boolean) As Boolean
Dim type As String
Select Case txtType.Text
Case "I"
txtType.Text = "Invention"
typeanalyze = True
Case "S"
txtType.Text = "Study"
typeanalyze = True
Case "X"
txtType.Text = "Experiment"
typeanalyze = True
Case Else
typeanalyze = False
MsgBox("You have inputted an invalid Project Type.
Please enter I for an invention, X for an experiment, or S for a
study")
Return typeanalyze
End Select
End Function

End Class


Apr 13 '06 #2
Define "won't work". Are you getting an error? Step through the code in the
debugger to see what is going on

Jeff

"dc15" <de******@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I am trying to write an application, taking input from various text
boxes and appending it to a text file.... it was working, then I had to
create various sub procedures to reflect limits set in place (class: A
through C), (type: X, I, S), grade (4 through 6)

Ive tried everything and it still wont work, anyone have any ideas?

heres my code

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblLastName1 As System.Windows.Forms.Label
Friend WithEvents lblLastName2 As System.Windows.Forms.Label
Friend WithEvents lblFirstNameStudent1 As
System.Windows.Forms.Label
Friend WithEvents LblFirstNameStudent2 As
System.Windows.Forms.Label
Friend WithEvents txtLastNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent1 As
System.Windows.Forms.TextBox
Friend WithEvents txtFirstNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtLastNameStudent2 As
System.Windows.Forms.TextBox
Friend WithEvents txtProjectName As System.Windows.Forms.TextBox
Friend WithEvents lblProjectName As System.Windows.Forms.Label
Friend WithEvents lblGrade As System.Windows.Forms.Label
Friend WithEvents lblClass As System.Windows.Forms.Label
Friend WithEvents txtGrade As System.Windows.Forms.TextBox
Friend WithEvents txtClass As System.Windows.Forms.TextBox
Friend WithEvents lblType As System.Windows.Forms.Label
Friend WithEvents txtType As System.Windows.Forms.TextBox
Friend WithEvents btnAddtoRecord As System.Windows.Forms.Button
Friend WithEvents dlgSaveFile As
System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.lblLastName1 = New System.Windows.Forms.Label
Me.lblLastName2 = New System.Windows.Forms.Label
Me.lblFirstNameStudent1 = New System.Windows.Forms.Label
Me.LblFirstNameStudent2 = New System.Windows.Forms.Label
Me.txtLastNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent1 = New System.Windows.Forms.TextBox
Me.txtFirstNameStudent2 = New System.Windows.Forms.TextBox
Me.txtLastNameStudent2 = New System.Windows.Forms.TextBox
Me.txtProjectName = New System.Windows.Forms.TextBox
Me.lblProjectName = New System.Windows.Forms.Label
Me.lblGrade = New System.Windows.Forms.Label
Me.txtGrade = New System.Windows.Forms.TextBox
Me.lblClass = New System.Windows.Forms.Label
Me.txtClass = New System.Windows.Forms.TextBox
Me.lblType = New System.Windows.Forms.Label
Me.txtType = New System.Windows.Forms.TextBox
Me.btnAddtoRecord = New System.Windows.Forms.Button
Me.dlgSaveFile = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'lblLastName1
'
Me.lblLastName1.Location = New System.Drawing.Point(8, 48)
Me.lblLastName1.Name = "lblLastName1"
Me.lblLastName1.Size = New System.Drawing.Size(128, 23)
Me.lblLastName1.TabIndex = 0
Me.lblLastName1.Text = "Last Name of Student 1:"
Me.lblLastName1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblLastName2
'
Me.lblLastName2.Location = New System.Drawing.Point(8, 112)
Me.lblLastName2.Name = "lblLastName2"
Me.lblLastName2.Size = New System.Drawing.Size(128, 23)
Me.lblLastName2.TabIndex = 1
Me.lblLastName2.Text = "Last Name of Student 2:"
Me.lblLastName2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblFirstNameStudent1
'
Me.lblFirstNameStudent1.Location = New System.Drawing.Point(8,
16)
Me.lblFirstNameStudent1.Name = "lblFirstNameStudent1"
Me.lblFirstNameStudent1.Size = New System.Drawing.Size(128, 23)
Me.lblFirstNameStudent1.TabIndex = 2
Me.lblFirstNameStudent1.Text = "First Name of Student 1:"
Me.lblFirstNameStudent1.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'LblFirstNameStudent2
'
Me.LblFirstNameStudent2.Location = New System.Drawing.Point(8,
80)
Me.LblFirstNameStudent2.Name = "LblFirstNameStudent2"
Me.LblFirstNameStudent2.Size = New System.Drawing.Size(128, 23)
Me.LblFirstNameStudent2.TabIndex = 3
Me.LblFirstNameStudent2.Text = "First Name of Student 2:"
Me.LblFirstNameStudent2.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtLastNameStudent1
'
Me.txtLastNameStudent1.Location = New System.Drawing.Point(144,
48)
Me.txtLastNameStudent1.Name = "txtLastNameStudent1"
Me.txtLastNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent1.TabIndex = 4
Me.txtLastNameStudent1.Text = ""
'
'txtFirstNameStudent1
'
Me.txtFirstNameStudent1.Location = New
System.Drawing.Point(144, 16)
Me.txtFirstNameStudent1.Name = "txtFirstNameStudent1"
Me.txtFirstNameStudent1.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent1.TabIndex = 5
Me.txtFirstNameStudent1.Text = ""
'
'txtFirstNameStudent2
'
Me.txtFirstNameStudent2.Location = New
System.Drawing.Point(144, 80)
Me.txtFirstNameStudent2.Name = "txtFirstNameStudent2"
Me.txtFirstNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtFirstNameStudent2.TabIndex = 6
Me.txtFirstNameStudent2.Text = ""
'
'txtLastNameStudent2
'
Me.txtLastNameStudent2.Location = New System.Drawing.Point(144,
112)
Me.txtLastNameStudent2.Name = "txtLastNameStudent2"
Me.txtLastNameStudent2.Size = New System.Drawing.Size(160, 20)
Me.txtLastNameStudent2.TabIndex = 7
Me.txtLastNameStudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectName.Location = New System.Drawing.Point(144, 144)
Me.txtProjectName.Name = "txtProjectName"
Me.txtProjectName.Size = New System.Drawing.Size(160, 20)
Me.txtProjectName.TabIndex = 8
Me.txtProjectName.Text = ""
'
'lblProjectName
'
Me.lblProjectName.Location = New System.Drawing.Point(8, 144)
Me.lblProjectName.Name = "lblProjectName"
Me.lblProjectName.Size = New System.Drawing.Size(128, 23)
Me.lblProjectName.TabIndex = 9
Me.lblProjectName.Text = "Project Name:"
Me.lblProjectName.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'lblGrade
'
Me.lblGrade.Location = New System.Drawing.Point(8, 176)
Me.lblGrade.Name = "lblGrade"
Me.lblGrade.Size = New System.Drawing.Size(128, 23)
Me.lblGrade.TabIndex = 10
Me.lblGrade.Text = "Grade:"
Me.lblGrade.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtGrade
'
Me.txtGrade.Location = New System.Drawing.Point(144, 176)
Me.txtGrade.Name = "txtGrade"
Me.txtGrade.Size = New System.Drawing.Size(160, 20)
Me.txtGrade.TabIndex = 11
Me.txtGrade.Text = ""
'
'lblClass
'
Me.lblClass.Location = New System.Drawing.Point(8, 208)
Me.lblClass.Name = "lblClass"
Me.lblClass.Size = New System.Drawing.Size(128, 23)
Me.lblClass.TabIndex = 12
Me.lblClass.Text = "Class:"
Me.lblClass.TextAlign =
System.Drawing.ContentAlignment.TopRight
'
'txtClass
'
Me.txtClass.Location = New System.Drawing.Point(144, 208)
Me.txtClass.Name = "txtClass"
Me.txtClass.Size = New System.Drawing.Size(160, 20)
Me.txtClass.TabIndex = 13
Me.txtClass.Text = ""
'
'lblType
'
Me.lblType.Location = New System.Drawing.Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing.Size(128, 23)
Me.lblType.TabIndex = 14
Me.lblType.Text = "Type:"
Me.lblType.TextAlign = System.Drawing.ContentAlignment.TopRight
'
'txtType
'
Me.txtType.Location = New System.Drawing.Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing.Size(160, 20)
Me.txtType.TabIndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoRecord.Location = New System.Drawing.Point(160, 272)
Me.btnAddtoRecord.Name = "btnAddtoRecord"
Me.btnAddtoRecord.Size = New System.Drawing.Size(120, 24)
Me.btnAddtoRecord.TabIndex = 16
Me.btnAddtoRecord.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile.Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(384, 318)
Me.Controls.Add(Me.btnAddtoRecord)
Me.Controls.Add(Me.txtType)
Me.Controls.Add(Me.lblType)
Me.Controls.Add(Me.txtClass)
Me.Controls.Add(Me.lblClass)
Me.Controls.Add(Me.txtGrade)
Me.Controls.Add(Me.lblGrade)
Me.Controls.Add(Me.lblProjectName)
Me.Controls.Add(Me.txtProjectName)
Me.Controls.Add(Me.txtLastNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent2)
Me.Controls.Add(Me.txtFirstNameStudent1)
Me.Controls.Add(Me.txtLastNameStudent1)
Me.Controls.Add(Me.LblFirstNameStudent2)
Me.Controls.Add(Me.lblFirstNameStudent1)
Me.Controls.Add(Me.lblLastName2)
Me.Controls.Add(Me.lblLastName1)
Me.Name = "Form1"
Me.Text = "Science Fair Entries"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnAddtoRecord_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAddtoRecord.Click
Dim x As Boolean
CheckClass(x)
If x Then
CheckGrade(x)
End If
If x Then
CheckType(x)
End If
Dim record As IO.StreamWriter =
IO.File.AppendText(dlgSaveFile.FileName)
record.WriteLine("")
record.WriteLine("Names:" & " " & txtFirstNameStudent1.Text & "
" & txtLastNameStudent1.Text & "," & " " & txtFirstNameStudent2.Text &
" " & txtLastNameStudent2.Text)
record.WriteLine("Type:" & " " & txtType.Text)
record.WriteLine("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLine("Project Title:" & " " & txtProjectName.Text)
record.WriteLine(" ")

record.WriteLine("================================ ======================")
record.Close()
txtFirstNameStudent1.Clear()
txtLastNameStudent1.Clear()
txtFirstNameStudent2.Clear()
txtLastNameStudent2.Clear()
txtClass.Clear()
txtGrade.Clear()
txtType.Clear()
txtProjectName.Clear()
End Sub
Function CheckClass(ByRef classanalyze As Boolean) As Boolean
Select Case txtClass.Text
Case "A"
classanalyze = True
Case "B"
classanalyze = True
Case "C"
classanalyze = True
Case Else
MsgBox("You have inputted an invalid Class. Please
select a Class between A and C")
classanalyze = False
End Select
Return classanalyze
End Function
Function CheckGrade(ByRef analyzegrade As Boolean) As Boolean
Select Case txtGrade.Text
Case "4"
txtGrade.Text = "4"
analyzegrade = True

Case "5"
txtGrade.Text = "5"
analyzegrade = True
Case "6"
txtGrade.Text = "6"
analyzegrade = True
Case Else
analyzegrade = False
MsgBox("You have inputted an invalid Grade. Please
select a Grade between 4 or 6")
Return analyzegrade
End Select
End Function
Function CheckType(ByRef typeanalyze As Boolean) As Boolean
Dim type As String
Select Case txtType.Text
Case "I"
txtType.Text = "Invention"
typeanalyze = True
Case "S"
txtType.Text = "Study"
typeanalyze = True
Case "X"
txtType.Text = "Experiment"
typeanalyze = True
Case Else
typeanalyze = False
MsgBox("You have inputted an invalid Project Type.
Please enter I for an invention, X for an experiment, or S for a
study")
Return typeanalyze
End Select
End Function

End Class

Apr 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Colby | last post by:
Using the following code I am trying to write to a text file. I keep getting "£" All I want is "£" Any Ideas? using System;
1
by: Wootaek Choi | last post by:
I've tried to record some data to the file with C#. The data should be added in the end of log file, And If there is no log file, A new log file should be created to write the data for that...
2
by: Mullin Yu | last post by:
I create a component to write the error log as follow, but it seems sometimes locked by other processes, and pop up the I/O exception. How can we handling the concurrency issue at file level?...
1
by: Mullin Yu | last post by:
is the following capable of restricting more than one program writing error log to file? in the past, i got error stating the log file is currently opened by another process. private void...
7
by: mahendranepali | last post by:
I am making a simulator application that will simulate different concurrent users connecting to a database. the application creates different userkeys and pushes them to the database tables. The...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
7
by: Andrew | last post by:
VB .NET 2003, WinXP Pro: Adding text to a text box with the TextBox.AppendText method limits the amount of text in the textbox to 32K. I have a short program that uses the GetFiles function of...
7
by: CCLeasing | last post by:
I would like to open a text file titled (c:\logs.txt). If the file doesn't exist i would like to create it. if it does exist i would like to append to it. I would like to insert a line into the...
0
by: rwf_20 | last post by:
I've got a form that contains a RichTextBox control and periodically receives strings to append to it. The function in question is below. I've been receiving mysterious bug reports of application...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.