VB 6 Codes
Microsoft Visual Basic 6 Commands
Basic Commands
Create New Folder
Mkdir”C:\New Folder”
Remove Empty Folder
Rmdir”C:\New Folder”
File Run
Shell(”C:\New Folder\Kasun.exe”)
File Delete
kill(”C:\New Folder\Kasun.exe”)
Avoid Run Time Errors
On Error Resume Next
Copy Files
Filecopy(”C:\New
Folder\Kasun.exe”,” D: \Tharindu.exe”)
Show Next Form
Form2.show
Unload Current Form
Unload Me
Refresh Form
Form1.Refresh
Message Box
MsgBox “Do You Want to Save The
Changes “,VbYesNoCancel+Vbinformation,”K.K.T.M Folder Maker”
Button Numbers
VbOk = 1
VbCancel =2
VbAbort =3
VbRetry= 4
Vbignore = 5
VbYes=6
VbNo=7
X=MsgBox(“Exit This Program
?”,VbyesNo+Vbqustion,”Exit”)
If X=6 Then
End
End If
Date & Time formula
To get correct system date following can be used
Format(Date,”MM/DD/YYYY”)
E.g.
Format(Date,”16.06.1990”)
Label1.Caption=Time
Following Date Functions will Help You
Date
Time
Now
Timer
Identify Variables
String – Any letters without numbers
Integer –Numbers without decimal points
Double-Numbers with decimal points
Currency- Currency values can be stored
Date- Date & Time
Boolean- True or False data
Variant – All above data
E.g.
Dim X as Integer
Dim Y as Integer
X=Text1.Text
Y=Text2.Text
Label1.Caption=Val(X)+ Val(Y)
Symbols
( + ) Add two or several value
( - ) Reduce Value two or
more
( / ) Divide values
( * ) Multiply values
( ^ ) Geometry
( & ) Gather two or
few string value
String Function
E.g.
Left(TextBox1.Text,3)
Right(TextBox1.Text,3)
Ucase(TextBox1.Text)
Lcase(TextBox1.Text)
Mid(TextBox1.Text,3,2)
Len(TextBox1.Text)
Str(TextBox1.Text)
Trim(TextBox1.Text)
Ltrim(TextBox1.Text)
Chr(TextBox1.Text)
String Function
E.g.
Cos(TextBox1.Text)
Tan(TextBox1.Text)
Sin(TextBox1.Text)
Log (TextBox1.Text)
Abs(TextBox1.Text)
Data Conversion Function
Hex(TextBox1.Text)
Oct(TextBox1.Text)
Format Function
Format(123467,”###,###.00”)
If Condition
If TextBox1.Text=”12345” Then
Form2.Show
Else
Beep
If TextBox1.Text=”1264” Then
Form3.Show
Else
Beep
If TextBox1.Text=”0000” Then
Form4.Show
Else
Beep
End If
End If
End If
Create Registry Key
‘You can write this command inside command button
Private Sub Command1_Click
Createregkey”HKEY_CURRENT_CONFIG\Hello!”,”Oh
I’m Kasun”
End Sub
Sub Createregkey (regkey,regval)
Dim regedit
Set regedit=createobject(“WScript.Shell”)
Regedit.Regwrite regKey,regval
End Sub
Control Box
Maximize
Form1.windowState=2
Minimize
Form1.windowState=1
Normal
Form1.windowState=0
Close Application
End
OLE
Action
OLE1.Action=7
To avoid alert message we can better write
OLE1.Setfocus
OLE1.Action=7
Sendkeys(“/R”)
Delete
OLE1.Action=10
Add New
Object
OLE1.Action=14
Create New Link
OLE1.CreateLink(“C:\A.exe”)
Embed New File
OLE1.CreateEmbed(“C:\A.exe”)
Use
Windows Common Dialog Controls
Using this
command you will be able to save text file
CommonDialog1.DialogTitle=”Save”
CommonDialog1.Filter=”Text
Files(*.Text)|*.Txt”
CommonDialog1.ShowSave
Open
CommonDialog1.FileName For Output As #1
Print #1,
TextBox1.text
Close#1
Exit Sub
To Obtain More Details View This video