VB Constant declaration

Source: Internet
Author: User
Tags constant expression integer
1.VisualBasic data type
2. Declaration of variables
3.Option Explicit keyword
4. Scope of variables
5.Static keywords
6. Constant
7. Data type Conversion

VisualBasic data type Data type example
Byte Type 56
Boolean True False
Integral type 5367
Long Integral type 4364574
Single-Precision 4362.34
Double-precision 4652.65735745
Currency type $234.34
Date Type 4/7/2000
Object Type Label1
String "My homepage"
Variant type arbitrary value

Declaration of variables
Dim var as Type
public Var as Type
Private var as Type
which
Public defines a common variable
Dim, private define private variables

Option Explicit keyword
In VisualBasic, users can use variables without declaring them, but they tend to produce errors. You can use the Option Explicit keyword to force a declaration of a variable, which must be declared before it is referenced.
Option explicit keywords in the form or module's general declaration (genneraldeclarations).
You can also automatically add Option Explicit to each module by setting.


Scope of variables
Partial (local): A variable defined at the procedure level that is visible only in the process of declaring it.
Module/form (modudule/form): A variable declared at the module or form level, visible in all procedures in the module or form in which it is declared.
Public: A variable declared at the module or form level that is visible in any procedure of any project.

Static keyword
Ordinary local variables are freed at the end of the procedure and are initialized to 0 the next time the procedure is executed.
Local variables declared with static are not freed at the end of the procedure and still retain the value of the variable.
For example:
Sub P ()
Static I as Integer
I=i+1
MsgBox "A=" & I
End Sub

Constant
Constants are values that are not changed in your program. It has three scopes as well as variables:
Its definition syntax is as follows:
[Public] Const Con[as type]=expression
[Private] Const Con[as type]=expression
[] within the default

Data type conversions
VisualBasic automatically completes certain data conversions, and to improve speed, we typically use the CType () function to display the conversion.
VisualBasic conversion functions include:
CBool Convert to Boolean type
CByte Convert to byte type
CCur Conversion to currency type
CDate Conversion to date type
CDBL conversion to double type
CInt conversion to Integer type
CLng converted to Long type
CSng conversion to single type
CSTR conversion to String type
CVar conversion to Variant type
CVERR Conversion to error type




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.