![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
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 SubPrivate 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
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. Last edited by bigguy; Aug 18th, 2007 at 4:21 AM. Reason: Trying to fix the CODE |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Repost your code with line breaks so it's legible and I will take a look.
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#3 |
|
Professional Programmer
|
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 SubPrivate 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
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
When you write the 2nd file are you updating the number variable with the new number from txtnumber.text? It doesn't appear so.
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#5 | ||
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3
![]() |
Quote:
What was this error it handled?
__________________
Quote:
|
||
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
What I don't understand is that this has got 102 views and yet only (now 5 replies)...
Sorry for the OT nonesense... |
|
|
|
|
|
#7 | ||
|
Expert Programmer
|
Quote:
Quote:
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org Last edited by Kilo; Aug 30th, 2007 at 4:27 PM. Reason: Added a quote... |
||
|
|
|
|
|
#8 |
|
Professional Programmer
|
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?
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. Last edited by bigguy; Aug 30th, 2007 at 10:12 PM. Reason: Forgot soemthing |
|
|
|
|
|
#9 | |
|
Expert Programmer
|
Quote:
number = txtnumber.text File.WriteAllText(My.Application.Info.DirectoryPath & "\" & number & ".emp")
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
|
#10 |
|
Professional Programmer
|
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
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain Destruction leads to a very rough road, but it also breeds creation. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 8th, 2007 11:50 PM |
| OnlineTextEditor.Com! | Sane | Show Off Your Open Source Projects | 43 | Jun 16th, 2006 8:55 AM |
| Writing to a file from a TSR (MASM16) | Roku | Assembly | 2 | Apr 29th, 2006 7:08 PM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 9:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |