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)
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
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
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.
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?
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
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.
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.
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.
i have a string from a file, and i want it to be the object name. how can i do that?
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
public VarName as string
not
dim VarName as string
then you can use it on all forms and modules
example; form1.VarName = something
Please, how to declare a variable that can be accessed and changed in all procedures in all the forms in a project?
Thanks
This thread is for discussions of Variables.