nK0de, on 06 February 2012 - 10:47 AM, said:
what I meant by disabling boxes is to write a function like this to disable Textboxes after data is saved so that the user can't enter anymore data.
if its too much of a trouble, remove disableBoxes() from the code for now as I see you're not very familiar with Functions yet. Its not necessary for the program to run.
Public Function disableBoxes() As Integer
txtCarrier.Enabled = False
txtLocation.Enabled = False
'all the other Textboxes
Return Nothing
End Function
if its too much of a trouble, remove disableBoxes() from the code for now as I see you're not very familiar with Functions yet. Its not necessary for the program to run.
ok when i did that the program works great,
but it asks me for the load origin and destination and for the file name, everytime i click the save button.
instead of it just asking once..
other then that it works perfect.
what did i do wrong??
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
'declare variables to hold the header details and the filename
Dim loadOrigin, destination, deliverdate, filename, path As String
Dim flag As Boolean = False
loadOrigin = InputBox("Where is the Load Origin?", "Origin")
destination = InputBox("Where is the Destination?", "Destination")
deliverdate = InputBox("Where is the delivery date?", "Delivery date")
filename = InputBox("What's the text file name?", "File Name")
path = "C:\" + filename + ".txt"
If File.Exists(path) Then
MessageBox.Show("File already exists")
Exit Sub 'always remember to put "Exit Sub" after the condition you do not want to proceed. It holds the program there. If not the execution will continue with the rest of the code even after you get the error message
Else
Dim fs As FileStream = File.Create(path)
fs.Dispose()
Dim writer As New StreamWriter(path, True)
If flag = False Then
writer.Write("Origin : " & Trim(loadOrigin) & vbTab & "-" & vbTab)
writer.Write("Destination : " & Trim(destination) & vbTab & "-" & vbTab)
writer.Write("Deliver Date : " & Trim(deliverdate) & vbTab & vbCrLf & vbCrLf & vbCrLf)
flag = True
'See the variable declaration part at the beginning. This flag variable make the header details to be
'written to the text file only once. It is initialized as False. So when it comes down here and this
'If statement checks if the True or false and since it is False, the header details get written to the
'file. And after that it switches to True. Then when you append another, it comes down here and checks
'with the If statement but now its value is True. So it skips writing header details once again.
End If
writer.Write(Trim(carrierbox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(locationbox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(destinationbox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(quotebox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(phonebox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(faxbox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(emailbox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(datebox.Text) & vbTab & "-" & vbTab)
writer.Write(Trim(notebox.Text) & vbTab & vbCrLf & vbCrLf)
writer.Write(Trim(emptybox.Text) & vbTab & "-" & vbTab)
writer.Close()
MessageBox.Show("Text written to file", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
clearFields() 'a function to clear out all the data from all the textboxes
End If
End Sub
Public Function clearFields() As Integer
'created a function to clear out fields
carrierbox.Text = ""
locationbox.Text = ""
destinationbox.Text = ""
quotebox.Text = ""
phonebox.Text = ""
faxbox.Text = ""
emailbox.Text = ""
datebox.Text = ""
notebox.Text = ""
emptybox.Text = ""
End Function
End Class

New Topic/Question
Reply




MultiQuote


|