How can I show the next 15 odd numbers of for example number 10 ?

Recommended Answers

All 7 Replies

Use the Mod Function to determine if input number is odd or not.
If not, add 1 to number.
Use for loop from 1 to 15 and a variable that is incremented by two with each iteration of the loop.
Take the value from the variable and concatinate into a string variable or textbox, or use the additem method of a list box to display.

Good Luck

Could you please write it i mean each steps?
coz I'm not an expert in VB

Please post your code that you are working on. Our experts will advice you to improve the same. Don't expect the complete code.

Read my reply line by line, sentence by sentence and you will have your answer as you code it up. Then as debasisdas said, if you have any problems with what you have created, then post it with where and what the error is.

Good Luck

There is no easy way if you are a beginner in the OOP way, Lida...
Yeah, you post your code and we'll see what we can do.

i think this may help you...

first, put 1 listbox(List1), 1 textbox(txtNum) and 1 command button(cmdShow)

and here's the code

Private Sub cmdShow_Click(Index As Integer)
Dim i, num As Integer

num = Val(txtNum.Text)

For i = 1 To num

If i Mod 2 = 1 Then

List1.AddItem i

End If
Next i
End Sub

Odd numbers will show on your listbox. If you want, return it with msgbox. >> Msgbox i

Well thanks everyone. I managed to solve it myself.
So here is how I did it:

Private Sub Command1_Click()
Dim x As Integer
x = Val(Text1.Text)
If x Mod 2 = 0 Then
x = x + 1
For i = 1 To 15
Print x
x = x + 2
Next i
Else
x = x + 2
For i = 1 To 15
Print x
x = x + 2
Next i
End If
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.