Programmers

They could change the world,., You too,..

Accuracy

A good application needs accurate datas,..

Controlling

A good application needs ability to control business flow.,,

Visual Basic 6.0 Form

Forms for entry the datas,..

Reports

The goal of a application show the reports of business datas,..

Contact Form

Name

Email *

Message *

Showing posts with label Procedure. Show all posts
Showing posts with label Procedure. Show all posts

Friday, September 27, 2013

Select Case procedure in Visual Basic 6.0

Select...Case structure is an alternative to If...Then...Else. It  for selectively executing a single block of statements from among multiple block of statements. Select...case is more convenient to use than the If...Else...End If. The following program block illustrate the working of Select...Case.
Syntax of the Select...Case selection structure:



Select Case Index
     Case 0
           Statements 1
     Case 1
           Statements 2

End Select


e.g.: Assume you have to find the grade using select...case and display in the text box
Dim average as Integer
---

Private Sub Cmd_Click(Index As Integer)

  Select Case Index
     Case 0
           Call save
     Case 1
           Call delete
  End Select

End Sub
---

If..Then..Else procedure in Visual Basic 6.0

Control Statements are used to control the flow of program's execution. Visual Basic supports control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such as Do While...Loop, While...Wend, For...Next etc method.

If...Then selection structure

The If...Then selection structure performs an indicated action only when the condition is True; otherwise the action is skipped.
Syntax of the If...Then selection

If <condition> Then
      statement
End If
e.g.: 
---
If average>75 Then
     txtGrade.Text = "A"
End If

---

If...Then...Else selection structure

The If...Then...Else selection structure allows the programmer to specify that a different action is to be performed when the condition is True than when the condition is False.

Syntax of the If...Then...Else selection

If <condition > Then
     statements 1
Else
     statements 2
End If
e.g.: 
---
If average>50 Then
       txtGrade.Text = "Pass"
Else
       txtGrade.Text = "Fail"
End If

Nested If...Then...Else selection structure

Nested If...Then...Else selection structures test for multiple cases by placing If...Then...Else selection structures inside If...Then...Else structures.
Syntax of the Nested If...Then...Else selection structure
You can use Nested If either of the methods as shown above

Method 1
If < condition 1 > Then
        statements 1
ElseIf < condition 2 > Then
        statements 2
ElseIf < condition 3 > Then
        statements 3
Else
        statements 4
End If
Method 2
If < condition 1 > Then
     statements
Else
     If < condition 2 > Then
            statements
      Else
            If < condition 3 > Then
                    statements
            Else
                    statements
            End If
      End If
End If
e.g.:

Assume you have to find the grade using nested if and display in a text box
---
If average > 75 Then
      txtGrade.Text = "A"
ElseIf average > 65 Then
      txtGrade.Text = "B"
ElseIf average > 55 Then
      txtGrade.Text = "C"
ElseIf average > 45 Then
      txtGrade.Text = "S"
Else
      txtGrade.Text = "F"

End If
---