Search code examples
listboxvb6

How do I display numbers in the List Box?


Introduction: Hi! I'm new in VB6 UI and I just want to make numbers appear in a list box.

Details: And what I mean is that, for example, I have two textboxes and the 1st textbox is labeled as "From" and the 2nd "To" and if the user inputs 1 in "From" and 10 in "To", I wanna list numbers 1 to 10 in the List Box.

What you've tried?: Don't know what to write right now.

Code:

Option Explicit
Private Sub btCalculate_Click()
    Dim From As Long
    Dim T As Long
    
    From = Val(txtFrom.Text)
    T = Val(txtTo.Text)

End Sub

Thank you for answering and replying to my question.


Solution

  • You will need to add a loop. Something like this:

    Option Explicit
    
    Private Sub btCalculate_Click()
       Dim i As Integer
       
       lstCount.Clear
       
       For i = Val(txtFrom.Text) To Val(txtTo.Text)
          lstCount.AddItem i
       Next
    End Sub
    

    Where lstCount is a ListBox.