Multiple Text Boxes - Write to txt File on Same Line + More.

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 21788 Views - Last Post: 06 February 2012 - 12:09 PM Rate Topic: -----

#1 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 26 January 2012 - 01:05 AM

i am new to coding, I am currently in my 3rd week of my first VB class. i am learning, but i do not know enough yet.

i need to code a program to help me in my everyday job, i own my own business and this will help me with my sales.

its a very simple program, and i cant figure out how to get my multiple textboxes to write to a new .txt file. i can only get it to do 1 line at a time.

I have textboxes. named txtDate, txtCarrier, txtLocation, txtDateEmpty, txtDestination, txtQuote, txtPhone, txtFax, txtEmail.

I want the "txtDate" textbox to be autofilled with the current date and time of the user input, which is started on the next textbox.

the rest of the textboxes are going to be user input.

then when the user is done entering data into the multiple textbox's they would click a button "add" or something to that sort.

then those text box entries including the "txtDate" would be written to a new .txt file.

in this format,

Quote

"Date - Carrier - Location - DateEmpty - Destination - Quote - Phone - Fax - Email "

all on the same line.

and when the "add" button is clicked, the multiple textbox fields clear all the data previously entered.

and is ready for another user input.

after the 2nd set of user input is entered, and "add" button is pressed, it would add(append) another line to the same txt file previously written.
example:

Quote

"Date - Carrier - Location - DateEmpty - Destination - Quote - Phone - Fax - Email "

"Date2 - Carrier2 - Location2 - DateEmpty2 - Destination2 - Quote2 - Phone2 - Fax2 - Email2 "



then the previously filled text boxes would be empty again, and ready for input 3. and with this you would be able to add countless lines over and over of user input.

ok, also when the program launches

I want a msg txt box to pop up and ask.

"Where is the Load Origin?" then the user would input data and click enter
Another Msg box would pop up and ask "Where is the Destination?"
Next "Pick Up Date"
then "Deliver Date"
and last would be "Notes"

and all that data that was entered into the msg box's will Be at the top of the txt file like a header .

example :

Quote

"Origin: Los Angeles, CA - Destination: San Diego, CA - PU: 01/26/12 - Del: 01/27/12 - Note: Must be on time."

"Date - Carrier - Location - DateEmpty - Destination - Quote - Phone - Fax - Email "

"Date2 - Carrier2 - Location2 - DateEmpty2 - Destination2 - Quote2 - Phone2 - Fax2 - Email2 "



and in case the application is closed, and the user wanted to add another set of multiple text box entries to write to a txt file that has already been created. when the application launches, you could browse and selcet the txt file you want to continue to add to.

also

every time you open the application and start a new txt file, by entering in the data into the msg box's, it takes the info from "Pick up Date" and "Origin" and "Destination" and names the txt file that.
Example:

Quote

10/26/12 - Los Angeles CA - San Diego CA.txt


Example on how i would use the software.


I get a call from my customer that he has a load from Dallas TX to houston TX for pick up on 02-01-12 and deliver on 02-02-12.

I post this load on the online load board. and start receiving calls from truckers who are interested in hauling this load.

thats where this program comes in.

when i answer the phone i launch the program, enter in the load details in the pop up msg box's then it creates a txt file.
and than i start to talk to the trucker, and find out all the details to enter into the correct fields (textboxes). I find out the trucking company's name and contact and enter it in the "txtCarrier" textbox.
after i fill all the textbox's accordingly. i click add.

and i keep this program running, and when the next trucker calls i enter in that truckers info also. and repeat until i have a nice list to reference, and select the trucker with the cheapest price.

and if i have another load in addition to the dallas houston load, i just open another instance of the application and enter in the different details for that particular load.

so i can have 5 loads or 10 loads posted on the load board, and 10 applications running, and tab to the different instances for each new call.

would i like to put it in a excel file rather then a txt file? sure. but really i just want something that i can use.

::i just realized:: the form box name should change to the load details that were entered into the msg box, so that the user can differentiation between the instances. and know which instance is linked to which created txt file


I know its a long shot to get this program created. i have been trying for a few days now, and am still stuck , with little progress done.

if anyone can take the time to help e with this i would greatly appreciate it.

and i thank all of you in advance for the help.


-Matt

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple Text Boxes - Write to txt File on Same Line + More.

#2 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 26 January 2012 - 01:30 AM

