By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

Displaying odd/even numbers in label.caption

P: n/a
hi guys,

i'm creating a program that instead of using the print method to display the odd/even numbers, i want to display the result in label.caption. Im crazy about it, please help me.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEven_Click()
  2.     Dim x As Integer
  3.     Dim intReturn As Integer
  4.     If txtNum = "" Then
  5.         intReturn = MsgBox("enter a number!",  vbExclamation + vbOKOnly)
  6.     End If
  7.     x = Val(txtNum.Text)
  8.     For x = 0 To x Step 2
  9.     'Print x
  10.     lblOutput.Caption = x & Space$(2)
  11.     Next
  12.  
  13. End Sub
  14.  
  15. Private Sub cmdOdd_Click()
  16.     Dim x As Integer
  17.     Dim intReturn As Integer
  18.     If txtNum = "" Then
  19.         intReturn = MsgBox("enter a number!",  vbExclamation + vbOKOnly)
  20.     End If
  21.     x = Val(txtNum.Text)
  22.     For x = 1 To x Step 2
  23.     'Print x
  24.     lblOutput.Caption = x & Space$(2)
  25.     Next
  26.  
  27. End Sub
Oct 21 '10 #1
Share this Question
Share on Google+
1 Reply


Guido Geurs
Expert 100+
P: 767
You want all the odd or even number from 0 to TxtNum ?
In the loop You have to store the results in a string or Label.caption like:

Expand|Select|Wrap|Line Numbers
  1. lblOutput.Caption = ""
  2. For x = 1 To x Step 2 
  3.     lblOutput.Caption = lblOutput.Caption & x & Space$(2) 
  4. Next 
Oct 22 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.