VB6 Basics

Post on 11-Jan-2016

273 views 3 download

Tags:

description

Basic startup for VB6

transcript

1

2

MICROSOFT VISUAL BASIC 6.0

Basic Components

Key Events

Conditional Statements (If then ..Else)

Variables

Message Box/Input Box

Procedures & FunctionsASCII

Control Statements(Loops)

3

Basic Components

Label

Frame

Checkbox

Text Box

Command Button

Option Button

4

Command Button

Private Sub CMDcal_Click()<statement 1><statement 2>

End Sub

5

Text BoxLabel

6

Conditional Statements

IF CONDITION THENSTATEMENT 1

ELSESTATEMENT 2

END IF

7

Conditional Statements

IF CONDITION 1 THENstatement 1

ELSE IF CONDITION 2 THENstatement 2

ELSE IF CONDITION 3 THENstatement 3

End IF

8

KeyPress > SetFocus Event

Private Sub TXTN1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 ThenTXTN2.SetFocusEnd If

9

Setting Variables

Dim X, Y, Z As Variant

PUBLIC, LOCAL, DIM, PRIVATE

Any Number of Variables for the requirement

Variant, Integer, Byte,String

10

Setting Variables

It is not required to declare all the variables in theGENRAL DECRALARION.

Declare variables as the requirement

11

Setting Variables

It is not required to declare all the variables in theGENRAL DECRALARION.

Declare variables as the requirement

12

Message Boxes

Private Sub CMDplus_Click()

MsgBox "Testing Message Boxes", vbCritical + vbExclamation, "Warning"

End Sub

13

Message Boxes > Capturing Return Value

Private Sub CMDplus_Click()Dim x As Stringx = MsgBox("Are you sure want to exit ? ", vbYesNo

+ vbCritical, "Confirmation") If x = vbYes Then End Else CMDplus.SetFocus

End If

14

Message Boxes > Result into 2 Lines

Private Sub CMDplus_Click()MsgBox "Display Line 1" & vbCrLf & "Display

Line 2“,vbCritical + vbExclamation,"Warning"

End Sub

15

Option Button

Private Sub OptionF_Click()Label1.Caption = "Female"End Sub

Private Sub OptionM_Click()Label1.Caption = "Male"

End Sub

16

Check Boxes

Private Sub CheckMo_Click()If CheckMo.Value = 1 ThenLabel1.Caption = Val(Label1.Caption) + 10000ElseLabel1.Caption = Val(Label1.Caption) - 10000End IfEnd Sub

Private Sub CheckKey_Click()If CheckKey.Value = 1 ThenLabel1.Caption = Val(Label1.Caption) + 1500ElseLabel1.Caption = Val(Label1.Caption) - 1500End IfEnd Sub

Private Sub CheckSys_Click()If CheckSys.Value = 1 ThenLabel1.Caption = Val(Label1.Caption) + 25000ElseLabel1.Caption = Val(Label1.Caption) - 25000End IfEnd Sub

17

Check Boxes

18

Control Statements - LoopsFor LoopFor <exp1> to <exp2>

part A

next

exampleFor i=1 to 10Print “HNDE”

next

For i=1 to 10 step 2Print INext

1 3 5 7 9