473,549 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IO.File.AppendT ext 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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblFirstNameStu dent1 As
System.Windows. Forms.Label
Friend WithEvents LblFirstNameStu dent2 As
System.Windows. Forms.Label
Friend WithEvents txtLastNameStud ent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent2 As
System.Windows. Forms.TextBox
Friend WithEvents txtLastNameStud ent2 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.SaveFileD ialog
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.lblLastName1 = New System.Windows. Forms.Label
Me.lblLastName2 = New System.Windows. Forms.Label
Me.lblFirstName Student1 = New System.Windows. Forms.Label
Me.LblFirstName Student2 = New System.Windows. Forms.Label
Me.txtLastNameS tudent1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student2 = New System.Windows. Forms.TextBox
Me.txtLastNameS tudent2 = New System.Windows. Forms.TextBox
Me.txtProjectNa me = New System.Windows. Forms.TextBox
Me.lblProjectNa me = 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.btnAddtoReco rd = New System.Windows. Forms.Button
Me.dlgSaveFile = New System.Windows. Forms.SaveFileD ialog
Me.SuspendLayou t()
'
'lblLastName1
'
Me.lblLastName1 .Location = New System.Drawing. Point(8, 48)
Me.lblLastName1 .Name = "lblLastNam e1"
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. ContentAlignmen t.TopRight
'
'lblLastName2
'
Me.lblLastName2 .Location = New System.Drawing. Point(8, 112)
Me.lblLastName2 .Name = "lblLastNam e2"
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. ContentAlignmen t.TopRight
'
'lblFirstNameSt udent1
'
Me.lblFirstName Student1.Locati on = New System.Drawing. Point(8,
16)
Me.lblFirstName Student1.Name = "lblFirstNameSt udent1"
Me.lblFirstName Student1.Size = New System.Drawing. Size(128, 23)
Me.lblFirstName Student1.TabInd ex = 2
Me.lblFirstName Student1.Text = "First Name of Student 1:"
Me.lblFirstName Student1.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'LblFirstNameSt udent2
'
Me.LblFirstName Student2.Locati on = New System.Drawing. Point(8,
80)
Me.LblFirstName Student2.Name = "LblFirstNameSt udent2"
Me.LblFirstName Student2.Size = New System.Drawing. Size(128, 23)
Me.LblFirstName Student2.TabInd ex = 3
Me.LblFirstName Student2.Text = "First Name of Student 2:"
Me.LblFirstName Student2.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtLastNameStu dent1
'
Me.txtLastNameS tudent1.Locatio n = New System.Drawing. Point(144,
48)
Me.txtLastNameS tudent1.Name = "txtLastNameStu dent1"
Me.txtLastNameS tudent1.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent1.TabInde x = 4
Me.txtLastNameS tudent1.Text = ""
'
'txtFirstNameSt udent1
'
Me.txtFirstName Student1.Locati on = New
System.Drawing. Point(144, 16)
Me.txtFirstName Student1.Name = "txtFirstNameSt udent1"
Me.txtFirstName Student1.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student1.TabInd ex = 5
Me.txtFirstName Student1.Text = ""
'
'txtFirstNameSt udent2
'
Me.txtFirstName Student2.Locati on = New
System.Drawing. Point(144, 80)
Me.txtFirstName Student2.Name = "txtFirstNameSt udent2"
Me.txtFirstName Student2.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student2.TabInd ex = 6
Me.txtFirstName Student2.Text = ""
'
'txtLastNameStu dent2
'
Me.txtLastNameS tudent2.Locatio n = New System.Drawing. Point(144,
112)
Me.txtLastNameS tudent2.Name = "txtLastNameStu dent2"
Me.txtLastNameS tudent2.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent2.TabInde x = 7
Me.txtLastNameS tudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectNa me.Location = New System.Drawing. Point(144, 144)
Me.txtProjectNa me.Name = "txtProjectName "
Me.txtProjectNa me.Size = New System.Drawing. Size(160, 20)
Me.txtProjectNa me.TabIndex = 8
Me.txtProjectNa me.Text = ""
'
'lblProjectName
'
Me.lblProjectNa me.Location = New System.Drawing. Point(8, 144)
Me.lblProjectNa me.Name = "lblProjectName "
Me.lblProjectNa me.Size = New System.Drawing. Size(128, 23)
Me.lblProjectNa me.TabIndex = 9
Me.lblProjectNa me.Text = "Project Name:"
Me.lblProjectNa me.TextAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'lblGrade
'
Me.lblGrade.Loc ation = New System.Drawing. Point(8, 176)
Me.lblGrade.Nam e = "lblGrade"
Me.lblGrade.Siz e = New System.Drawing. Size(128, 23)
Me.lblGrade.Tab Index = 10
Me.lblGrade.Tex t = "Grade:"
Me.lblGrade.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtGrade
'
Me.txtGrade.Loc ation = New System.Drawing. Point(144, 176)
Me.txtGrade.Nam e = "txtGrade"
Me.txtGrade.Siz e = New System.Drawing. Size(160, 20)
Me.txtGrade.Tab Index = 11
Me.txtGrade.Tex t = ""
'
'lblClass
'
Me.lblClass.Loc ation = New System.Drawing. Point(8, 208)
Me.lblClass.Nam e = "lblClass"
Me.lblClass.Siz e = New System.Drawing. Size(128, 23)
Me.lblClass.Tab Index = 12
Me.lblClass.Tex t = "Class:"
Me.lblClass.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtClass
'
Me.txtClass.Loc ation = New System.Drawing. Point(144, 208)
Me.txtClass.Nam e = "txtClass"
Me.txtClass.Siz e = New System.Drawing. Size(160, 20)
Me.txtClass.Tab Index = 13
Me.txtClass.Tex t = ""
'
'lblType
'
Me.lblType.Loca tion = New System.Drawing. Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing. Size(128, 23)
Me.lblType.TabI ndex = 14
Me.lblType.Text = "Type:"
Me.lblType.Text Align = System.Drawing. ContentAlignmen t.TopRight
'
'txtType
'
Me.txtType.Loca tion = New System.Drawing. Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing. Size(160, 20)
Me.txtType.TabI ndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoReco rd.Location = New System.Drawing. Point(160, 272)
Me.btnAddtoReco rd.Name = "btnAddtoRecord "
Me.btnAddtoReco rd.Size = New System.Drawing. Size(120, 24)
Me.btnAddtoReco rd.TabIndex = 16
Me.btnAddtoReco rd.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile. Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(384, 318)
Me.Controls.Add (Me.btnAddtoRec ord)
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.lblProjectN ame)
Me.Controls.Add (Me.txtProjectN ame)
Me.Controls.Add (Me.txtLastName Student2)
Me.Controls.Add (Me.txtFirstNam eStudent2)
Me.Controls.Add (Me.txtFirstNam eStudent1)
Me.Controls.Add (Me.txtLastName Student1)
Me.Controls.Add (Me.LblFirstNam eStudent2)
Me.Controls.Add (Me.lblFirstNam eStudent1)
Me.Controls.Add (Me.lblLastName 2)
Me.Controls.Add (Me.lblLastName 1)
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.EventArg s) 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.AppendT ext(dlgSaveFile .FileName)
record.WriteLin e("")
record.WriteLin e("Names:" & " " & txtFirstNameStu dent1.Text & "
" & txtLastNameStud ent1.Text & "," & " " & txtFirstNameStu dent2.Text &
" " & txtLastNameStud ent2.Text)
record.WriteLin e("Type:" & " " & txtType.Text)
record.WriteLin e("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLin e("Project Title:" & " " & txtProjectName. Text)
record.WriteLin e(" ")

record.WriteLin e("============ =============== =============== ============")
record.Close()
txtFirstNameStu dent1.Clear()
txtLastNameStud ent1.Clear()
txtFirstNameStu dent2.Clear()
txtLastNameStud ent2.Clear()
txtClass.Clear( )
txtGrade.Clear( )
txtType.Clear()
txtProjectName. Clear()
End Sub
Function CheckClass(ByRe f 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(ByRe f 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 1870
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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblFirstNameStu dent1 As
System.Windows. Forms.Label
Friend WithEvents LblFirstNameStu dent2 As
System.Windows. Forms.Label
Friend WithEvents txtLastNameStud ent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent2 As
System.Windows. Forms.TextBox
Friend WithEvents txtLastNameStud ent2 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.SaveFileD ialog
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.lblLastName1 = New System.Windows. Forms.Label
Me.lblLastName2 = New System.Windows. Forms.Label
Me.lblFirstName Student1 = New System.Windows. Forms.Label
Me.LblFirstName Student2 = New System.Windows. Forms.Label
Me.txtLastNameS tudent1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student2 = New System.Windows. Forms.TextBox
Me.txtLastNameS tudent2 = New System.Windows. Forms.TextBox
Me.txtProjectNa me = New System.Windows. Forms.TextBox
Me.lblProjectNa me = 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.btnAddtoReco rd = New System.Windows. Forms.Button
Me.dlgSaveFile = New System.Windows. Forms.SaveFileD ialog
Me.SuspendLayou t()
'
'lblLastName1
'
Me.lblLastName1 .Location = New System.Drawing. Point(8, 48)
Me.lblLastName1 .Name = "lblLastNam e1"
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. ContentAlignmen t.TopRight
'
'lblLastName2
'
Me.lblLastName2 .Location = New System.Drawing. Point(8, 112)
Me.lblLastName2 .Name = "lblLastNam e2"
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. ContentAlignmen t.TopRight
'
'lblFirstNameSt udent1
'
Me.lblFirstName Student1.Locati on = New System.Drawing. Point(8,
16)
Me.lblFirstName Student1.Name = "lblFirstNameSt udent1"
Me.lblFirstName Student1.Size = New System.Drawing. Size(128, 23)
Me.lblFirstName Student1.TabInd ex = 2
Me.lblFirstName Student1.Text = "First Name of Student 1:"
Me.lblFirstName Student1.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'LblFirstNameSt udent2
'
Me.LblFirstName Student2.Locati on = New System.Drawing. Point(8,
80)
Me.LblFirstName Student2.Name = "LblFirstNameSt udent2"
Me.LblFirstName Student2.Size = New System.Drawing. Size(128, 23)
Me.LblFirstName Student2.TabInd ex = 3
Me.LblFirstName Student2.Text = "First Name of Student 2:"
Me.LblFirstName Student2.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtLastNameStu dent1
'
Me.txtLastNameS tudent1.Locatio n = New System.Drawing. Point(144,
48)
Me.txtLastNameS tudent1.Name = "txtLastNameStu dent1"
Me.txtLastNameS tudent1.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent1.TabInde x = 4
Me.txtLastNameS tudent1.Text = ""
'
'txtFirstNameSt udent1
'
Me.txtFirstName Student1.Locati on = New
System.Drawing. Point(144, 16)
Me.txtFirstName Student1.Name = "txtFirstNameSt udent1"
Me.txtFirstName Student1.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student1.TabInd ex = 5
Me.txtFirstName Student1.Text = ""
'
'txtFirstNameSt udent2
'
Me.txtFirstName Student2.Locati on = New
System.Drawing. Point(144, 80)
Me.txtFirstName Student2.Name = "txtFirstNameSt udent2"
Me.txtFirstName Student2.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student2.TabInd ex = 6
Me.txtFirstName Student2.Text = ""
'
'txtLastNameStu dent2
'
Me.txtLastNameS tudent2.Locatio n = New System.Drawing. Point(144,
112)
Me.txtLastNameS tudent2.Name = "txtLastNameStu dent2"
Me.txtLastNameS tudent2.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent2.TabInde x = 7
Me.txtLastNameS tudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectNa me.Location = New System.Drawing. Point(144, 144)
Me.txtProjectNa me.Name = "txtProjectName "
Me.txtProjectNa me.Size = New System.Drawing. Size(160, 20)
Me.txtProjectNa me.TabIndex = 8
Me.txtProjectNa me.Text = ""
'
'lblProjectName
'
Me.lblProjectNa me.Location = New System.Drawing. Point(8, 144)
Me.lblProjectNa me.Name = "lblProjectName "
Me.lblProjectNa me.Size = New System.Drawing. Size(128, 23)
Me.lblProjectNa me.TabIndex = 9
Me.lblProjectNa me.Text = "Project Name:"
Me.lblProjectNa me.TextAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'lblGrade
'
Me.lblGrade.Loc ation = New System.Drawing. Point(8, 176)
Me.lblGrade.Nam e = "lblGrade"
Me.lblGrade.Siz e = New System.Drawing. Size(128, 23)
Me.lblGrade.Tab Index = 10
Me.lblGrade.Tex t = "Grade:"
Me.lblGrade.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtGrade
'
Me.txtGrade.Loc ation = New System.Drawing. Point(144, 176)
Me.txtGrade.Nam e = "txtGrade"
Me.txtGrade.Siz e = New System.Drawing. Size(160, 20)
Me.txtGrade.Tab Index = 11
Me.txtGrade.Tex t = ""
'
'lblClass
'
Me.lblClass.Loc ation = New System.Drawing. Point(8, 208)
Me.lblClass.Nam e = "lblClass"
Me.lblClass.Siz e = New System.Drawing. Size(128, 23)
Me.lblClass.Tab Index = 12
Me.lblClass.Tex t = "Class:"
Me.lblClass.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtClass
'
Me.txtClass.Loc ation = New System.Drawing. Point(144, 208)
Me.txtClass.Nam e = "txtClass"
Me.txtClass.Siz e = New System.Drawing. Size(160, 20)
Me.txtClass.Tab Index = 13
Me.txtClass.Tex t = ""
'
'lblType
'
Me.lblType.Loca tion = New System.Drawing. Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing. Size(128, 23)
Me.lblType.TabI ndex = 14
Me.lblType.Text = "Type:"
Me.lblType.Text Align = System.Drawing. ContentAlignmen t.TopRight
'
'txtType
'
Me.txtType.Loca tion = New System.Drawing. Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing. Size(160, 20)
Me.txtType.TabI ndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoReco rd.Location = New System.Drawing. Point(160, 272)
Me.btnAddtoReco rd.Name = "btnAddtoRecord "
Me.btnAddtoReco rd.Size = New System.Drawing. Size(120, 24)
Me.btnAddtoReco rd.TabIndex = 16
Me.btnAddtoReco rd.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile. Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(384, 318)
Me.Controls.Add (Me.btnAddtoRec ord)
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.lblProjectN ame)
Me.Controls.Add (Me.txtProjectN ame)
Me.Controls.Add (Me.txtLastName Student2)
Me.Controls.Add (Me.txtFirstNam eStudent2)
Me.Controls.Add (Me.txtFirstNam eStudent1)
Me.Controls.Add (Me.txtLastName Student1)
Me.Controls.Add (Me.LblFirstNam eStudent2)
Me.Controls.Add (Me.lblFirstNam eStudent1)
Me.Controls.Add (Me.lblLastName 2)
Me.Controls.Add (Me.lblLastName 1)
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.EventArg s) 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.AppendT ext(dlgSaveFile .FileName)
record.WriteLin e("")
record.WriteLin e("Names:" & " " & txtFirstNameStu dent1.Text & "
" & txtLastNameStud ent1.Text & "," & " " & txtFirstNameStu dent2.Text &
" " & txtLastNameStud ent2.Text)
record.WriteLin e("Type:" & " " & txtType.Text)
record.WriteLin e("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLin e("Project Title:" & " " & txtProjectName. Text)
record.WriteLin e(" ")

record.WriteLin e("============ =============== =============== ============")
record.Close()
txtFirstNameStu dent1.Clear()
txtLastNameStud ent1.Clear()
txtFirstNameStu dent2.Clear()
txtLastNameStud ent2.Clear()
txtClass.Clear( )
txtGrade.Clear( )
txtType.Clear()
txtProjectName. Clear()
End Sub
Function CheckClass(ByRe f 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(ByRe f 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.goo glegroups.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'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 lblFirstNameStu dent1 As
System.Windows. Forms.Label
Friend WithEvents LblFirstNameStu dent2 As
System.Windows. Forms.Label
Friend WithEvents txtLastNameStud ent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent1 As
System.Windows. Forms.TextBox
Friend WithEvents txtFirstNameStu dent2 As
System.Windows. Forms.TextBox
Friend WithEvents txtLastNameStud ent2 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.SaveFileD ialog
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.lblLastName1 = New System.Windows. Forms.Label
Me.lblLastName2 = New System.Windows. Forms.Label
Me.lblFirstName Student1 = New System.Windows. Forms.Label
Me.LblFirstName Student2 = New System.Windows. Forms.Label
Me.txtLastNameS tudent1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student1 = New System.Windows. Forms.TextBox
Me.txtFirstName Student2 = New System.Windows. Forms.TextBox
Me.txtLastNameS tudent2 = New System.Windows. Forms.TextBox
Me.txtProjectNa me = New System.Windows. Forms.TextBox
Me.lblProjectNa me = 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.btnAddtoReco rd = New System.Windows. Forms.Button
Me.dlgSaveFile = New System.Windows. Forms.SaveFileD ialog
Me.SuspendLayou t()
'
'lblLastName1
'
Me.lblLastName1 .Location = New System.Drawing. Point(8, 48)
Me.lblLastName1 .Name = "lblLastNam e1"
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. ContentAlignmen t.TopRight
'
'lblLastName2
'
Me.lblLastName2 .Location = New System.Drawing. Point(8, 112)
Me.lblLastName2 .Name = "lblLastNam e2"
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. ContentAlignmen t.TopRight
'
'lblFirstNameSt udent1
'
Me.lblFirstName Student1.Locati on = New System.Drawing. Point(8,
16)
Me.lblFirstName Student1.Name = "lblFirstNameSt udent1"
Me.lblFirstName Student1.Size = New System.Drawing. Size(128, 23)
Me.lblFirstName Student1.TabInd ex = 2
Me.lblFirstName Student1.Text = "First Name of Student 1:"
Me.lblFirstName Student1.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'LblFirstNameSt udent2
'
Me.LblFirstName Student2.Locati on = New System.Drawing. Point(8,
80)
Me.LblFirstName Student2.Name = "LblFirstNameSt udent2"
Me.LblFirstName Student2.Size = New System.Drawing. Size(128, 23)
Me.LblFirstName Student2.TabInd ex = 3
Me.LblFirstName Student2.Text = "First Name of Student 2:"
Me.LblFirstName Student2.TextAl ign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtLastNameStu dent1
'
Me.txtLastNameS tudent1.Locatio n = New System.Drawing. Point(144,
48)
Me.txtLastNameS tudent1.Name = "txtLastNameStu dent1"
Me.txtLastNameS tudent1.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent1.TabInde x = 4
Me.txtLastNameS tudent1.Text = ""
'
'txtFirstNameSt udent1
'
Me.txtFirstName Student1.Locati on = New
System.Drawing. Point(144, 16)
Me.txtFirstName Student1.Name = "txtFirstNameSt udent1"
Me.txtFirstName Student1.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student1.TabInd ex = 5
Me.txtFirstName Student1.Text = ""
'
'txtFirstNameSt udent2
'
Me.txtFirstName Student2.Locati on = New
System.Drawing. Point(144, 80)
Me.txtFirstName Student2.Name = "txtFirstNameSt udent2"
Me.txtFirstName Student2.Size = New System.Drawing. Size(160, 20)
Me.txtFirstName Student2.TabInd ex = 6
Me.txtFirstName Student2.Text = ""
'
'txtLastNameStu dent2
'
Me.txtLastNameS tudent2.Locatio n = New System.Drawing. Point(144,
112)
Me.txtLastNameS tudent2.Name = "txtLastNameStu dent2"
Me.txtLastNameS tudent2.Size = New System.Drawing. Size(160, 20)
Me.txtLastNameS tudent2.TabInde x = 7
Me.txtLastNameS tudent2.Text = ""
'
'txtProjectName
'
Me.txtProjectNa me.Location = New System.Drawing. Point(144, 144)
Me.txtProjectNa me.Name = "txtProjectName "
Me.txtProjectNa me.Size = New System.Drawing. Size(160, 20)
Me.txtProjectNa me.TabIndex = 8
Me.txtProjectNa me.Text = ""
'
'lblProjectName
'
Me.lblProjectNa me.Location = New System.Drawing. Point(8, 144)
Me.lblProjectNa me.Name = "lblProjectName "
Me.lblProjectNa me.Size = New System.Drawing. Size(128, 23)
Me.lblProjectNa me.TabIndex = 9
Me.lblProjectNa me.Text = "Project Name:"
Me.lblProjectNa me.TextAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'lblGrade
'
Me.lblGrade.Loc ation = New System.Drawing. Point(8, 176)
Me.lblGrade.Nam e = "lblGrade"
Me.lblGrade.Siz e = New System.Drawing. Size(128, 23)
Me.lblGrade.Tab Index = 10
Me.lblGrade.Tex t = "Grade:"
Me.lblGrade.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtGrade
'
Me.txtGrade.Loc ation = New System.Drawing. Point(144, 176)
Me.txtGrade.Nam e = "txtGrade"
Me.txtGrade.Siz e = New System.Drawing. Size(160, 20)
Me.txtGrade.Tab Index = 11
Me.txtGrade.Tex t = ""
'
'lblClass
'
Me.lblClass.Loc ation = New System.Drawing. Point(8, 208)
Me.lblClass.Nam e = "lblClass"
Me.lblClass.Siz e = New System.Drawing. Size(128, 23)
Me.lblClass.Tab Index = 12
Me.lblClass.Tex t = "Class:"
Me.lblClass.Tex tAlign =
System.Drawing. ContentAlignmen t.TopRight
'
'txtClass
'
Me.txtClass.Loc ation = New System.Drawing. Point(144, 208)
Me.txtClass.Nam e = "txtClass"
Me.txtClass.Siz e = New System.Drawing. Size(160, 20)
Me.txtClass.Tab Index = 13
Me.txtClass.Tex t = ""
'
'lblType
'
Me.lblType.Loca tion = New System.Drawing. Point(8, 240)
Me.lblType.Name = "lblType"
Me.lblType.Size = New System.Drawing. Size(128, 23)
Me.lblType.TabI ndex = 14
Me.lblType.Text = "Type:"
Me.lblType.Text Align = System.Drawing. ContentAlignmen t.TopRight
'
'txtType
'
Me.txtType.Loca tion = New System.Drawing. Point(144, 240)
Me.txtType.Name = "txtType"
Me.txtType.Size = New System.Drawing. Size(160, 20)
Me.txtType.TabI ndex = 15
Me.txtType.Text = ""
'
'btnAddtoRecord
'
Me.btnAddtoReco rd.Location = New System.Drawing. Point(160, 272)
Me.btnAddtoReco rd.Name = "btnAddtoRecord "
Me.btnAddtoReco rd.Size = New System.Drawing. Size(120, 24)
Me.btnAddtoReco rd.TabIndex = 16
Me.btnAddtoReco rd.Text = "Add Entry To Record"
'
'dlgSaveFile
'
Me.dlgSaveFile. Filter = "Text Files(*.txt)|"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(384, 318)
Me.Controls.Add (Me.btnAddtoRec ord)
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.lblProjectN ame)
Me.Controls.Add (Me.txtProjectN ame)
Me.Controls.Add (Me.txtLastName Student2)
Me.Controls.Add (Me.txtFirstNam eStudent2)
Me.Controls.Add (Me.txtFirstNam eStudent1)
Me.Controls.Add (Me.txtLastName Student1)
Me.Controls.Add (Me.LblFirstNam eStudent2)
Me.Controls.Add (Me.lblFirstNam eStudent1)
Me.Controls.Add (Me.lblLastName 2)
Me.Controls.Add (Me.lblLastName 1)
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.EventArg s) 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.AppendT ext(dlgSaveFile .FileName)
record.WriteLin e("")
record.WriteLin e("Names:" & " " & txtFirstNameStu dent1.Text & "
" & txtLastNameStud ent1.Text & "," & " " & txtFirstNameStu dent2.Text &
" " & txtLastNameStud ent2.Text)
record.WriteLin e("Type:" & " " & txtType.Text)
record.WriteLin e("Class:" & " " & txtGrade.Text &
txtClass.Text)
record.WriteLin e("Project Title:" & " " & txtProjectName. Text)
record.WriteLin e(" ")

record.WriteLin e("============ =============== =============== ============")
record.Close()
txtFirstNameStu dent1.Clear()
txtLastNameStud ent1.Clear()
txtFirstNameStu dent2.Clear()
txtLastNameStud ent2.Clear()
txtClass.Clear( )
txtGrade.Clear( )
txtType.Clear()
txtProjectName. Clear()
End Sub
Function CheckClass(ByRe f 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(ByRe f 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
3809
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
1902
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 reason, AppendText() function used to open the log file. but AppendText() returns StreamWriter object using utf-8 encode mode. What shall i do to get...
2
4702
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? Retry accessing the file if catch error => like waiting and polling. Thanks! private void LogError2File(string errorMessage, string LogFilePath)
1
4394
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 LogError2File(string errorMessage, string LogFilePath) { FileInfo oFileInfo = new FileInfo(LogFilePath);
7
12399
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 business procedures hence interpret the userkey as a seperate request and act accordingly. For this I need to check the response time to the DB for...
4
2169
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is...
7
6883
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 the directory object, then iterates through the returned array and appends the strings to the textbox. However, if the character count is greater...
7
41991
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 end of the file. The line is contained in the variable 'line' which is a string variable. once i've done this i would like to close the file.
0
1262
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 crashes ('Attempt to Read/Write Protected Memory', 'Object Reference not set to instance of an object') which I cannot recreate. In the reports,...
0
7467
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7827
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.