View Full Version : Punctuation, baby


twoplustwo
06-18-2008, 11:54 PM
Hey guys,

I think I've seen a solution to this here before but I can't really word my problem into a search criteria!

I basically group some sites in a module into one string. I separate these with commas presently but I can't figure out how to stop before the last entry.


For x = 0 To lstSite.ListCount - 1 'Select sites
If lstSite.Selected(x) = True Then
strSite = strSite & lstSite.Column(2, x) & ", "
End If
Next


Bolded is the line I need to edit I guess.

Please to be suggesting how to go about it :)

Thanks.

Steve.

dsigner1
06-19-2008, 12:12 AM
The elegant solution is to add the first site with no comma then put the comma in front of the site string in the loop. The quick and dirty way is to crop two chars off the string after the loop has ended.

twoplustwo
06-19-2008, 12:19 AM
Hi ds,

Thanks for the ideas.

Would it be possible to point me in the right direction or offer some syntaxt advice?

Thanks for the reply.

dsigner1
06-19-2008, 12:32 AM
I am the worlds worst at actual coding. Just plug away till the damn thing works, mainly because I have used to many different pieces of software. Anyway try this
strSite = Left(strSite, Len(strSite - 2))
which should chop off the final comma and space

twoplustwo
06-19-2008, 12:49 AM
Hmm I've inserted that but it "can't assign to this expression"...


For x = 0 To lstSiteContact.ListCount - 1 'Select sites
If lstSiteContact.Selected(x) = True Then
strCc = strCc & lstSiteContact.Column(1, x) & ", "
strCc = Right(strCc, Len(strCc - 2))
End If
Next


It breaks at the bolded line :)

dsigner1
06-19-2008, 12:54 AM
Sorry, It must go outside the loop
For x = 0 To lstSiteContact.ListCount - 1 'Select sites
If lstSiteContact.Selected(x) = True Then
strCc = strCc & lstSiteContact.Column(1, x) & ", "
End If
Next
strCc = Left(strCc, Len(strCc - 2))

twoplustwo
06-19-2008, 12:59 AM
Thanks for the reply.

It's getting errored I think because we're trying to use a numeric expression on a string according to Access Help.

"You attempted to use a numeric expression (javascript:hhobj_3.Click()) as an argument (javascript:hhobj_4.Click()) to the Len function.
The Len function doesn't accept a numeric expression, a numeric literal, or a binary numeric expression, but it does accept either a string or numeric variable, a string expression (javascript:hhobj_5.Click()), or a variable (javascript:hhobj_6.Click()) of user-defined type (javascript:hhobj_7.Click())."

dsigner1
06-19-2008, 01:02 AM
I did warn you - this should do better
strCc = Left(strCc, Len(strCc) - 2)

twoplustwo
06-19-2008, 01:05 AM
Awesome, thanks a lot mate.

Happy time!