We can't actually tell you how to write a complete application like that line by line. But I can give you a few things to take note.

* Instead of using a textbox for the date, use DateTimePicker. no need to bother to autofill anything with the current date then. The DateTimePicker control takes care of that.

* Its better to use reports, Crystal Reports for example, to display the data in a certain format than writing them to a text file.

Try hard, do some research on the net, if you get stuck, somewhere, mention the specific problem with the code you have written for that, error messages you're getting. No one will just give you teh codez here.
Was This Post Helpful? 0
  • +
  • -

#3 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 30 January 2012 - 05:12 PM

okay this is what i have so far..


Posted Image

 Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim FILE_NAME As String = "C:\test.txt"

        Dim objReader As New System.IO.StreamReader(FILE_NAME)

        carrierbox.Text = objReader.ReadToEnd

        objReader.Close()

        If System.IO.File.Exists(FILE_NAME) = True Then

        Else
            MsgBox("File Does Not Exist")
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim FILE_NAME As String = "C:\test.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.Write(carrierbox.Text)
            objWriter.Write(quotebox.Text)
            objWriter.Write(locationbox.Text)
            objWriter.Write(namebox.Text)
            objWriter.Write(datebox.Text)
            objWriter.Write(emptybox.Text)
            objWriter.Write(faxbox.Text)
            objWriter.Write(destinationbox.Text)
            objWriter.Write(phonebox.Text)
            objWriter.Write(emailbox.Text)
            objWriter.Close()
            MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist")
        End If
    End Sub
End Class 


its working just how i want it to.


but the output, i want to know how to put dashes or a few dashes inbetween the inputs of the textboxs, so that i can easily tell what it reads... how can i do this??

this is what it looks like.. right now...

Posted Image

also, i am not able to run the program unless i already have the file test.txt in my C: drive.

how can i make it to where the program automatically creates the file, and names it what i want to name it. for example: when the program launches, it asks me in a pop up msg box "what do you want to name this file." then i enter "oakland" then it goes to main screen, and i enter in all my inputs in the textboxes, write to file with my button, and it names the file "oakland.txt"


im sorry i am really trying my best to get this going.

This post has been edited by Atli: 30 January 2012 - 09:26 PM
Reason for edit:: Fixed the [code] tags.

Was This Post Helpful? 0
  • +
  • -

#4 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 30 January 2012 - 05:48 PM

okay, i just learned how to creat a msg box,

and this is the code i used.


Dim MsgBox1 = InputBox("What do you want to name the output file?", "OUTPUT FILE NAME", "FILE NAME HERE", 100, 100)



now how do i take the user input of that msg box and make it create a txt file using the name that was input by user.
Was This Post Helpful? 0
  • +
  • -

#5 trevster344   User is offline

  • The Peasant
  • member icon

Reputation: 225
  • View blog
  • Posts: 1,526
  • Joined: 16-March 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 30 January 2012 - 08:27 PM

View Postripgriggs, on 30 January 2012 - 06:48 PM, said:

okay, i just learned how to creat a msg box,

and this is the code i used.


Dim MsgBox1 = InputBox("What do you want to name the output file?", "OUTPUT FILE NAME", "FILE NAME HERE", 100, 100)



now how do i take the user input of that msg box and make it create a txt file using the name that was input by user.


First off that code is wrong. You declared Msgbox1 as what? If you want to get the value of the input box declare it properly. Once the user inputs whatever into the inputbox the variable you declared will contain the string typed. You've already created the textfile part haven't you? So tie it in. Don't forget to dispose of your objects.
Was This Post Helpful? 0
  • +
  • -

#6 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 31 January 2012 - 11:46 AM

well, I read your whole question again and I've put some code together to help you out from where your're stuck.
Mind you, I have very little experience working with Files in VB.NET. So there might be easier ways/shortcuts to accomplish some of the tasks I've done here. Anyway here it goes, I've commented the code so you can get an idea what it does.

Quote

i want to know how to put dashes or a few dashes inbetween the inputs of the textboxs, so that i can easily tell what it reads... how can i do this??


This is little tricky when it comes to writing data into a text file. You need to use control characters to do this. The problem is, the format of the document won't stay neatly due to the length of the data strings. It will go astray.

Quote

how can i make it to where the program automatically creates the file, and names it what i want to name it. for example: when the program launches, it asks me in a pop up msg box "what do you want to name this file." then i enter "oakland" then it goes to main screen, and i enter in all my inputs in the textboxes, write to file with my button, and it names the file "oakland.txt"


