Simple with simple program
Hi All,
New to the forum so hello all.
I'm creating a VB program to do the following:
I need a simple form with multiple data entry boxes and yes/no tick boxes. At the end I need it so spit out a .csv file containing what has been entered on the form.
I'm new to VB so any help would be great.
Thanks
Re: Simple with simple program
what have you got so far?
Re: Simple with simple program
I've got an example for you, but like westconn1 says, whatch got now?
Basically you want to write to a file with commas inserted between the 'values' of your textboxes, I assume. And that may be contingnent upon what the CHECKboxes (not tick boxes) show (either checked or not checked).
You can use variables for each of the textbox text value, or just include the textbox1.text (etc) in your write statement.
if you use writeline, it would be like this: XXXX.writeline (text1.text & "," & text2.text &"," & text3.text), where XXXX is a filesystemobject created .csv file. You would do that for each line you wanted to export.
SO, whatch got so far?
Re: Simple with simple program
I would advise not using the filesystem object [FSO]
Instead I would advise to use the native BASIC functions that are designed for this. Namely Print #FileNumber Or Write #FileNumber depending on the desired output
Re: Simple with simple program
Thanks for the response guys
Basically I've designed the form with text boxes and labels. I just need the code for the button to export a file.
So far I have:
WriteLine(TextBox1.ToString + "," & TextBox2.ToString + "," + TextBox3.ToString.ToString)
I just need the code that will export a .csv file with the filename of "<TextBox1 TextBox2>.csv" into "C:\".
Once I have this I will be building a lot more to it hopefully.
Thanks
Re: Simple with simple program
Looks like you are writing VB.Net code so the stuff thus far does not really apply
Is that the only line you have or do you have more?
What method are you using to open the file?
Code:
Dim OutFile as New System.IO.StreamWriter("c:\" & textbox1.Text & TextBox2.Text &".csv",True)
OutFile.Writeline(Textbox1.Text & "," & Textbox2.Text & "," & Textbox3.Text)
OutFile.Close
The true flag on the first line above tells the stream writer to create the file if it does not exist or if it does exist that it should append to the end of the existing file.
Re: Simple with simple program
Moved to the VB.Net forum.
Re: Simple with simple program
Thanks DATAMISER
Once the file is output it is to be used in another program.
I get the following error when I use the code you gave me:
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
any ideas?
Cheers
Re: Simple with simple program
Quote:
Originally Posted by
TJJC88
Thanks DATAMISER
Once the file is output it is to be used in another program.
I get the following error when I use the code you gave me:
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
any ideas?
Cheers
Just changed the destination and it works, cheers!
Re: Simple with simple program
I want to include some tick boxes instead of text boxes on my form:
So when the CheckBox1.checked I want it to return "Y" in my writeline. any ideas?
Thanks
Re: Simple with simple program
Usually when I am writing lines of data to a file that are made up of a few different things I use a variable to hold what I want to write, add the stuff to that variable then write the variable contents with write line.
Code:
Dim strLine as string=""
strLine=Textbox1.Text & ","
strLine &= Textbox2.Text & ","
strLine &= Textbox3.Text
OutFile.Writeline(strLine)
In the case of your last question you just need to use an IF statement to test the value of the combo box and then if it is checked add the Y into your line at the proper point.
Re: Simple with simple program
Quote:
Originally Posted by
DataMiser
Usually when I am writing lines of data to a file that are made up of a few different things I use a variable to hold what I want to write, add the stuff to that variable then write the variable contents with write line.
Code:
Dim strLine as string=""
strLine=Textbox1.Text & ","
strLine &= Textbox2.Text & ","
strLine &= Textbox3.Text
OutFile.Writeline(strLine)
In the case of your last question you just need to use an IF statement to test the value of the combo box and then if it is checked add the Y into your line at the proper point.
Thanks that is a better method, this is coming together nicely now.
I need to output a 6 digit unique reference which is generated when the file is exported bearing in mind that this program will be used on multiple PCS/Users. this number can not be duplicated in the future. So I'm assuming this needs to look at a global list of numbers but not sure how to do this?
Thanks