2013/11/01 Reprint Please specify Source: http://blog.csdn.net/lxk7280
Syntax Basics:
(1) Sequential structure
Private Sub Form_Load ()
Dim Num1 as Integer, Num2 as inteher
Num1 = 1
Num2 = 2
MsgBox Num2
End Sub
The program executes from top to bottom, there is no jump or loop, and runs to end Sub.
This is called the sequential structure.
(2) Select structure
There are various, such as: If statement, multi-branch if statement, Select case statement.
Private Sub Form_Load ()
Dim num as Integer
num = 1
If num = 1 then
num = 2
Else
num = 3
End If
MsgBox Num
End Sub
The choice of structure is that the program chooses whether to execute the current statement based on the criteria you give.
(3) Cycle structure
The loop structure contains various, such as: For Loop, while loop, for each Next loop, etc.
Private Sub Form_Load ()
Dim I as Integer do while
i <=
s = s + i
i = i + 1
Loop
MsgBox "1 to 100 and yes" & S
End Sub
Several intrinsic functions are commonly used:
1.Trim function: Used to delete spaces on both sides of a string.
Private Sub Form_Load ()
Dim Str as String
str = " Can you? "
Magbox str
str = Trim (str)
MsgBox str
End Sub
2.Mid function: Mid (string, starting position, length) For example: Mid (str,4,1); Starting from the fourth bit of the string str, intercept a character
3.Len function: Calculating the length of a string
4.Left function: The first bit from the left of a string to intercept, a number of characters.
5.Right function: The first bit from the right of a string to intercept, a number of characters.
6.Instr function: Used to determine whether the string 2 appears in string 1, and where it appears. For example: Instr (str1, "God")
7.ASC function: Returns the ASCII code of a character
8.CHR function: The exact opposite of the ASC function
9.Lcase function: The character is converted to lowercase.
10.Ucase function: The exact opposite of the LCase function.
☆11. MsgBox Function:
vbOKOnly: Show only OK button
Vbokcance: Show only OK and Cancel buttons
Vbabortretrylgnorel: Show Abort Retry Ignore button
vbYesNoCancel: Show Yes No Cacel button
vbYesNo: Show Yes No button
Vbretrycancel: Show retry Cancel button
Vbcritical: Display critical message icon
vbquestion: Display warning query icon
Vbexclamation: Display warning message icon
vbinformation: Display information message icon
VbDefaultButton1: The first button is a default value
VbDefaultButton2: Second push-button default value
VbDefaultButton3: Third Push-button default value
VbDefaultButton4: The fourth button is a default value
For example:
MsgBox "Do you love Me?", vbYesNo, "Ask:"
MsgBox "You is right!", vbinformation, "Yes"
Default value: The computer software system requires the user to enter certain values while the user is not given, the system automatically assigns a predetermined value.
The MsgBox function has a return value, and the following describes its return value (int type):
vbOK: Pressed OK
Vbcancel: Press Cancel
Vbabort: The abort was pressed
Vbretry: pressed the retry
Vbignore: pressed the Ignore
Vbyes: Pressed Yes
Vbno: Pressed No
12.dir function
Basic form: Dir (path, attribute)
Possible values for the property:
Vbnormal: Default file with no attributes
vbReadOnly: Read-only file with no attributes
Vbhidden: Hidden files with no attributes
Vbsystem: System files with no attributes
VbVolume: Volume label file
Vbdirectory: No properties files and paths and folders
For example:
Dim file as String
file = Dir ("D:\test\")
After running these two lines, file will be the name of the first file in the test file under the D drive.
13.SetAttr function
Used to set properties for files and folders.
Optional value of the property:
Vbnormal: General
vbReadOnly: Read-only
Vbhidden: Hide
Vbsystem: System files
Vbarchive: The file has changed since the last backup
For example:
SetAttr "D:\test", Vbhidden + Vbsystem
After executing this sentence, the test folder is hidden. There are a lot of ways to get him back, and here are two of them.
One is to open any system disk when the settings open, set to show hidden folders, the general computer default is not to show hidden files.
Another is to use the SetAttr function in VB6.0 to manipulate the file, the statement is:
SetAttr "D:\test", vbnormal
This chapter is to write a little bit, the following a few simple procedures:
Private Sub Form_Load ()
Dim answer As Integer
Dim A As String, B As String
answer = MsgBox ("Do You Love Me?", vbquestion + vbYesNo, "ask:")
If answer = vbyes Then
a = Dir ("D:\test\") while
a <> vbnullstring
b = A & Chr & Chr10 & B
a = Dir
wend
MsgBox b
SetAttr "D:\test", vbnormal ' Vbhidden + vbsyst EM
Else
End If
End Sub
Here is the effect diagram of this program: