![]() |
a little VB help...
im trying to decide which control to use by using a string for a mailer.. each target has 4 email bodys it rotates thru, named like this
asianbody1.text asianbody2.text asianbody3.text asianbody4.text heres what im having trouble with: Dim thebody As Control target$="asian" bodycount$="1" thebody = (target$ & "body" & bodycount$) MsgBox (thebody.Text) here is the error im getting http://www.insanegreen.com/error.jpg does anyone know how to make something like this work? thanks in advance!!! |
I'm not even that good at VB, but it looks like you're setting "thebody" to a string then referencing it like an object.
|
Quote:
|
Quote:
|
Hey, what's up...here's a sample for you.
I'd open a new project and paste this in there. Then make your modifications where ever. You'll notice when the form loads up, it populates the Bodies Collection. From there it just calls one out at random. You can see the output by making a cheap test, In my case it's "MsgBox GetRandBody" GetRandBody() returns as a hahahahahahahaha Hope this helps...any other questions? -Brad Option Explicit 'Body Randomizer - by SuperBrad 'This may seem like a morbid example, but it works... Public Bodies As New Collection 'Public Body Collection... 'Returns your random body as a string for usage anywhere. Public Function GetRandBody() As String GetRandBody = CStr(Bodies(Random(1, Bodies.Count))) End Function 'Loads your body string into the Bodies Collection Public Function LoadBodies(strBody As String) Bodies.Add strBody End Function 'This Function Generates Your Random Number (The High is the body count) Public Function Random(lngLow As Long, lngHigh As Long) As Long Rnd -1 Randomize Random = Int((lngHigh - lngLow + 1) * Rnd(Rnd)) + lngLow End Function Private Sub Command1_Click() End Sub Private Sub Form_Load() Set Bodies = New Collection LoadBodies "This is a body1" LoadBodies "This is a body2" LoadBodies "This is a body3" LoadBodies "This is a body4" MsgBox GetRandBody End Sub |
...almost forgot.
You can iterate through that bodies collection if you did this. Dim i as Long For i = 1 to Bodies.Count Msgbox Bodies(i) Next i |
Yea...not a really busy day at work today; so I'll explain why I did what I did.
1. I'm awesome... No, but the thing to keep in mind is that storing large chunks of text in GUI "holders" in your case the textboxes is a bad way of managing resources. Every time you use another control, you are adding to the horrible GUI Beast's overhead. Even if the text boxes were off-screen, they still take up resources. And the more stuff you have painting on your forms the slower your app is going to be; especially if they're filled with lots of text/html! So by using Collections, you now have a means to order and structure your data. And it's easy as sin to add/remove/count your resources! If you didn't know already, the extensions of the Collection type are as follows: Collection.Add - Adds to your collection Collection.Remove(index) - removes the "nth" item from your collection (remember they're ordered 1-n, unlike normall arrays {0-n}) Collection.Count - returns the number of elements in your collection. And finally Collection.Item(index) - returns the "nth" item in your collection. So now that you've got this slick object to play with - I would suggest (since you're mailing) to use another collection (let's say Subjects) to manage all of your subjects so that you could randomize those as well! Hope this little tutorial was worthwhile...I'd be happy to answer more questions while I'm bored. Until next time, Brad |
All times are GMT -7. The time now is 12:14 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123