I've done this in the code below. Take a look at it.


'must import these namespaces to access methods for file operations
Imports System
Imports System.IO
Imports System.Text

Public Class frmLogger

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click

        'declare variables to hold the header details and the filename
        Dim loadOrigin, destination, filename As String

        'inputboxes take user input for the header
        loadOrigin = InputBox("Where is the Load Origin?", "Origin")
        destination = InputBox("Where is the Destination?", "Destination")

        'takes the name the user wants to name the file to a variable
        filename = InputBox("What's the text file name?", "File Name")

        'concatanates the file name with the file path. Change the path to your liking.
        Dim path As String = "D:\" + 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 objWriter As New System.IO.StreamWriter(path)

			'The "Trim" method removes all unnecessary space characters from the beginning and end of the textbox field.
			'The "&" operator is used to concat 2 strings together.
			'The "vbTab" and "vbCrLf" are called Control Characters. Simply vbTab = a Tab space, vbCrLf = Newline
			'I've shared links to some external reading resources which may help to better understand these things. 
            objWriter.Write("Origin : " & Trim(loadOrigin) & vbTab & "-" & vbTab)
            objWriter.Write("Destination : " & Trim(destination) & vbTab & vbCrLf & vbCrLf)

            objWriter.Write(Trim(txtCarrier.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtLocation.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtDest.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtQuote.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtPhone.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtFax.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtEmail.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(dtpDate.Value.ToString("dd/mm/yyyy")) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtNotes.Text) & vbTab)

            objWriter.Close()
            MessageBox.Show("Text written to file", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
            clearFields()	'calls the function to clear textboxes after data has been saved
        End If
		
    End Sub


    Public Function clearFields() As Integer
	
		'created a function to clear out fields
        txtCarrier.Text = ""
        txtLocation.Text = ""
        txtDest.Text = ""
        txtQuote.Text = ""
        txtPhone.Text = ""
        txtFax.Text = ""
        txtEmail.Text = ""
        dtpDate.Value = Date.Today
        txtNotes.Text = ""

    End Function

End Class


I've only tried to answer the questions you've asked the last time. This code, creates a text file with the name you give and writes the data you provide. But it won't do it multiple times. To be honest, I don't know how to write data to a file multiple times as of now. I will look into it and let you know once I get a grasp of this. In the meantime, keep up with your work. Good luck!
Here are the links,

Control Characters

Trim Method

VB.NET Operators

EDIT :
I've used the control DateTimePicker to set the time. Using a textbox to do that is not ideal.
Posted Image

This post has been edited by nK0de: 31 January 2012 - 11:57 AM

Was This Post Helpful? 1
  • +
  • -

#7 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 01 February 2012 - 02:24 PM

View PostnK0de, on 31 January 2012 - 11:46 AM, said:

well, I read your whole question again and I've put some code together to help you out from where your're stuck.
Mind you, I have very little experience working with Files in VB.NET. So there might be easier ways/shortcuts to accomplish some of the tasks I've done here. Anyway here it goes, I've commented the code so you can get an idea what it does.

Quote

i want to know how to put dashes or a few dashes inbetween the inputs of the textboxs, so that i can easily tell what it reads... how can i do this??


This is little tricky when it comes to writing data into a text file. You need to use control characters to do this. The problem is, the format of the document won't stay neatly due to the length of the data strings. It will go astray.

Quote

how can i make it to where the program automatically creates the file, and names it what i want to name it. for example: when the program launches, it asks me in a pop up msg box "what do you want to name this file." then i enter "oakland" then it goes to main screen, and i enter in all my inputs in the textboxes, write to file with my button, and it names the file "oakland.txt"


I've done this in the code below. Take a look at it.


'must import these namespaces to access methods for file operations
Imports System
Imports System.IO
Imports System.Text

Public Class frmLogger

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click

        'declare variables to hold the header details and the filename
        Dim loadOrigin, destination, filename As String

        'inputboxes take user input for the header
        loadOrigin = InputBox("Where is the Load Origin?", "Origin")
        destination = InputBox("Where is the Destination?", "Destination")

        'takes the name the user wants to name the file to a variable
        filename = InputBox("What's the text file name?", "File Name")

        'concatanates the file name with the file path. Change the path to your liking.
        Dim path As String = "D:\" + 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 objWriter As New System.IO.StreamWriter(path)

			'The "Trim" method removes all unnecessary space characters from the beginning and end of the textbox field.
			'The "&" operator is used to concat 2 strings together.
			'The "vbTab" and "vbCrLf" are called Control Characters. Simply vbTab = a Tab space, vbCrLf = Newline
			'I've shared links to some external reading resources which may help to better understand these things. 
            objWriter.Write("Origin : " & Trim(loadOrigin) & vbTab & "-" & vbTab)
            objWriter.Write("Destination : " & Trim(destination) & vbTab & vbCrLf & vbCrLf)

            objWriter.Write(Trim(txtCarrier.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtLocation.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtDest.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtQuote.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtPhone.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtFax.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtEmail.Text) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(dtpDate.Value.ToString("dd/mm/yyyy")) & vbTab & "-" & vbTab)
            objWriter.Write(Trim(txtNotes.Text) & vbTab)

            objWriter.Close()
            MessageBox.Show("Text written to file", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
            clearFields()	'calls the function to clear textboxes after data has been saved
        End If
		
    End Sub


    Public Function clearFields() As Integer
	
		'created a function to clear out fields
        txtCarrier.Text = ""
        txtLocation.Text = ""
        txtDest.Text = ""
        txtQuote.Text = ""
        txtPhone.Text = ""
        txtFax.Text = ""
        txtEmail.Text = ""
        dtpDate.Value = Date.Today
        txtNotes.Text = ""

    End Function

End Class


I've only tried to answer the questions you've asked the last time. This code, creates a text file with the name you give and writes the data you provide. But it won't do it multiple times. To be honest, I don't know how to write data to a file multiple times as of now. I will look into it and let you know once I get a grasp of this. In the meantime, keep up with your work. Good luck!
Here are the links,

Control Characters

Trim Method

VB.NET Operators

EDIT :
I've used the control DateTimePicker to set the time. Using a textbox to do that is not ideal.
Posted Image



amazing, i have been busy since yesterday, and i just got into this right now. I will let you know how it works out =)

thanks man.
Was This Post Helpful? 0
  • +
  • -

#8 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 01 February 2012 - 03:17 PM

okay man, i just want to say thanks again

and that works great. the way it is formatted to look on the txt file looks great also.

how would i make it to where it only asks for the load origin and destination 1 time?
and when it clears the fields, and i input more data, it will append the already made txt file, and add the new entry underneath the first one.

and i can keep that application open, and i will be able to add new entries throughout the day.



and if there is another load with a different load origin and destination, then i will just open a second instance of the application. and start a new one.

does that make sense?

thanks a million in advance.
Was This Post Helpful? 0
  • +
  • -

#9 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 05 February 2012 - 01:49 AM

no problem :) okay, I did some changes in the code. To make the program ask the load origin and the destination only one time, you put that code inside the Form's Load event. So you'll get those inputboxes only when the application starts.

