dcsimg
Results 1 to 13 of 13

Thread: Wrong text in .TxT file

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Wrong text in .TxT file

    I have a programm most i get help from here and copy a part en write a little part.

    Wat goes wrong.

    I want some text in a TxT file
    I have option to fill in each one write seperated with the | (The part on the \ key with shift)

    Example fill in: text = Hello, text2 = how are, ans text3 = you
    I press a button to save and it must be:
    Hello|how are|you

    And i get:
    Hello |how are | you

    I dont know how te get the spaces between gone


    What is wrong?

    Private Sub Command1_Click()
    On Error Resume Next
    Dim Filenum As Integer
    Dim fname As String
    Filenum = FreeFile
    Open "C:\game\Game list.txt" For Append As Filenum
    Print #Filenum, Text1.Text, "|", Text2.Text, "|", Text3.Text
    fname = "txt"
    Close Filenum
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    375

    Re: Wrong text in .TxT file

    The commas in between the values is causing the spaces to appear.

    Try the below print command instead:

    Code:
    Print #Filenum, Text1.Text & "|" & Text2.Text & "|" & Text3.Text

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Re: Wrong text in .TxT file

    Thanks, You fix't it..

  4. #4
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,137

    Re: Wrong text in .TxT file

    ... or use semicolons ( instead of the commas(,).

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Re: Wrong text in .TxT file

    Thanks..

    Can you help me with another "problem"

    i fill in in Text1.text a path and filename example "c:\test.exe"

    This is no problem..

    Bud what i realy like is a button and goto the disk (c:\) search the file and bij clikking or pressing ok that this is automatic the text1.txt.
    Is this posible?

  6. #6
    Junior Member
    Join Date
    Jan 2018
    Posts
    21

    Re: Wrong text in .TxT file

    Quote Originally Posted by JTvD View Post
    Thanks..

    Can you help me with another "problem"

    i fill in in Text1.text a path and filename example "c:\test.exe"

    This is no problem..

    Bud what i realy like is a button and goto the disk (c:\) search the file and bij clikking or pressing ok that this is automatic the text1.txt.
    Is this posible?
    explain again please?!
    Eng.27

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Re: Wrong text in .TxT file

    I'll try

    In a text box Text1.Text i fil in a file start path.
    Example: c:\test\test.exe
    This i save in a filepath.txt file.. it's for a programm
    Bud a error is easy to type.

    When by pressing a button and search on the harddisk for the file c:\test\test.exe.
    When found press the ok and the path is automatic Text1.Text= "c\test\test.exe"

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Re: Wrong text in .TxT file

    Example:

    Button command1

    Text1.text = ""
    Open filedialog
    Search on harddisk for file.
    By finding the file
    Text1.text = "the filename"

  9. #9
    Junior Member
    Join Date
    Jan 2018
    Posts
    21

    Re: Wrong text in .TxT file

    Quote Originally Posted by JTvD View Post
    Example:

    Button command1

    Text1.text = ""
    Open filedialog
    Search on harddisk for file.
    By finding the file
    Text1.text = "the filename"
    look, I have a problem in explaining in English (so I feel now what people thought when reading what I explain in posts)
    back to your problem, I have not understand! you can not make the file you need? or you can not find it after you succeed to make it??
    Eng.27

  10. #10
    Junior Member
    Join Date
    Jan 2018
    Posts
    21

    Re: Wrong text in .TxT file

    wait a moment
    do you mean that when you press on Command1 and CommonDialog1 Appears, then browsing for the file you want, when you do those , you get the name of the file in Text1.text, NOT THE PATH OF THE FILE????
    Eng.27

  11. #11
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,528

    Re: Wrong text in .TxT file

    Add Microsoft Common Dialog control to your project from Project> Components... menu and use the following code

    Code:
    Private Sub Command1_Click()
        On Error GoTo OpenCancel
        
        With CommonDialog1
            .CancelError = True
            .InitDir = "C:\test\"
            .Filter = "All files (*.*)|*.*|Text (*.txt)|*.txt" ' add more filters if you want
            .ShowOpen
            Text1.Text = .FileName
        End With
        Exit Sub
    OpenCancel:
        ' Do nothing or show some message
        MsgBox "Cancel button has been pressed."
    End Sub



  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    62

    Re: Wrong text in .TxT file

    Thanks.. that was it.

    And sorry for my bad englisch..
    I have tried to translate it with Google translation but is is more bad than this.. (i hope)

  13. #13
    Junior Member
    Join Date
    Jan 2018
    Posts
    21

    Re: Wrong text in .TxT file

    Quote Originally Posted by JTvD View Post
    Thanks.. that was it.

    And sorry for my bad englisch..
    I have tried to translate it with Google translation but is is more bad than this.. (i hope)
    hhhhhhh, not bad as my English..
    Eng.27

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