Loop structures allow you to execute one or more lines of code repetitively. VB.Net support the following loop statements:
- Do.....loop
- While.....End While
- For.......Next
The use any one below mentioned code on the click event of the button.
1 . Private Sub
BtnFind_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
BtnFind.Click
Dim
num1, num2 As Integer
If
Val(txtfirst.Text) Mod 2 = 0 Then
num1 = Val(txtfirst.Text) + 1
Else
num1 = Val(txtfirst.Text)
End If
num2 = Val(txtlast.Text)
Do While num1 < num2
ListBox1.Items.Add(num1)
num1 = num1 + 2
Loop
End Sub
2 . Dim num1, num2 As
Integer
If
Val(txtfirst.Text) Mod 2 = 0 Then
num1 = Val(txtfirst.Text) + 1
Else
num1 = Val(txtfirst.Text)
End If
num2 = Val(txtlast.Text)
Do Until num1 > num2
ListBox1.Items.Add(num1)
num1 = num1 + 2
Loop
3 . Dim num1, num2 As
Integer
If
Val(txtfirst.Text) Mod 2 = 0 Then
num1 = Val(txtfirst.Text) + 1
Else
num1 = Val(txtfirst.Text)
End If
num2 = Val(txtlast.Text)
For
num1 = num1 To num2 Step
2
ListBox1.Items.Add(num1)
Next
No comments:
Post a Comment