Results 1 to 13 of 13

Thread: newbie xtreme

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    US uv A
    Posts
    14

    newbie xtreme

    hey..nice site...
    now I know this may be "basic" stuff but....
    i wanna know if this code could be shortened or made more efficient? >>
    Private Sub Form_Load()
    Dim x As String
    Open "artist.txt" For Append As #1
    Open "song.txt" For Append As #2
    Open "album.txt" For Append As #3
    Open "genre.txt" For Append As #4
    Close #1
    Close #2
    Close #3
    Close #4

    Open "artist.txt" For Input As #1
    Do While Not EOF(1)
    Input #1, x
    lstArtist.AddItem x
    Loop
    Close #1
    Open "song.txt" For Input As #1
    Do While Not EOF(1)
    Input #1, x
    lstSong.AddItem x
    Loop
    Close #1
    Open "album.txt" For Input As #1
    Do While Not EOF(1)
    Input #1, x
    lstAlbum.AddItem x
    Loop
    Close #1
    Open "genre.txt" For Input As #1
    Do While Not EOF(1)
    Input #1, x
    lstGenre.AddItem x
    Loop
    Close #1

    End Sub
    thx! ;-)

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Open "artist.txt" For Append As #1
    2. Open "song.txt" For Append As #2
    3. Open "album.txt" For Append As #3
    4. Open "genre.txt" For Append As #4
    5. Close #1
    6. Close #2
    7. Close #3
    8. Close #4

    ?
    -= a peet post =-

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    well right off the top.. whats this for?

    Open "artist.txt" For Append As #1
    Open "song.txt" For Append As #2
    Open "album.txt" For Append As #3
    Open "genre.txt" For Append As #4
    Close #1
    Close #2
    Close #3
    Close #4

    youre not doing anything here?


    as for the rest...if the files arent to big..that code should be fine

    you could grab the whole file then split it and add to the listbox...but stick with what you have for now.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by geoff_xrx
    well right off the top.. whats this for?

    Open "artist.txt" For Append As #1
    Open "song.txt" For Append As #2
    Open "album.txt" For Append As #3
    Open "genre.txt" For Append As #4
    Close #1
    Close #2
    Close #3
    Close #4
    I think it's just there to make sure the file exist before opening it For Input.

  5. #5
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    If that's the case...
    Use this function

    Code:
    Public Function FileExists(ByVal FileName As String) As Boolean
        If Dir(FileName) = "" Then
            FileExists = False
        Else
            FileExists = True
        End If
    End Function
    Then you call it by going like this

    Code:
    if FileExists("C:\text.txt") then
         msgbox "File exists"
    else
         msgbox "File does not exist"
    end if

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Joacim Andersson...

    fine Mr."smartie who is actually 'awake' this early"



    lol
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by geoff_xrx
    Joacim Andersson...

    fine Mr."smartie who is actually 'awake' this early"



    lol
    Well actually since I live in Sweden the time here is 3:15 PM so I should be awake.

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    See told you Im not awake...didnt even notice youre in Sweeden!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by geoff_xrx
    See told you Im not awake...didnt even notice youre in Sweeden!
    Hmmm... well I'm awake and I notice that you're in Rochesteeer

  10. #10
    Lively Member FRAIL_KNIGHT's Avatar
    Join Date
    Nov 2001
    Posts
    100
    I don't think you need the open for appends...

    I thought "input" created files if they aren't there, just like "append"



    ---------------------------------------------------------
    Calling someone an I.D.Ten.T. is MEAN!!!!!!!!

    I.D.Ten.T.
    ID10T
    IDIOT

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by FRAIL_KNIGHT
    I don't think you need the open for appends...

    I thought "input" created files if they aren't there, just like "append"
    No, opening a file for Append or Output creates the file if it doesn't exist but trying to open a non-existing file for Input raises an error.

  12. #12
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    Well, I'm at work, I have to be awake.

    Anyway. You don't need to create the files.

    Check to see if it exists before creating it, and what the hell is there to input if it doesn't exist? Validity checking is the solution here, not wasting time making empty files and reading in nothing.

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Location
    US uv A
    Posts
    14
    Originally posted by Joacim Andersson
    I think it's just there to make sure the file exist before opening it For Input.
    thas is correct...
    btw...wow!...thx for responses guyz... I just got a chance to come to the forum to see it....thx!

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