Results 1 to 20 of 20

Thread: [Resolved] String As Variable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Resolved [Resolved] String As Variable

    Lets say I have a string that contains label.Caption. The variable name is Send (Not the useage but similar structure)

    I want to know how would I get it to show frmHello.Show instead of Send on Runtime.

    I want it to show

    label.Caption = Value
    instead of
    Send = Value

    It seems so simple! Do I need to declare an object. If so How. I'm still learning the object useage. The book isn't being very nice w/ me right now.
    Last edited by DJHotIce; Jun 28th, 2005 at 10:15 PM.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: String As Variable

    i dont understand your question at all..please clarify a bit

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: String As Variable

    I want to dynamically create an event that will insert information inside of a control.

    So I need to define a var and a value. I'm using a module to do this, I plan on reusing this event.

    I have a dialog that shows up and it calculates a value, I want that value to be inserted correctly when I hit the update button. So far I've got the field to be updated to the dialog. Now I need to output it out.

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: String As Variable

    If 'Send' is a Variable as you stated, then:
    label1.Caption = Send should work!


    However, I suspect that a few keys pieces of info are missing



    Bruce.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: String As Variable

    Is it that the Variable 'Send' has limited scope?
    Is it Public, declared at the Module level so it can be seen by a Form?




    Bruce.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: String As Variable

    Bruce! I see what your saying. That would work only for a few problems! But that would be cool. I might consider it if all else fails. Possibly put a prefix on all items that could be updated. but that would mean I would have to take all my code back to the drawing board for validation techniques.

    Lets say for instance I want to send something to a textbox like ImaTextbox. I couldn't use that example

    I want
    Var1 = Var2

    Var 1 references an control to be updated and Var2 shows the value of the control

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: String As Variable

    Bruce, This is my Brainstorming Code:
    VB Code:
    1. Public Function PassBack(ByVal Send As String, ByVal Value As String) As Long
    2.     [Send] = Value
    3. End Function

  8. #8
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: String As Variable

    Var 1 references an control to be updated and Var2 shows the value of the control
    text1.text = label1.caption?

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: String As Variable

    Ok,

    i [think] I understand.

    If you know the name of the contol (Label in this case), you can append a number to it like:
    VB Code:
    1. Me.Controls("Label" & 1).Caption = "Test"


    Bruce.

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: String As Variable

    Alternatly, you could pass the Control ByReference as an argument in that sub.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: String As Variable

    Ok Thanks Bruce, I'm very satisfied w/ your responses. Added to your reputation, and am closing this by calling it resolved.

  12. #12
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: [Resolved] String As Variable

    Ok,

    Try:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Call PassBack(ImaTextbox, "This is a Test")
    5. End Sub
    6.  
    7. Public Sub PassBack(ByRef Send As TextBox, ByVal strValue As String)
    8.     Send = strValue
    9. End Sub

    I changed the Function to a Sub (as noting (in this case) was being passed back)

  13. #13
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: [Resolved] String As Variable

    The appending a number is not the solution here (I dont beleive) - that was just an example if you did know just the name of the control. I think the solution is to pass the
    control (see Sub in previous post).




    Bruce.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: [Resolved] String As Variable

    Read My mind, I was looking for some code to help me. I wasn't fully sure what you wanted, but before I posted ran a quick google and nothing showed up! Thanks again!

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: String As Variable

    I'm getting a type mismatch error. And It's pointing to
    VB Code:
    1. Private Sub Submit_Click()
    2.     Call TextBack(Label3[b].Caption[/b], txtMil.Text)
    3. End Sub

    Hmmmm. THe Textbox is a MaskedEdit box, I've changed that in the Sub.
    VB Code:
    1. Public Sub TextBack(ByRef Send As MaskEdBox, ByVal strValue As String)
    2.     Send = strValue
    3. End Sub

    Edit, However a normal textbox DOES work.
    What is up with Masked edit. Oh Well I'll work on it.
    Last edited by DJHotIce; Jun 28th, 2005 at 10:12 PM.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: [Resolved] String As Variable

    I'm pulling the text from a var label.caption but it won't work.

    This is because it is not a valid textbox item. However the text contained within that is the key. How do I break the variable and show only the text. I keep getting this text mismatch error. And have it narrowed it down to that issue.

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [Resolved] String As Variable

    Post your code. I don't understand what the label has to do with the textbox.

  18. #18
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: [Resolved] String As Variable

    Does 'Label3.Caption' identify a Control? ie Text1?

  19. #19
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428

    Re: [Resolved] String As Variable

    If so, then I succsefully tested this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Submit_Click()
    4.     Call TextBack([b](Me.Controls(Label1.Caption)[/b], txtMil.Text)
    5. End Sub
    6.  
    7. Public Sub TextBack(ByRef Send As TextBox, ByVal strValue As String)
    8.     Send = strValue
    9. End Sub
    In this case, my Labe1's Caption = "Text1".


    Note: I used a TextBox.... (cant load MaskedEditBox on this PC)



    Bruce.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: [Resolved] String As Variable

    Ahha, little modifying of the code and it works. Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width