Reversing a Text List for use in combo box?

Discussion in 'AutoCAD' started by pkirill, Apr 14, 2004.

  1. pkirill

    pkirill Guest

    I have a form where user input in a combo box is appended as the last line
    in a text file. I need to preload the combo box with the last 10 entries.
    So I either need to count backwards from the bottom of the text file, ie.
    last item in text file is first item in cbo OR reverse the input from cbo to
    text file, ie. user input in cbo becomes FIRST line in text file.

    Can anyone help me with either of these? Somehow I suspect an array will
    come up. Arrays are my nemesis...

    Thanks for any suggestions!
     
    pkirill, Apr 14, 2004
    #1
  2. Sub test()

    Const NUMLINES As Integer = 10
    Dim fNum As Integer
    fNum = FreeFile
    Dim inFile As String
    inFile = "c:\temp\~temp.txt"
    Dim lineCount As Long
    Dim strCurLine As String
    Dim startLine As Long
    Dim readCount As Long
    Dim boxValues() As String
    Dim i As Long

    Open inFile For Input As #fNum
    lineCount = 0
    Do While Not EOF(fNum)
    lineCount = lineCount + 1
    Line Input #fNum, strCurLine
    Loop

    If lineCount = 0 Then
    'file has no lines in it...
    Close #fNum
    Exit Sub
    ElseIf lineCount < NUMLINES Then
    readCount = lineCount
    startLine = 0
    Else
    readCount = NUMLINES
    startLine = lineCount - NUMLINES
    End If
    ReDim boxValues(1 To readCount)

    Seek #fNum, 1

    For i = 1 To startLine
    Line Input #fNum, strCurLine
    Next 'i
    For i = 1 To readCount
    Line Input #fNum, boxValues(i)
    Next 'i

    Close #fNum

    For i = UBound(boxValues) To LBound(boxValues) Step -1
    Debug.Print i & " : " & boxValues(i)
    Next 'i
    Debug.Print

    End Sub
     
    James Belshan, Apr 14, 2004
    #2
  3. pkirill

    pkirill Guest

    Boy did that hit the nail on the head. Extreme thanks!

    Works beautifully...
     
    pkirill, Apr 14, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.