Results 1 to 11 of 11

Thread: [RESOLVED] How to put a variable in a form name

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Resolved [RESOLVED] How to put a variable in a form name

    Wondering how you would put a varible into a form name. For example Results(x). Or something like that.

  2. #2
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: How to put a variable in a form name

    VB Code:
    1. frmMain.Caption = Results(x)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: How to put a variable in a form name

    Thanks

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: [RESOLVED] How to put a variable in a form name

    Didn't work, said end of satement and highlighted the (. I tried putting quotes around the "Results" but still didn't work.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: [RESOLVED] How to put a variable in a form name

    Does Results(x) evaluate to a string? If it evaluates to a number try CStr(Results(x)).

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: [RESOLVED] How to put a variable in a form name

    Quote Originally Posted by Al42
    Does Results(x) evaluate to a string? If it evaluates to a number try CStr(Results(x)).
    That highlights Results and says sub or function not defined. Results isn't a variable, it's a string. So it's thinking Results is a variable.

  7. #7
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: [RESOLVED] How to put a variable in a form name

    I'm not sure if this is what you want...
    VB Code:
    1. frmMain.Caption = "Results(x)"

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: [RESOLVED] How to put a variable in a form name

    Quote Originally Posted by BoneCrif
    I'm not sure if this is what you want...
    VB Code:
    1. frmMain.Caption = "Results(x)"

    No it's not. I want it to keep a running total of how many times I click a command. So it's like:

    Dim x as integer

    x = x + 1
    Form1.caption = Results (x)


    So it would be the first time you open it. Results 1 then the 2nd time results 2 ect

  9. #9
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: [RESOLVED] How to put a variable in a form name

    ohh, now I see...
    VB Code:
    1. Dim x as integer
    2. x = x + 1
    3. frmMain.Caption = x

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    71

    Re: [RESOLVED] How to put a variable in a form name

    ok, but how would you make it with a string, then a varible. Would it be with &

    frmmain = "Results" & x

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

    Re: [RESOLVED] How to put a variable in a form name

    Quote Originally Posted by Grant1377
    ok, but how would you make it with a string, then a varible. Would it be with &

    frmmain = "Results" & x
    Yep. The & (Ampersand) is the String concatenation (join) operator.

    NB. use a space (after Result) > "Results " & x
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

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