Results 1 to 5 of 5

Thread: Got code, and i need to turn it into a loop

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    Dim LineNumber as interger
    Dim lngCOUNT as interger
    Dim sFirst

    LineNumber = 1
    Dowhile LineNumber < lngCOUNT
    open "C:\datain.dat" for input as #1
    Line input #1, sFirst
    Label1.caption = sFirst
    Close #1
    LineNumber = LineNumber + 1
    EndDo

    what i am doing is opening the dat file taking the first line and putting it in label1.caption....., 2nd line in label2.caption...or better yet to fix that problem attact it to a label? argh see my problems? hehe....well instead of a bunch of code each line trying to creat a loop any help? lngCOUNT is the total of lines that i did from a search earlier in the program.
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Use a control array, that would be best.

    Otherwise, you can refer to a control as follows:

    FormName("ControlName").Property

    So it'd be:
    Code:
    Dim i As Long 
    i = 1
    Open "C:\datain.dat" For Input As #1 
    Do While i < lngCOUNT 
        Line Input #1, strLine
        Me("Label" & i).Caption = strLine
        i = i + 1 
    Loop
    Close #1

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'if I have guessed your question properly, try this
    
    'Add a bas module code and add this code
    Option Explicit
    
    Public myArr
    
    'On a form add a command button Command1
    'Add a lablel, Label1 and set it's index to 0
    'then run this code
    
    Option Explicit
    
    Private Sub command1_Click()
    
    Dim LineNumber As Integer
    
    Open "C:\datain.dat" For Input As #1
    
    Do While Not EOF(1)
        ReDim Preserve myArr(LineNumber)
        Line Input #1, myArr(LineNumber)
        LineNumber = LineNumber + 1
    Loop
    
    Call AddLabel(UBound(myArr))
    
    
    End Sub
    
    Public Sub AddLabel(intCount As Integer)
    
       Label1(0).Caption = myArr(0)
       Dim i
       For i = 1 To intCount
        Load Label1(i)     ' Create new button.
        Label1(i).Top = Label1(i - 1).Top + 400
        Label1(i).Visible = True  ' Display new                                 ' button.
        Label1(i).Width = 4000
        Label1(i).Caption = myArr(i)
       Next i
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    New Member
    Join Date
    Nov 2000
    Posts
    8
    Well, you could use a control array for the lables and then just don't close the text file during the loop and get the next line.

    Code:
    Dim lngCOUNT As Long
    Dim sFirst As String
    dim i As Long 'How big can lngCount Get?
    open "C:\datain.dat" for input as #1 
    
    for i = 1 to lngcount
       Line input #1, sFirst 'Line Input # will go to the next line automatically
       Label1(i-1).caption = sFirst 'Control arrays are 0 based
    Next i
    
    Close #1

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    hehe

    Thanks a lot guys, I'll give it a shot when I get home.
    -RaY
    VB .Net 2010 (Ultimate)

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