a little VB help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • InsaneGreen
    Confirmed User
    • Aug 2003
    • 996

    #1

    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

    does anyone know how to make something like this work? thanks in advance!!!
    SIG TOO BIG! Maximum 120x60 button and no more than 3 text lines of DEFAULT SIZE and COLOR. Unless your sig is for a GFY top banner sponsor, then you may use a 624x80 instead of a 120x60.
  • fletcher
    Confirmed User
    • Jan 2003
    • 698

    #2
    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.
     
    [email protected]
    ICQ: 6411138

    Comment

    • fletcher
      Confirmed User
      • Jan 2003
      • 698

      #3
      Originally posted by fletcher
      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.
      Ohhh...I see what you're trying to do. Dynamically build the variable.
       
      [email protected]
      ICQ: 6411138

      Comment

      • InsaneGreen
        Confirmed User
        • Aug 2003
        • 996

        #4
        Originally posted by fletcher


        Ohhh...I see what you're trying to do. Dynamically build the variable.
        exactly, any ideas?
        SIG TOO BIG! Maximum 120x60 button and no more than 3 text lines of DEFAULT SIZE and COLOR. Unless your sig is for a GFY top banner sponsor, then you may use a 624x80 instead of a 120x60.

        Comment

        • Mr. T
          Registered User
          • Jun 2002
          • 62

          #5
          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
          Mr. T!

          Comment

          • Mr. T
            Registered User
            • Jun 2002
            • 62

            #6
            ...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
            Mr. T!

            Comment

            • Mr. T
              Registered User
              • Jun 2002
              • 62

              #7
              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
              Mr. T!

              Comment

              Working...