-
Feb 13th, 2013, 03:01 PM
#1
Thread Starter
New Member
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
-
Feb 13th, 2013, 03:18 PM
#2
Re: Simple with simple program
what have you got so far?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 13th, 2013, 04:34 PM
#3
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?
-
Feb 13th, 2013, 05:30 PM
#4
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
-
Feb 13th, 2013, 06:57 PM
#5
Thread Starter
New Member
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
-
Feb 14th, 2013, 12:22 AM
#6
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.
Last edited by DataMiser; Feb 14th, 2013 at 02:34 AM.
-
Feb 14th, 2013, 01:02 AM
#7
Re: Simple with simple program
Moved to the VB.Net forum.
-
Feb 14th, 2013, 05:19 AM
#8
Thread Starter
New Member
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
-
Feb 14th, 2013, 07:21 AM
#9
Thread Starter
New Member
Re: Simple with simple program
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!
-
Feb 14th, 2013, 07:55 AM
#10
Thread Starter
New Member
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
-
Feb 14th, 2013, 11:27 AM
#11
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.
-
Feb 15th, 2013, 08:01 AM
#12
Thread Starter
New Member
Re: Simple with simple program
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|