how to declare a variable in vb

Posted by Shanky11 under VB.NET on 2/23/2013 | Points: 10 | Views : 1821 | Status : [Member] | Replies : 4
private datetime As DateTime

Dim datetime As DateTime




Responses

Posted by: Raj.Trivedi on: 2/23/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Shanky11,

The syntax that you have posted for the second option should work as Dim is for dimension in VB and the above syntax seems good

Dim xdate as datetime

dont use datetime as variable name.

Date time is a reserve word for VB

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 2/23/2013 [Member] Starter | Points: 25

Up
0
Down
i m asking what is the diff b/w two declaration?????

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 2/23/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Shanky11

Misunderstood your Question sorry for that?

Dim is used for declaring variables and allocate memory space
Private,protected or public are access modifiers.They will determine the accessibility of your variables whether it should be public or depending on the modifiers specified.
If you dont use access modifiers such Private,protected or public explicitly and just declare it as Dim date as datetime,then the variable will be private by default.

To omit Dim use you can use private date as Datetime, this variable will work in that class only and same logic applies for Dim date as Datetime

When you declare any other specific apart from private it will works as specifier

To summarize both declaration work the same way logicaly as both will behave as private variables

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 2/23/2013 [Member] Starter | Points: 25

Up
0
Down
Hai
Access Specifier:
It is used to tell lifespan of a vairable

private todaydt as datetime


It specifies the statement can be accessed that the elements can be accessed only from the within the same module,class,structure.

Dim -Declaration in Memory

Dim todaydt as datetime

Accessed globally


Example:
dim a as string="From a"
Dim b as string="From b"

module pr ()
private dim c as string="C"
dim d as string="D"

End module



Explanation:

c is used only within the function
If we call this vairable access is not possible

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response