Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Need Help with Writing to File (http://www.programmingforums.org/showthread.php?t=13800)

bigguy Aug 18th, 2007 5:17 AM

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
Here is my code for the Save Employee Button:
:

  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
Like I said everything would work, if I only wanted to create one employee file. But it wont let me write to another file. When I click save, it erases the text boxes, and if I try to create a file with a duplicate employee number, it handle the error. It just wont create the file. I typed in my info for all the info i needed, clicked save, the text was "" in the textboxes, but no file was created. Am I missing somehtign in my code, guess I've been looking at it for the past hour and a half trying to see it, but i don't. Either I'm tired, or I can't program. I'll let yall be the judge of that. But just help me, if ya can. Thanks

Kilo Aug 30th, 2007 11:00 AM

Repost your code with line breaks so it's legible and I will take a look.

bigguy Aug 30th, 2007 1:58 PM

:

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

Kilo Aug 30th, 2007 4:14 PM

When you write the 2nd file are you updating the number variable with the new number from txtnumber.text? It doesn't appear so.

kruptof Aug 30th, 2007 5:09 PM

Quote:

Originally Posted by bigguy (Post 132411)
if I try to create a file with a duplicate employee number, it handle the error

Won't this mean that you trying to create a file that already exist, since the number is used to in the filename?

What was this error it handled?

mattireland Aug 30th, 2007 5:11 PM

What I don't understand is that this has got 102 views and yet only (now 5 replies)...

Sorry for the OT nonesense...

Kilo Aug 30th, 2007 5:24 PM

Quote:

Originally Posted by kruptof (Post 133021)
Won't this mean that you trying to create a file that already exist, since the number is used to in the filename?

What was this error it handled?

He is saying that part of the program worked correctly. When he attempted to create a duplicate file "the error was thrown" AKA "it handle the error"

Quote:

Originally Posted by mattireland
What I don't understand is that this has got 102 views and yet only (now 5 replies)...

Sorry for the OT nonesense...

Yes that is BS, I completely agree. Usually I use the forum to recieve help and insight on my own problems, but when I see a post like this just sitting around it bothers the hell out of me that no one tries to help. It happens to me all the time.

bigguy Aug 30th, 2007 11:09 PM

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?

Kilo Aug 31st, 2007 9:57 AM

Quote:

Originally Posted by bigguy (Post 133036)
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?

No not really... I meant this

:

number = txtnumber.text
File.WriteAllText(My.Application.Info.DirectoryPath & "\" & number & ".emp")


bigguy Aug 31st, 2007 2:47 PM

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