Simple with simple program-VBForums
Results 1 to 12 of 12

Thread: Simple with simple program

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,947

    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

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    3,656

    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?

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,118

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    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

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,118

    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 01:34 AM.

  7. #7
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,454

    Re: Simple with simple program

    Moved to the VB.Net forum.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: Simple with simple program

    Quote Originally Posted by TJJC88 View Post
    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!

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    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

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,118

    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.

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: Simple with simple program

    Quote Originally Posted by DataMiser View Post
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.