Imports System
Imports System.IO
Imports System.Text
Imports System.Windows.Forms

Public Class frmLogger
	
	Dim loadOrigin, destination, notes, filename, path As String
	Dim flag As Boolean = False
	
	Private Sub frmLogger_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        loadOrigin = InputBox("Where is the Load Origin?", "Origin")
        destination = InputBox("Where is the Destination?", "Destination")
        filename = InputBox("What's the text file name?", "File Name")

        path = "D:\" + filename + ".txt"

        If File.Exists(path) Then
            MessageBox.Show("File already exists", "File Exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Me.Close()  'the program closes if the file already exists
        Else
            Dim fs As FileStream = File.Create(path)
            fs.Dispose()
        End If

        disableBoxes()  'a function to disable textboxes until the user press the New button.

    End Sub
	
End Class


And appending more data to the existing file is easier than I thought. You just have to set the StreamWriter's second constructor parameter as True like this.

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        If Not File.Exists(path) Then
            MessageBox.Show("File doesn't exist in the given path", "No File", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        Else
			'this is that second constructor parameter. If its set to True, the new data get appended to the existing data. 
			'If it's set to False, it overwrites the existing file.
            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(txtCarrier.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtLocation.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtDest.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtQuote.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtPhone.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtFax.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtEmail.Text) & vbTab & "-" & vbTab)
            writer.Write(Trim(dtpDate.Value.Date.ToString("MM/dd/yyyy")) & vbTab & "-" & vbTab)
            writer.Write(Trim(txtNotes.Text) & vbTab & vbCrLf & vbCrLf)

            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.
            disableBoxes()

        End If

    End Sub



And yes, you can open up multiple instances of the program with different filenames and enter data to them.

This is the UI of what I ended up with.

Posted Image

Mind you, there's a lot to be done, like validating user input. (ex : only entering numbers for phone number) I'll leave them to you. Sorry about my crappy explanations. I suck at it.

oh and a couple of little suggestions, I think you might learn about working with databases in your class in the future. I suggest you think about connecting this application to a database. That way you can store data in an organized way, take proper reports, track your progress and do a lot more.

And look into the TabControl control in the VS Toolbox (its under the Containers catagory). I ahve a feeling that you can use that to make this app more efficient and easy to use rather than opening up multiple instances all over the desktop.

Good Luck!
Was This Post Helpful? 1
  • +
  • -

#10 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 09:12 AM

thank you very much for the help,

i am so close, but i can not figure out how to get rid of these darn erros,

can you help me?


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, notes, filename, path As String
        Dim flag As Boolean = False

        loadOrigin = InputBox("Where is the Load Origin?", "Origin")
        destination = InputBox("Where is the Destination?", "Destination")
        [b]deliverDate[/b] = InputBox("What is the delivery date?")
        filename = InputBox("What's the text file name?", "File Name")

        path = "C:\" + filename + ".txt"




        If Not File.Exists(path) Then
            MessageBox.Show("File doesn't exist in the given path", "No File", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        Else
            'this is that second constructor parameter. If its set to True, the new data get appended to the existing data. 
            'If it's set to False, it overwrites the existing file.
            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([b]deliverDate[/b]) & 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.
            [b]disableBoxes[/b]()

        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




these errors


Error 1 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 2 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 3 'disableBoxes' is not declared. It may be inaccessible due to its protection level.
Was This Post Helpful? 0
  • +
  • -

#11 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 09:24 AM

i tried to bold the errors in the code box, but it did not work. ignore those.
Was This Post Helpful? 0
  • +
  • -

#12 trevster344   User is offline

  • The Peasant
  • member icon

Reputation: 225
  • View blog
  • Posts: 1,526
  • Joined: 16-March 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 09:25 AM

Look in your code did you declare any of those variables anywhere? I don't think so bud. If you did they are to limited a scope for the compiler to find and cannot be accessed as a result pretty straight forward.
Was This Post Helpful? 0
  • +
  • -

#13 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 09:35 AM

View Postripgriggs, on 06 February 2012 - 09:42 PM, said:

Error 1 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 2 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 3 'disableBoxes' is not declared. It may be inaccessible due to its protection level.


The error means you haven't declared those variables in your code. This is how you do it.

Dim variableName As dataType


You must declare the variables before using them in your code.

And disableBoxes is just a simple function I told you to write to disable Textboxes. See the clearFields() function? take that as an example and write the disableBoxes() function. Use the .Enabled property.

This post has been edited by nK0de: 06 February 2012 - 09:37 AM

Was This Post Helpful? 1
  • +
  • -

#14 ripgriggs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-January 12

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 10:38 AM

View PostnK0de, on 06 February 2012 - 09:35 AM, said:

View Postripgriggs, on 06 February 2012 - 09:42 PM, said:

Error 1 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 2 'deliverDate' is not declared. It may be inaccessible due to its protection level.

Error 3 'disableBoxes' is not declared. It may be inaccessible due to its protection level.


The error means you haven't declared those variables in your code. This is how you do it.

Dim variableName As dataType


You must declare the variables before using them in your code.

And disableBoxes is just a simple function I told you to write to disable Textboxes. See the clearFields() function? take that as an example and write the disableBoxes() function. Use the .Enabled property.




i am not sure what you mean about the disable boxes
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.
            MessageBox.Show("Text written to file", "Data Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
            disableBoxes()



thats what i tried?? did not work...


also, when i take the disable boxes out of the code, and try to the program to see if it works, it works perfect... but it re asks me for the info via msg box and wants to rename the the file again.. (instead of asking once)

what did i do wrong?

thanks in advance again!

=)
Was This Post Helpful? 0
  • +
  • -

#15 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Multiple Text Boxes - Write to txt File on Same Line + More.

Posted 06 February 2012 - 10:47 AM

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.

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.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2