CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    126

    Problem with reading txt file

    Hi.
    i have a problem when I read from a txt file.
    I looks something like this:
    Spa
    1,216
    1,081

    And now when I put the data into strings, the values are:
    Spa
    1
    216

    Why does it stop at the " , " ?
    I don't wan't it to stop at the ","

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Problem with reading txt file

    Because , is a field-delimiter in VB6, not a decimal separator.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2009
    Posts
    126

    Re: Problem with reading txt file

    Ok, but I have now solved the problem, I changed , to .
    But there is a new problem now, if the number is below 1 ex: 0.9
    Then it only shows 9.
    How do I solve this problem?

  4. #4
    Join Date
    Dec 2007
    Posts
    234

    Re: Problem with reading txt file

    We're not mind readers... if you post the code you are using we may be able to help.

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Problem with reading txt file

    instead of using input to get the data use line input that will read the entire line and not break at the comma
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    May 2010
    Posts
    2

    Thumbs up Re: Problem with reading txt file

    Hi,


    I don't know how you are reading text file.
    But try this one.


    <Code>

    Option Explicit

    Private Sub Form_Load()
    Call ReadFormFile("C:\Test.txt")
    End Sub


    Rem Read data from file using Sequentila file handling
    Public Function ReadFormFile(strFilePath As String) As Boolean
    Dim tempString As String

    Rem Open text file
    Open strFilePath For Input As #1

    Rem Read line by line
    While EOF(1) = 0
    Line Input #1, tempString
    MsgBox tempString
    Wend

    Rem Close text file
    Close #1
    End Function

    </Code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured