dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 4 123 ... LastLast
Results 1 to 15 of 50

Thread: How to export data from forms to *.txt file

  1. #1
    Join Date
    Jul 2005
    Posts
    50

    Question How to export data from forms to *.txt file

    Hello, I just got VB6 and i am very excited about creating programs, but i have came uppon a small problem that I don't know how to fix. I want to create a program that exports data from text boxes (forms) to a .txt file so that it will create a script for a game named quake 3. I was wondering if anyone could help me with my problem?


  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    See if this helps:
    http://www.vbexplorer.com/VBExplorer.../faq_060298_ht

    You'll find the answers to several other frequently-asked VB questions here:
    http://www.vbexplorer.com/VBExplorer/faq.asp
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jul 2005
    Posts
    50

    Question Missing Info

    I understand the code that makes the function, but how do you make the code be activated by a Command Button?


  4. #4
    Join Date
    Jul 2005
    Posts
    19
    Private Sub Command1_Click()
    RichTextBox1.SaveFile (App.Path + "\" + "txt.txt")
    End Sub

    add RichTextBox in your components

  5. #5
    Join Date
    Jul 2005
    Posts
    50

    Question Still....

    I got it to create the text file, but the data isnt in it, what do i do?

    Last edited by thphaca; 07-17-2005 at 11:46 PM.

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    In the Visual Basic form designer, double-click on the button you would like to save the file. The code editor will open to the button's Click event procedure. Copy and paste the file save code into that procedure.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    Jul 2005
    Posts
    9
    Private Sub drive_Change()
    ' sets the drive
    drvDir.Path = drive.drive

    End Sub

    Private Sub drvDir_Change()
    'sets the folder
    file.Path = drvDir.Path
    lblpath.Caption = drvDir.Path

    End Sub

    Private Sub file_DblClick()
    Dim Filepath As String

    lblpath.Caption = drvDir.Path

    If Right(lblpath.Caption, 1) = "\" Then 'sets the path of the file
    Filepath = lblpath.Caption + file.FileName
    Else
    Filepath = lblpath.Caption + "\" + file.FileName
    End If
    lblpath.Caption = Filepath

    End Sub

    Private Function loadfile() As String
    Dim InputData As String
    Dim Filepath As String

    Filepath = lblpath.Caption

    If ((StrComp(Filepath, "", vbTextCompare) <> 0) And (StrComp(Right(Filepath, 4), ".txt", vbTextCompare) = 0)) Then
    ' Vailded File Path

    Open Filepath For Input As #1 'Open file for input.

    Do While Not EOF(1) 'Check for end of file.
    Line Input #1, InputData 'Read line of data.

    loadfile = loadfile + Chr(13) + InputData
    Loop
    Close #1 'Close file.
    Else
    MsgBox "Invaild File, it must be a .txt File.", vbCritical, "File Path Error"
    loadfile = ""
    End If

    End Function

    i got that from a pdf file, good luck
    I'm a lost Kid

  8. #8
    Join Date
    Jul 2005
    Posts
    50

    Thumbs up

    Yes, I got it!!!!! All I had to do was delete some of the code that VB said was incorrect. Thank You All Very Much!!!!

    P.S. : Would it be possible to make it submit multiple text boxes to each line of the text file.

    Last edited by thphaca; 07-18-2005 at 02:18 PM.

  9. #9
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Would it be possible to make it submit multiple text boxes to each line of the text file?
    Yes, that's possible. Why don't you post the code you have now and we'll figure it out together.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  10. #10
    Join Date
    Jul 2005
    Posts
    50

    Question ?

    Sorry, but i am only 12 and i know only very little about visual basic. The only thing that I do know is the how to change the appearance of an object by clicking the same 1 or another object...


  11. #11
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You said you have it working with a single textbox, correct? Please post the code you have now in your button's click event.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  12. #12
    Join Date
    Jul 2005
    Posts
    50

    Post The Code

    oh, ok. I thought that you thought that I already had a multiple textbox submit code. Here it is:

    Private Sub cmdCommand1_Click()
    Dim iFB As Integer

    'Writing to the file:
    iFB = FreeFile
    Open "C:\q3config.cfg" For Output As #iFB
    Print #iFB, Text1.Text,
    Close iFB

    'Reading from the File:
    Dim sTmp1 As String, sTmp2 As String

    iFB = FreeFile
    Open "C:\q3config.cfg" For Input As #iFB
    Do While EOF(iFB) = False
    Line Input #iFB, sTmp1
    sTmp2 = sTmp2 & sTmp1 & vbCrLf
    Loop
    Close iFB
    End Sub

  13. #13
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    OK, first of all, I assume you only want to write to the file (not read from it) when the user clicks the command button, correct? If so, you may remove the "Reading from the file" code, so it becomes simply:
    Code:
    Private Sub cmdCommand1_Click()
        Dim iFB As Integer
    
        'Writing to the file:
        iFB = FreeFile
        Open "C:\q3config.cfg" For Output As #iFB
        Print #iFB, Text1.Text
        Close iFB
    End Sub
    Now, let's take one line at a time and figure out what it does:
    Code:
    ' Declare an Integer variable named iFB
    Dim iFB As Integer
    ' Get the next available file number and assign it to iFB
    iFB = FreeFile
    ' ...etc.
    Why don't you do the rest? Look up the relevant keywords (Open, For Output, Print #, Close) in VB's online help and post a reply explaining what each line of code does.

    Once you've done that, we'll figure out what to change to make the program write multiple textboxes to the file. :-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  14. #14
    Join Date
    Jul 2005
    Posts
    50

    Lightbulb Definitions

    Ok. "Open For Input" means to give the file a certaint ID in the code. "Print #iFB, text1.text" where iFB is the file ID, and text1.text is the source for the data, means to copy the text that is in text1 and insert it into the file. And "Close #iFB" means to "terminate" the action and end it.

    I understand the definitions, but how do I use "Print #iFB, text1.text" to make it print 1 line at a time from multiple text boxes.
    Last edited by thphaca; 07-18-2005 at 03:32 PM.

  15. #15
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Close. :-) You're actually opening the file For Output, which means you're going to write to the file (as opposed to For Input, which means you're going to read from it). Pop quiz: What does For Output do if the file does not exist? What if the file does exist?

    OK, so if "Print #iFB, text1.text" writes the contents of text1 to one line in the file, how would you write the contents of multiple textboxes to the file?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center