Results 1 to 9 of 9

Thread: Question with reading from txtfile

  1. #1
    mlink
    Guest

    Question with reading from txtfile

    Hi again, I am pretty sure this didn't post twice. Anyway, I have this program which I am supposed to make which requires me to write to a txt file then read it. Now I looked through the msg boards and found lots of things about this, however, nothing which is what i need exactly, or it was there and I just didn't understand it.

    I have 4 textboxes. One is name, Second is Artist, Third is Price and forth is path.

    I can get them all to work except the price which always shows up as 0 in the textbox.

    My real problem is with reading it. When i click my retrieve button it is supposed to hide the first form and open a second one which is exactly alike except for no path textbox or save. I need the information which is printed into the textbox to go into the corresponding textboxes in the 2nd form. In the first form I have a save button which writes to the file, it can save multiple times and what I need as well is when it is saved multiple times I can click retrieve for the next form then on that form click another button called retrieve next which would give me the info on the 2nd line and put it in the corresponding textboxes.

    My code for the write is below, I don't have any for retrieve yet except just hiding and showing the forms. I tried a few ways from reading the msg board but none would work how I need them.

    Anyhelp would be great
    Thanks

    Code:
    Private Sub cmdSave_Click()
    Dim strTitle As String
    Dim strArtist As String
    Dim curPrice As Currency
    
    strTitle = txtTitle.Text
    strArtist = txtArtist.Text
    curPrice = Val(curPrice)
    
    Dim ff&
     ff = FreeFile
      Open "h:\test.txt" For Append As #ff
        Write #ff, strTitle, strArtist, curPrice
         Close #ff
    
    
    txtTitle = ""
    txtArtist = ""
    txtPrice = ""
    End Sub

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    Try this


    Code:
    Private Sub cmdSave_Click()
    Dim strTitle As String
    Dim strArtist As String
    Dim curPrice As Currency
    
    strTitle = txtTitle.Text
    strArtist = txtArtist.Text
    curPrice = Val(curPrice)
    
    Dim ff&
     ff = FreeFile
      Open "h:\test.txt" For Append As #ff
    
        *Write #ff, strTitle, strArtist, curPrice
         Print #ff, strTitle, strArtist, curPrice
    
         Close #ff
    
    
    txtTitle = ""
    txtArtist = ""
    txtPrice = ""
    End Sub
    this is working on my prog.

  3. #3
    mlink
    Guest

    erm

    tried that, it didn't work though, it just took away the quotations
    and commas in the text lines and put a big space between the artist text and price.

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    since you're saving it to a text file, I would just change the currency to a string. What I mean is declare it as a string. You can change it to currency if you need to in the program by having a second variable.

    VB Code:
    1. 'Declarations
    2.  
    3. dim curPrice as currency
    4.  
    5. Sub Whatever
    6. dim sCur as string
    7.  
    8. ''''''.......................
    9.  
    10.     get #1, sCur
    11.  
    12. close #1
    13.  
    14. ' I'm not sure if this is right since I don't ever work with
    15. ' currency, but you get the idea
    16.  
    17. curPrice=CCur(sCur)
    18.  
    19. End Sub

  5. #5
    mlink
    Guest
    thanks i'll try that, anyone have suggestions on how i could do the Retrieve part of the program?

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Heres a place to start:

    Bruce.
    Attached Files Attached Files
    Last edited by Bruce Fox; Apr 16th, 2002 at 11:19 PM.

  7. #7
    mlink
    Guest

    Thanks Bruce :)

    Thanks a ton

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    No Pobs,

    Remember its just the basics, u will need some code to check
    for things like:
    File empty, File dosn't exist etc.
    And ull need to fiddle with the Currency.


    Good Luck
    Last edited by Bruce Fox; Apr 17th, 2002 at 01:25 AM.

  9. #9
    Member
    Join Date
    Jan 2002
    Location
    Southern Oregon
    Posts
    38
    Could it be your not assigning a value to curPrice?

    strTitle = txtTitle.Text
    strArtist = txtArtist.Text
    curPrice = Val(curPrice)

    As shown above curPrice will be 0.

    try;
    strTitle = txtTitle.Text
    strArtist = txtArtist.Text
    curPrice = txtPrice.Text

    I would also use a string datatype for curPrice then just format when needed.
    Format(curPrice, "Currency")

    Chuck

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