Results 1 to 5 of 5

Thread: [RESOLVED] general help sligtly stuck

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Resolved [RESOLVED] general help sligtly stuck

    i have a listbox1 and text1.text

    list1 holds keywords

    office books <<<<<<< when i click here it should automaticly select that and 5 lines below and add to text1.text with comma ,
    plane tickets
    colour pens
    match box
    pen drive
    usb stick
    flash drives
    computer spare parts
    hdd drives


    example when selected ( office books )

    text1.text = "office books,plane tickets,colour pens,match box,pen drive"



    this is what i have

    Code:
    If List1.ListIndex = List1.ListCount - 1 Then
            List1.ListIndex = 0  ' <<< when it comes to selecting last item the other remaing items should get selected from top row again.
            Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3) & "," & List1.List(List1.ListIndex - 0 + 4) & "," & List1.List(List1.ListIndex - 0 + 5)
        Else
          '  List1.ListIndex = List1.ListIndex + 1
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3) & "," & List1.List(List1.ListIndex - 0 + 4) & "," & List1.List(List1.ListIndex - 0 + 5)
        End If
    End Sub

    ==========================================

    2nd thing how do i randomize the keywords before it goes to text1.text

    add random 5 items from list1 to text1.text

  2. #2

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: general help sligtly stuck

    Code:
    Private Sub List1_Click()
    If List1.ListIndex = List1.ListCount - 1 Then
            List1.ListIndex = 0
          '  Text1.Text = List1.Text '& "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3) & "," & List1.List(List1.ListIndex - 0 + 4) & "," & List1.List(List1.ListIndex - 0 + 5)
        ElseIf List1.ListIndex = List1.ListCount - 5 Then
          '  List1.ListIndex = List1.ListIndex + 1
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3) & "," & List1.List(List1.ListIndex - 0 + 4) & "," & List1.List(List1.ListIndex - 0 + 5)
           ElseIf List1.ListIndex = List1.ListCount - 4 Then
          '  List1.ListIndex = List1.ListIndex + 1
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3)
           ElseIf List1.ListIndex = List1.ListCount - 3 Then
          '  List1.ListIndex = List1.ListIndex + 1
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2)
           ElseIf List1.ListIndex = List1.ListCount - 2 Then
          '  List1.ListIndex = List1.ListIndex + 1
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1)
          Else
          Text1.Text = List1.Text & "," & List1.List(List1.ListIndex - 0 + 1) & "," & List1.List(List1.ListIndex - 0 + 2) & "," & List1.List(List1.ListIndex - 0 + 3) & "," & List1.List(List1.ListIndex - 0 + 4) & "," & List1.List(List1.ListIndex - 0 + 5)
        End If
    End Sub
    i have done this runs ok

    when it comes to List1.ListIndex = 0 how do i select top items

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: general help sligtly stuck

    You did.....list1.listindex = 0 does it.

    example:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    List1.ListIndex = 0
    MsgBox List1.Text
    End Sub
    
    Private Sub Form_Load()
    Dim x As Integer
    For x = 1 To 7
    List1.AddItem (Str(x))
    Next x
    List1.ListIndex = 3  'this selects the 4th item during form_load
    End Sub

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: general help sligtly stuck

    Wouldn't it be simpler using a loop ?
    Code:
    Private Sub List1_Click()
    Dim intI As Integer
    Dim intX As Integer
    Text1.Text = vbNullString
    intX = List1.ListIndex
    Do
        Text1.Text = Text1.Text & List1.List(intX) & ","
        intX = intX + 1
        If intX > List1.ListCount - 1 Then intX = 0
        intI = intI + 1
    Loop Until intI = 6
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    End Sub

  5. #5

    Thread Starter
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: general help sligtly stuck

    Quote Originally Posted by Doogle View Post
    Wouldn't it be simpler using a loop ?
    Code:
    Private Sub List1_Click()
    Dim intI As Integer
    Dim intX As Integer
    Text1.Text = vbNullString
    intX = List1.ListIndex
    Do
        Text1.Text = Text1.Text & List1.List(intX) & ","
        intX = intX + 1
        If intX > List1.ListCount - 1 Then intX = 0
        intI = intI + 1
    Loop Until intI = 6
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    End Sub

    excellent simple clean code very affective nice job thanks.

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