Imports System I0
Public Class Form1
'Class-level variables
Dim strFileName As String 'File name
Dim employeeFile As StreamWriter 'Object variable
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Get the file name from user
strFileName = InputBox("Enter the filename.")
Try
'Open the file
employeeFile = File.CreateText(strFileName)
Catch ex As Exception
End Try
'Error Message
MessageBox.Show("Cannot create file.")
End Sub
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
'Local variables
Dim strFirst As String 'first name
Dim strMiddle As String 'middle name
Dim strLast As String 'last name
Dim strEmpNum As String 'employee number
Dim strDepartment As String 'Department
Dim strTelephone As String 'Telephone number
Dim strExtension As String 'Extension
Dim strEmail As String 'Email address
'copy the textbox information into variables.
strFirst = txtFirst.Text
strMiddle = txtMiddle.Text
strLast = txtLast.Text
strEmpNum = txtEmpNum.Text
strDepartment = cboDepartment.Text
strTelephone = txtTelephone.Text
strExtension = txtExtension.Text
strEmail = txtEmail.Text
'Write the data to the file
employeeFile.WriteLine(strFirst)
employeeFile.WriteLine(strMiddle)
employeeFile.WriteLine(strLast)
employeeFile.WriteLine(strEmpNum)
employeeFile.WriteLine(strDepartment)
employeeFile.WriteLine(strTelephone)
employeeFile.WriteLine(strExtension)
employeeFile.WriteLine(strEmail)
'Close the file.
employeeFile.Close()
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
'Clear the textboxes
txtFirst.Clear()
txtMiddle.Clear()
txtLast.Clear()
txtEmpNum.Clear()
txtTelephone.Clear()
txtExtension.Clear()
txtEmail.Clear()
'Reset the combo box.
cboDepartment.SelectedIndex = -1
cboDepartment.Text = String.Empty
'Returns focus to first name box
txtFirst.Focus()
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
'Close the form.
Me.Close()
End Sub
End Class
1 Replies - 511 Views - Last Post: 15 September 2012 - 09:27 AM
#1
1. type streamwriter is not defined 2. file is not declared
Posted 15 September 2012 - 07:25 AM
Replies To: 1. type streamwriter is not defined 2. file is not declared
#2
Re: 1. type streamwriter is not defined 2. file is not declared
Posted 15 September 2012 - 09:27 AM
welcome to the forum.
A couple of points.
1. This is VB.Net code, so you're in the wrong forum.
2. Please post your code using the [ CODE] tags. This will format the code and make it easier to read.
3. Try to explain what your problem is and where it occurs.
A couple of points.
1. This is VB.Net code, so you're in the wrong forum.
2. Please post your code using the [ CODE] tags. This will format the code and make it easier to read.
3. Try to explain what your problem is and where it occurs.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|