View Full Version : Assigning UBound value to a variable
wimnat
03-10-2008, 07:50 AM
I have an array which is filled with email addresses from my database. I want to loop through this array and stash each 20 email addresses into a string and then any remainder into a string too. So...
arrayCounter = Ubound(array)
do
....
arrayCounter = arrayCounter - 1
loop while (arrayCounter <> 0)
Unfortunatly, I always get a mismatch type error. I've tried declaring arrayCounter as an int, a long and a variant and none of them work. How can i do this?
Norie
03-10-2008, 08:50 AM
Why not use a For Next loop?
For arrayCounter = LBound(myarray) To UBound(myarray)
Next arrayCounter
wimnat
03-10-2008, 09:15 AM
Just convenience i guess. I need to be keeping track of each block of 20 email addresses and how close i'm getting to the end of the array.
I guess i can use something like
counter = 0
For arrayCounter = LBound(myarray) To UBound(myarray)
rem = counter % 20
if rem <> 0 then
string = string + myarray(counter)
else if counter > (Ubound(myarray) - 20)
string = string + myarray(counter)
counter = counter + 1
Next arrayCounter
Norie
03-10-2008, 10:43 AM
How is the Do Loop structure more convienent?:huh:
PS Did you notice anything about this?
rem = counter % 20
Nice shade of green.:)
wimnat
03-10-2008, 01:05 PM
Not sure! It just was, when i was thinking about this last night. I've implemented it now as a for loop. Seems to be working ok.
For counter = LBound(emailAddressArray) To UBound(emailAddressArray)
If loopCounter < (UBound(emailAddressArray) - 20) Or addressCounter <> 0 Then
If addressCounter = 20 Then
[List65].AddItem ("Sending block of 20 email to: " + bccString)
MsgBox (bccString)
' Send Email
Call doSendEmail(objMessage, "", bccString, [emailSubject], htmlEmailTxt)
' Clear address string
bccString = ""
' Reset the address counter
addressCounter = 0
Else
bccString = bccString & emailAddressArray(counter) & ", "
End If
Else
bccString = bccString & emailAddressArray(counter) & ", "
End If
addressCounter = addressCounter + 1
loopCounter = loopCounter + 1
Next counter
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.