Results 1 to 4 of 4

Thread: another question...listbox help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    ok. i am working on an alarm program and i need to use listboxes to set the time. here is what my interface look like:



    what i need to do is use the listboxes to scroll to a certain hour, minute, and second. then i need to place the "time" in a text box. but i want to be able to place it without having to select the item (number) in the listbox. is there any way to say

    textbox.text = "the number that is showing in the window" ???

    here is my code so far:

    Code:
    Dim h As String
    Dim m As String
    Dim s As String
    Dim ap As String
    h = lstHour.Text
    m = lstMin.Text
    s = lstSec.Text
    If optAM.Value = True Then
        ap = "am"
    ElseIf optPM.Value = True Then
        ap = "pm"
    End If
    txtTime.Text = h & ":" & m & ":" & s & " " & ap
    i have the AM and PM parts taken care of. i assume i need to change lst"whatever".text to something else. am i making any sense? if not, let me know and i will try to help with further explanation. any help will be greatly appreciated. thank you.

    --michael

  2. #2
    Member
    Join Date
    Nov 1999
    Location
    Perth, WA
    Posts
    35

    Post

    well, first of all, wat sort of listbox is that? it doesnt look like a standard listbox, is an added component??

    also, you might try the list1box change event?

    i found an interesting way of doing it is to put in the got focus event a temp variable to store wat the field is, and then on the lost focus check if the data has changed and update the necessary variables

    (i know there is the change event, but if you want it to change three or four times before you like wat you get ie incrementing or typing more than one char it helps)

    also why does it have to be a listbox?? whats wrong with a textbox?

    and how are you incrementing the hours and mins so they dont clock over 24 or 60?

    hope these thoughts help, sorry if it is just causing more problems >

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    well, it is a normal listbox just shrunk down to be the size of one "selection".

    anyway, i have pre-populated the list box with the numbers 1-12 or 1-59 (depending on hours, mins, or secs) and i have to use listboxes because that's what the assignment is all about. my teacher says so. but i will try your idea about the got/lost focus. i think that might work. but any other suggestions from you or other people will still be appreciated, just in case it doesn't work.

    thanks again.

    --michael

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Create a Listbox Control Array, (Create a Listbox Called lstTime and set the Index Value to Zero, then Copy and Paste it Twice More), a Textbox - txtTime and a Checkbox - chkAMPM..
    Code:
    Private Sub Form_Load()
        Dim iIndex As Integer
        For iIndex = 0 To 59
            If iIndex < 12 Then lstTime(0).AddItem Right("00" & iIndex + 1, 2)
            lstTime(1).AddItem Right("00" & iIndex, 2)
            lstTime(2).AddItem Right("00" & iIndex, 2)
        Next
    End Sub
    
    Private Sub lstTime_Scroll(Index As Integer)
        txtTime = _
        lstTime(0).List(lstTime(0).TopIndex) & ":" & _
        lstTime(1).List(lstTime(1).TopIndex) & ":" & _
        lstTime(2).List(lstTime(2).TopIndex) & ":" & _
        IIf(chkAMPM, " PM", " AM")
    End Sub
    
    Private Sub chkAMPM_Click()
        lstTime_Scroll 0
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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