473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Displaying odd/even numbers in label.caption

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
1 7587
Guido Geurs
767 Expert 512MB
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

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

Similar topics

3
by: Pavan Arise | last post by:
Hi all.. This may seem simple..but I am stuck here! I have a frame in which I have a label. I was trying to change the caption of that label via code (I mean at runtime & not design time). But...
3
by: Jan E Andersen | last post by:
Is there an option for this It woul certainly make debugging much easier JE
4
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption =...
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
4
by: ghostrider | last post by:
I ned help in figuring out to make my program display even numbers only. My for loop counts every number, but I only need to display the even ones. Can someone help me with this?
6
by: devoreband | last post by:
hey i wrote all my code but i need to print out only the even numbers so is there any predefined function i can use or what can structure i should be following? ........ 16 for(int r = 0;...
2
by: webbi | last post by:
I have a text box called txtAttirubte1 and an update button in FormA. I want to update the label caption for all label name Attribute1_Lable in FormB and FormC with the WORD I type in the FormA text...
1
by: zion | last post by:
Hello, How can I change label caption on page load ? Thanks
2
by: colordrm88 | last post by:
Here is what I am supposed to do...Write a C++ program that asks for 10 numbers and prints the sum of only the even numbers. I also have to use an if statement and a while loop. Please please...
4
by: Annie Bender | last post by:
Wow, I finally got through my first VB "tutorial" project and everything works nice, except one userform label caption will only display as long as the Excel column it draws data from is set wide...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.