![]() |
Need Help with Writing to File
Hey I need some help. I cant figure out whats going on. I'm working on a Restaurant Management System, and I can create an employee, but then when I try to create another after I created one, it wont work. My Post Tools aint working so I'm gonna wing it on the CODE Tags. So sorry if it's messy. Maybe big_k can wrap em up till I figure out my problem. Here is the code that saves the employee info to file, and the code to show a message box if that employee number file already exists.
:
Sub Save() File.WriteAllText(My.Application.Info.DirectoryPath & "\" & number & ".emp", _ "-Employee Name Info-:" + vbCrLf _ & first + " " & middle + " " & last + vbCrLf _ & "-Employee Address Info-:" + vbCrLf _ & address + vbCrLf & city + vbCrLf & state + vbCrLf & zip + vbCrLf _ & "-Employee Info-:" + vbCrLf _ & bday + vbCrLf & hphone + vbCrLf & cphone + vbCrLf _ & "-Employee Social Security Number-:" + vbCrLf _ & ssn) managercp.txtfirst.Text = "" managercp.txtmiddle.Text = "" managercp.txtlast.Text = "" managercp.txtaddress.Text = "" managercp.txtcity.Text = "" managercp.txtstate.Text = "" managercp.txtzip.Text = "" managercp.txtbday.Text = "" managercp.txthome.Text = "" managercp.txtcell.Text = "" managercp.txtssn.Text = "" managercp.txtnumber.Text = "" End Sub Sub EmpExists() MsgBox("Employee File with that number already exists. Please specify a new number, or delete the existing Employee File.", _ MsgBoxStyle.Critical, "Employee File Error") End Sub:
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & txtnumber.Text & ".emp") Then Employee.EmpExists() Else Employee.Save() End If End Sub |
Repost your code with line breaks so it's legible and I will take a look.
|
:
Sub Save() :
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click |
When you write the 2nd file are you updating the number variable with the new number from txtnumber.text? It doesn't appear so.
|
Quote:
What was this error it handled? |
What I don't understand is that this has got 102 views and yet only (now 5 replies)...
Sorry for the OT nonesense... |
Quote:
Quote:
|
I think the biggest reason no one helped was because of my damn code tags thanks to avant has now been fixed though. But yeah that EmpExists sub i have created shows the message box incase they already have a employee file with that same number. I guess it really aint an error, but sorry for the confusion.
Also kilo, about the updating this is what I am using. File.WriteAllText(My.Application.Info.DirectoryPath & "\" & number & ".emp" << I specify it to write to number.emp Is that kind of what your asking? |
Quote:
:
number = txtnumber.text |
Yeah I have that I just didnt post that part, cause I didnt think it would help any. But yeah all that first middle and last stuff I have.
Dim number = managercp.txtnumber.text Should I have Dum number As Integer = managercp.txtnumber.text.tostring? Maybe try that |
| All times are GMT -5. The time now is 3:07 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC