martin2k

Home | Forums | Visual Basic 6.0 | Games | Web Directory | Software | HTML | Wiki | Blog | Contact

Using selection in your visual basic program


Home Read and add posts to the Visual Basic 6.0 Forums Download some of my programs and OCXs Read the Tips here The old style forum is still available here Contact

Back


From: sarah E-mail: shakingmyass@hotmail.com 1

Date: Sunday, October 21, 2001 at 20:25:21

Subject: Using selection in your visual basic program

Comments:

I just started to learn vb6.0.
I have to write a simple program where, the user type in their age and depending on their age a message appears. Either saying "time to retire" if you are older than 65, or keep on working if your age is below 65.
I'm getting stuck on how you code the if and else statement.
This is what I have done so far.

private sub cmdmessage_click()
Dim age as integer
if
age >65 then
txtage.text="time to retire"
else
txtage.text="keep on working"
end if
end sub

My code above don't seem to work because any number i press it display keep on working.
Could you please help me?
Thanks.

From: Martin Allen E-mail: <No e-mail> 2

Date: Monday, October 22, 2001 at 20:36:46

Subject: RE: Using selection in your visual basic program

Comments:

After you declare the variable using the 'Dim' statement, you need to give the variable a value.  After the second line, insert the following code:

age = txtNumber.Text

Where txtNumber is the name of the textbox where the user enters the number.  If you do not put this line in, the program will not know what the value of the 'age' variable is.


This forum is no longer taking new messages or replies since 01 November 2002.  The above material is for reference purposes only.

The new Visual Basic 6.0 forum can be found here.


Martin Allen 1999 - 2003.  Last updated Monday 12 May 2003 08:09:33 PM +0100.