Discussions

Friday, July 13, 2012

Sample Program #4


 













Let us create a program that will evaluate the smallest and the largest number from the three given inputs. We will enhance our condition using the AND and OR operators. In this example, we will use only AND.


Private Sub cmdcal_Click()
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)
  c = Val(txtn3.Text)
 
  If (a < b) And (a < c) Then
    txtsum.Text = "The smallest number is " + Trim(Str(a))
  ElseIf (b < a) And (b < c) Then
    txtsum.Text = "The smallest number is " + Trim(Str(b))
  Else
    txtsum.Text = "The smallest number is " + Trim(Str(c))
  End If
 
  If (a > b) And (a > c) Then
    txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(a))
  ElseIf (b > a) And (b > c) Then
    txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(b))
  Else
    txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(c))
  End If
End Sub

'ANOTHER METHOD STYLE CODE
Private Sub cmdcal_Click()
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)
  c = Val(txtn3.Text)
 
  If (a < b) And (a < c) Then
    txtsum.Text = "The smallest number is " + Trim(Str(a))
    If (b > c) Then
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(b))
    Else
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(c))
    End If
  ElseIf (b < a) And (b < c) Then
    txtsum.Text = "The smallest number is " + Trim(Str(b))
    If (a > c) Then
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(a))
    Else
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(c))
    End If
  Else
    txtsum.Text = "The smallest number is " + Trim(Str(c))
    If (b > a) Then
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(b))
    Else
      txtsum.Text = txtsum.Text + " and the largest is " + Trim(Str(a))
    End If
  End If
End Sub