Library tutorials & articles

Variables

Introduction

When you are creating your VB application you will find that you will need to store certain values. For example, after showing an options dialog, you will need to save the information selected to some variables so you can acess the data after the dialog box has been removed from the memory. You can use variables to store this information. They are called variables because they store variable information (information that changes)

Comments

  1. 17 Apr 2004 at 07:37

    i just found out how i can make my original idea work.


    i read something about the "eval" function in the microsotf script controls, so now ik kan just say: ScriptControl1.Eval(line) and it will finally work as i planned before

  2. 02 Mar 2004 at 02:35

    Hey cwamsley,


    Welcome to DevFusion!


    This sounds like a control array problem - if you're using VB (and not .NET) that is. You can have several controls with the same name, but with an index, like a normal array. For example,


    cboSelection(0), cboSelection(1), cboSelection(2), ..., cboSelection(n)


    Then the procedure which needs to know the name of the combobox need only be told an index, and can do something like:
    cboSelection(intIndex)


    to select the correct combobox object.


    The easiest way to create a control array, is to select the combo box in Form View, click Edit | Copy, click Edit | Paste and click Yes when asked whether or not you would like to create a control array.


    Control arrays are a complex topic, but have many, many uses. I recommend you consult the manual to clarify my explaination, and to cover the topics I simply do not have the time to write about!


    Good luck.

  3. 01 Mar 2004 at 16:12

    Louis,


    I am working on a somewhat similar problem (to the String to Object comments from Aug 5, 2003) and hope you can suggest a course of action.


    I'm trying to create a simple way to set and modify the values in multiple combination boxes. My plan is to have a sheet containing the combobox names in cells A .. n and the selection choices to be in rows 2 .. m.  


    CB1    CB2
    A1        A2
    B1        B2
    C1        C2


    In my VB code, I would like to use something like CBname = StringtoObject(Range("A" & m).value) so that I can loop through columns A to n and pass CBname as the combobox name to another procedure.  Another possibility might be for CBname to point to the CB1 address, but I'm not sure how to do this in VB. Do you have any suggestions?

  4. 01 Mar 2004 at 02:03

    The following lists the public, private, and default visibility
    for the various elements you can declare in your programs.


    Default means declaring without anything proceding (or with Dim
    in the case of variables) rather than with Public or Private.


                       Standard Module    Form and Class Modules
                       ============================
    Constants      Default private    Default private
                         Private OK         Private OK
                         Public OK          Public illegal


    User-defined types  Default public     Default illegal
                         Private OK         Private required
                         Public OK          Public illegal


    Declare statements  Default public     Default illegal
                         Private OK         Private required
                         Public OK          Public illegal


    Variables           Default private    Default private
                         Private OK         Private OK
                         Public OK          Public creates property


    Functions and subs  Default public     Default creates method
                         Private OK         Private OK
                         Public OK          Public creates method


    Properties          Default public     Default public
                         Private OK         Private OK
                         Public OK          Public OK

  5. 05 Aug 2003 at 13:48

    I'm glad that you came up with a solution.


    For muti-lingual support you best bet is to use a Resource file. Then the User's language and Locale will be detected automatically and your program will be capable of dealing with these details on-the-fly.


    If you the MSDN collection installed there is a rather good chapter in the Visual Basic section describing how best to use Resource Files.


    Hope this helps.

  6. 05 Aug 2003 at 13:29

    I already tought of a solution.


    The original plan was to have a text file, with the data (it's supposed to be a multi-language support, with text-files that contain the strings for like the menu's) in order: objName = value.


    This didn't work, so i used a bit harder method with a select case the when the object name is found, the string is used, for example:
    Case "mnuHelp": mnuHelp.Caption = info(1)
    the info(1) is the string after the "=" char.


    This works good now, maybe i will make it a bit better lateron, but now i'm gonna focus on making the real program (a better notepad).


    Thanks anyways.

  7. 05 Aug 2003 at 13:24

    I don't think you can do this.


    Why do you want to? Describe the situation and perhaps we can come up with a different solution.

  8. 05 Aug 2003 at 12:50

    i have a string from a file, and i want it to be the object name. how can i do that?

  9. 22 Sep 2002 at 01:07

    I am trying to make a program and when I set a variable with a long value and a portion of its value gets chopped off.  The shorter variables values get extra characters added to the end.  How do I fix this?


    It works fine if I hard code the variable into the program but I need to get it from an ini file and use it.


    Thank you in advance.


    Joel Strellner

  10. 18 May 2002 at 18:39

    to make a varible avilble in all forms use this;


    public VarName as string


    not


    dim VarName as string


    then you can use it on all forms and modules


    example;  form1.VarName = something

  11. 24 Apr 2002 at 12:38

    Please, how to declare a variable that can be  accessed and changed in all procedures in all the forms in a project?


    Thanks

  12. 01 Jan 1999 at 00:00

    This thread is for discussions of Variables.

Leave a comment

Sign in or Join us (it's free).