-
Jul 10th, 2013, 07:01 PM
#1
Thread Starter
Banned
[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
-
Jul 10th, 2013, 07:19 PM
#2
Thread Starter
Banned
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
-
Jul 10th, 2013, 09:06 PM
#3
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
-
Jul 11th, 2013, 12:13 AM
#4
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
-
Jul 11th, 2013, 02:35 PM
#5
Thread Starter
Banned
Re: general help sligtly stuck
Originally Posted by Doogle
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|