hello please help me..can you give some idea on how to declare variables in local....and also how to declare variables in public...hoping for your positive responds

hello please help me..can you give some idea on how to declare variables in local....and also how to declare variables in public...hoping for your positive responds

hi jemz,

i hope i will be of help.
to declare a public variable u must use the key word 'Public' e.g

Public strString As String

for the above variable to be accessible by all functions within a form(module) declare it in the 'General Declaration' section in the code window-this will qualify to be local variable but accessible only by functions created in the form.

if you want to declare a variable that is accessible throughout the project(by all forms in your project) add a module and declare all your variables that you want to be public to the project there.

variables declared within a function can only be accessible in that function that they have been declared in without using the key word 'Public' but using 'Dim' for dimensioning variable e.g

Dim strString As String

nice jemz. for local variable normally every body use : Dim. it is easy to use. but alternative way to use Dim is like :

'for Integer
Year% = 1999
'for Long
number&=123456584
'for Single
radius!=9985
'for Double
Price# = 44545.95
'for Currency
Taka@ = 10500.50

But man doesn't like to use it. it is easy to use

Dim Varname As Vartype

codefixer,

You have a few incorrect statements in your explanation...

To begin with...

>for the above variable to be accessible by all functions within a form(module) declare it in the 'General Declaration' section in the code window-this will qualify to be local variable but accessible only by functions created in the form.

is incorrect...

For a variable to be available to the entire form or module for that matter all you need to do is Dim it or Private it in the general declarations section of the form or module. If you declare a variable as Public in a form, say in form one as you have, then other forms and modules can access that variable by using the form as a reference in the dot notation we enjoy so much...(this code in form2 will reference the form1 variable you have declared in your post)...

Form2.Text1.Text = Form1.strString
Form1.strString = Form2.Text2.Text

Good Luck

codefixer,

You have a few incorrect statements in your explanation...

To begin with...

>for the above variable to be accessible by all functions within a form(module) declare it in the 'General Declaration' section in the code window-this will qualify to be local variable but accessible only by functions created in the form.

is incorrect...

For a variable to be available to the entire form or module for that matter all you need to do is Dim it or Private it in the general declarations section of the form or module. If you declare a variable as Public in a form, say in form one as you have, then other forms and modules can access that variable by using the form as a reference in the dot notation we enjoy so much...(this code in form2 will reference the form1 variable you have declared in your post)...

Form2.Text1.Text = Form1.strString
Form1.strString = Form2.Text2.Text

Good Luck

hi Vb5prgrmr,

thanks for the correction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.