Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > simple code help


Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2003, 03:42 PM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default simple code help


Code:
Private Sub Command1_Click() Select Case Text1.Text Case Is < 13 Label1.Caption = "too young" Case 13 To 19 Label1.Caption = " teenager" Case Else Label1.Caption = "old" End Select End Sub

for some reson if i enter 5 it shows up as old????
Reply With Quote
  #2  
Old 02-25-2003, 03:55 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Because Text1.Text is a string and you are treating it like an integer... use
Select Case Val(Text1.Text)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 02-25-2003, 03:58 PM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default

so what exactly does that code u give do? that is differant sorry about this
Reply With Quote
  #4  
Old 02-25-2003, 03:59 PM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default

also when i enter a letter i get the to young result is there a way to avoid this?
Reply With Quote
  #5  
Old 02-25-2003, 04:05 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Val(Text1.Text) gets the value located in the Textbox.
If the textbox has "35" as a string, Val() returns 35 as a number.

If the textbox has "5eoinfor...etc.", Val() returns 5.

If the textbox has "Hello", Val() returns 0.

For the too young idea, you'd want to check using the IsNumeric function.
The IsNumeric function will return a Boolean if the stuff inside of a string can be expressed as a number
IsNumeric("1004") = True
ISNumeric("Hello") = False
IsNumeric("3.1415926") = True
IsNumeric("3.1415abcde") = False
If IsNumeric(Text1.Text) Then
Select Case Val(Text1.Text)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #6  
Old 02-26-2003, 03:06 AM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default

thanks very much you helped me loads thanks :-)
Reply With Quote
  #7  
Old 02-26-2003, 05:51 AM
xmcnuggetx xmcnuggetx is offline
Regular
 
Join Date: Oct 2002
Posts: 86
Default

Game programming?

Sounds like an assignment to me ;p
Reply With Quote
  #8  
Old 02-26-2003, 01:20 PM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default

asignment for what lol???
Reply With Quote
  #9  
Old 02-26-2003, 01:21 PM
Squidge Squidge is offline
Restricted
 
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872
Default

i only15 and take no programming corses at scholl or colage! i was loking at an alternate to the if statements which are annoying me
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->