|
-
Nov 13th, 2002, 10:46 AM
#1
Thread Starter
Member
Loop thru Listbox not getting all records
I trying to loop through a listbox and retrieve e-mail addresses. I get the addresses just fine what I’m having a problem with is. If there are ten addresses I’m only pulling 9 addresses and if there is only one address it does not do anything.
What am I doing wrong?
VB Code:
Dim n As Integer
Dim x As Integer
'On Error GoTo err:
n = 0
x = lstSelected.ListCount - 1
Do Until n = x
lstSelected.ListIndex = n
adNM = InStr(1, lstSelected.Text, " - ")
adID = Right$(lstSelected.Text, Len(lstSelected.Text) - adNM - 1)
Addstr = adID
MsgBox adID
'Call SendBroadcast
n = n + 1
Loop
I'm a misanthropic philanthropist!
Frog, the only white meat...
-
Nov 13th, 2002, 10:53 AM
#2
Your condition should be "Do Until n > x", not "n = x"
"It's cold gin time again ..."
Check out my website here.
-
Nov 13th, 2002, 10:53 AM
#3
Addicted Member
when n reach .listcount - 1 when you get to the n = n + 1 it will exit the do block without taking the item at this index.
changing
for
should fix that
'You keep creatures in cages and release them to fight? That's sick!'
-
Nov 13th, 2002, 10:54 AM
#4
Frenzied Member
you should loop till n > x
or don't substract 1 from the listcount and test on n = x
change it to whatever you think is better.
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 13th, 2002, 10:54 AM
#5
Addicted Member
Guess i wasn't fast enough for that one
'You keep creatures in cages and release them to fight? That's sick!'
-
Nov 13th, 2002, 10:56 AM
#6
Frenzied Member
you could rewrite it with a for next, reads better
VB Code:
For n = 0 To lstSelected.ListCount -1
lstSelected.ListIndex = n
adNM = InStr(1, lstSelected.Text, " - ")
adID = Right$(lstSelected.Text, Len(lstSelected.Text) - adNM - 1)
Addstr = adID
MsgBox adID
'Call SendBroadcast
Next
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 13th, 2002, 11:15 AM
#7
Thread Starter
Member
I'm a misanthropic philanthropist!
Frog, the only white meat...
-
Nov 13th, 2002, 11:39 AM
#8
has everyone turned into burnt pancakes today???! 
VB Code:
Sub woof()
Dim lngIndex As Long
Dim strText As String
Dim lngPos As Long
For lngIndex = 0 To lstSelected.ListCount - 1
strText = lstSelected.List(lngIndex)
lngPos = InStr(1, strText, " - ")
adID = Right$(strText, Len(strText) - lngPos - 1)
Addstr = adID
MsgBox adID
'Call SendBroadcast
Next lngIndex
End Sub
The basics of ALL programming...*SIGH*
Woka
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
|