Results 1 to 10 of 10

Thread: opening a file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21

    opening a file

    i am opening a file with 5 lines
    layed out in theis format
    "string", "string", number, number
    "string", "string", number, number
    "string", "string", number, number
    "string", "string", number, number
    "string", "string", number, number

    i only get the last line when i open it
    so it says this
    "string", "string", number number



    this is my code any problems with this?
    i have to rewrite to it also


    Open "a:\THRFILE.DAT" For Input As #1


    Do While Not EOF(1)
    Input #1, name
    Input #1, sex
    Input #1, dba
    Input #1, rest

    Loop

    Close #1

    txtView.Text = name + " " + sex + " " + dba + " " + rest

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Do While Not EOF(1)
    Input #1, name
    Input #1, sex
    Input #1, dba
    Input #1, rest

    Loop

    Close #1



    From above, it's apparent that you're assigning the variables with the proper values, but you're not doing anything with them. So, once the file reaches it's EOF... it's the final values that you're presented with.

    What are you trying to do with all 5 lines? 5 different textboxes? Plz elaborate

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    For one thing, you need to 'add' to the TextBox, like:
    VB Code:
    1. 'Set txtView.MultiLine = True (at build)
    2. txtView.Text = [b]txtView.Text[/b] + name + " " + sex + " " + dba + " " + rest + [b]vbCrLf[/b]

    Place it in the Loop.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    When you dim the name, sex, dba and rest
    Instead of this:

    Dim name ...
    use this
    Dim name() ...


    Also, changer 'name' to something else like 'theName'

    When you app starts, Dim all the vars with zero elements like this:
    ReDim theName(0)
    ReDim sex(0)
    ReDim dba(0)
    reDim rest(0)

    Finally, Change this:

    Do While Not EOF(1)
    Input #1, name
    Input #1, sex
    Input #1, dba
    Input #1, rest

    Loop

    To This:

    Do While Not EOF(1)
    reDim preserve thename(0 to UBound(name) + 1)
    reDim preserve sex(0 to UBound(name) + 1)
    reDim preserve dba(0 to UBound(name) + 1)
    reDim preserve rest(0 to UBound(name) + 1)
    Input #1, name(ubound(name))
    Input #1, sex(ubound(sex))
    Input #1, dba(ubound(dba))
    Input #1, rest(ubound(rest))

    Loop
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Then, to show in a text box:


    txtView.text = ""

    For LoopVar = LBound(name)+1 to UBound(name)

    txtView.Text = textview.text & name(loopvar) & " " & sex(loopvar) & " " & dba(loopvar) & " " & rest(loopvar) & vbcrlf

    Next
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  6. #6
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Hey Bruce, what app is that in your sig?
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Also, u can load multi-variables on the one line like:
    VB Code:
    1. Do While Not EOF(1)
    2.       Input #1, name, sex, dba, rest
    3.       txtView.Text = txtView.Text + name + " " + sex + " " + dba + " " + rest + vbCrLf
    4.    Loop
    5.  
    6.    Close #1


    Lord_Rat: Thats my Intel(R) Active Monitor app that came on the CD
    for the MotherBoard. Nice little app too - monitors Temps, Power etc


    Bruce.

  8. #8
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Looked it up and it's specific to Intel boards. Oh well.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Theres probably heaps of freeware stuff like that out there.

    Anyways, I guess u could knock something similar up in VB

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21
    ok i have it all in a subprocedure and it opens now thanks
    but i have to perform a calculation on dba and rest
    it s giving me a type mismatch error

    txtView.Text = txtView.Text + name + " " + sex + " " + dba + " " + rest + vbCrLf


    I dimmed it the same where it is called so Im a little lost
    Private Sub Spot(name As String, sex As String, dba As Integer, rest As Integer)

    txtView.Text = ""
    txtView.Enabled = True


    Open "a:\THRFILE.DAT" For Input As #1


    Do While Not EOF(1)
    Input #1, name
    Input #1, sex
    Input #1, dba
    Input #1, rest

    txtView.Text = txtView.Text + name + " " + sex + " " + dba + " " + rest + vbCrLf
    Loop

    Close #1

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