Friday, July 13, 2012

Sample Program #5















Let us create a program that will count base on the given start and end value using the different types of loop.


'USING FOR LOOP
Private Sub cmdcal_Click()
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)
 
  For c = a To b
    txtsum.Text = txtsum.Text + Trim(Str(c)) + " "
  Next c
End Sub
  
'USING DO LOOP UNTIL
Private Sub cmdcal_Click()  
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)
 
  Do
    txtsum.Text = txtsum.Text + Trim(Str(a)) + " "
    a = a + 1
  Loop Until (a > b)
End Sub 

  
'USING DO LOOP WHILE
Private Sub cmdcal_Click()  
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)

  Do
    txtsum.Text = txtsum.Text + Trim(Str(a)) + " "
    a = a + 1
  Loop While (a <= b)
End Sub


'USING DO WHILE LOOP
Private Sub cmdcal_Click()  
  Dim a, b, c As Integer
 
  a = Val(txtn1.Text)
  b = Val(txtn2.Text)
  Do While (a <= b)
    txtsum.Text = txtsum.Text + Trim(Str(a)) + " "
    a = a + 1
  Loop
End Sub