Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Vb question using select

Thread Tools
 
Search this Thread
 
Old 26 September 2002, 06:50 PM
  #1  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Dim ans As Integer

Private Sub cmdcalc_Click()
ans = Val(txtage.Text)
Select Case ans
Case 0 - 16
lblcost1.Caption = "2"
Case 17 - 54
lblcost1.Caption = "3"
Case 55 - 80
lblcost1.Caption = "4"
Case 81 - 200
lblcost1.Caption = "5"
Case Else
lblcost1.Caption = "error"
lbltype2.Caption = "error"
MsgBox "Please correct the age"

End Select
lbltrace.Caption = Str$(ans)
End Sub

Private Sub cmdExit_Click()
End
End Sub

ive got this.

it doesnt seem to want to know the case statement. I think ive done it right. its just alittle college task. Ive used MSDN libabrys but hasnt shed any light cheers

Si
Old 26 September 2002, 08:08 PM
  #2  
Belf
Scooby Regular
 
Belf's Avatar
 
Join Date: Apr 2002
Posts: 41
Likes: 0
Received 0 Likes on 0 Posts
Post

The compiler is evaluating your different case conditions when it compiles. So for Case 0 - 16 it is calculating 0-16 = -16 and what it is actually testing for is Case -16. Enter a age of -16 in when you run the program and you'll see the code in the first case statement get run. Like wise it is doing similar for all the other Case statments. Any proper age you enter will just fall through to Case else. You could use something like 'Case 1,2,3,4,5,6' etc. What your trying to do isn't really suited to a Select Case statement, use if, if else, and else instead.
Old 26 September 2002, 08:11 PM
  #3  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Cheers mate but it specifcally says use a select case statement.

Personally id use a list or combo rather then having to input an age!!

says in notes i can use
case
case 1-2
case 1,2,3,4
case "fred"

and thats out the book ive trace coded so know the right value is in age. So im stumpted!

Si
Old 26 September 2002, 08:22 PM
  #4  
nkh
Scooby Regular
 
nkh's Avatar
 
Join Date: May 2002
Posts: 633
Likes: 0
Received 0 Likes on 0 Posts
Post

Don't have a copy of VB laying around to test this but have you tried the IS keyword?

Select Case Day
Case is > 15
txt.Txt = "Bills are past Due"
Case is > 10
txt.Txt = "Pay up"
End Select

Any help?
Old 26 September 2002, 08:26 PM
  #5  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

sort of!

the overlaps are

0-16
17-54
55-81
82+

its ****ty little if x = b then Junior member rubbish
Private Sub cmdcalc_Click()
ans = Val(txtage.Text)
Select Case ans

Case Is < 16
lblcost1.Caption = "<16"

Case Is > 16 < 54
lblcost1.Caption = ">16 <54"

Case Is > 55 < 80
lblcost1.Caption = ">55 <80"

Case Is > 81
lblcost1.Caption = ">80"
End Select
lbltrace.Caption = Str$(ans)
End Sub
New code works for the 1st two. Fails on the 3rd and 4th case!

Si

[Edited by super_si - 9/26/2002 8:28:53 PM]
Old 26 September 2002, 08:30 PM
  #6  
nkh
Scooby Regular
 
nkh's Avatar
 
Join Date: May 2002
Posts: 633
Likes: 0
Received 0 Likes on 0 Posts
Post

From VBA help pages for Access



So you need to rather than -

edited for picture URL

[Edited by nkh - 9/26/2002 8:31:27 PM]
Old 26 September 2002, 08:34 PM
  #7  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

pint to that guy

What did you search for?

I checked MSDN online and only came up with an example of the string based select cheers mate

Si

Trending Topics

Old 26 September 2002, 08:37 PM
  #8  
nkh
Scooby Regular
 
nkh's Avatar
 
Join Date: May 2002
Posts: 633
Likes: 0
Received 0 Likes on 0 Posts
Post

>>pint to that guy

I am not a guy as I have mentioned before...

>>What did you search for?

At the top of my post I said I used the standard microsoft help in MS Access VBA...

Can you read help pages? Do you remember anything beyond your own nose?

Old 26 September 2002, 08:39 PM
  #9  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Sorry for not minding reading.

Sorry for not spotting the page within the other 100 pages listed.

thanks anyway....

[Edited by super_si - 9/26/2002 8:40:11 PM]
Old 26 September 2002, 08:41 PM
  #10  
nkh
Scooby Regular
 
nkh's Avatar
 
Join Date: May 2002
Posts: 633
Likes: 0
Received 0 Likes on 0 Posts
Post

That's OK, glad to have been of help
Old 26 September 2002, 08:50 PM
  #11  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Ill be back soon hehehe programming some graphics interface soon
and on Dimensional arrays, reading on files too........
Old 26 September 2002, 09:21 PM
  #12  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

back hehehe.

ive got to do times tables 1 to user specifys!
For i = 1 To 10
lblanswer.Caption = "1"
Next i

prints 1 and thats it!

Anything to do with print Multiple lines to a label?

Thanks again.

Si
Old 26 September 2002, 10:06 PM
  #13  
nkh
Scooby Regular
 
nkh's Avatar
 
Join Date: May 2002
Posts: 633
Likes: 0
Received 0 Likes on 0 Posts
Post

This works for me in access

Private Sub Command1_Click()
Dim i As Integer

Label0.Caption = ""
For i = 1 To 10
Label0.Caption = Label0.Caption & Chr(13) & Chr(10) & i
Next i
End Sub

Chr(13) is a carriage return character
Chr(10) is a linefeed character

In combination they create a newline.

Does that help?
Old 26 September 2002, 10:13 PM
  #14  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

i was using + instead the & sign he he he. I was close!

Si
Old 27 September 2002, 08:35 AM
  #15  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

Honestly si, this isn't a dig, but your first point of call really should be the help system otherwise you're going to find yourself shafted sometime when you can't get on here, or people just give up

The big secret of being a PC whizz is to know where to get the answers you need. It'll make you appear God-like.

Cheers,

Nick.
Old 27 September 2002, 09:00 AM
  #16  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

No MSDN cd's Uni never supplied them. i used the online .vb net stuff but didnt shed much light

Si
Old 27 September 2002, 09:12 AM
  #17  
dsmith
Scooby Regular
 
dsmith's Avatar
 
Join Date: Mar 1999
Posts: 4,518
Likes: 0
Received 0 Likes on 0 Posts
Post

The big secret of being a PC whizz is to know where to get the answers you need. It'll make you appear God-like.
So very very true.
Old 27 September 2002, 09:39 AM
  #18  
IWatkins
Scooby Regular
 
IWatkins's Avatar
 
Join Date: Mar 2000
Location: Gloucestershire, home of the lawnmower.
Posts: 4,531
Likes: 0
Received 0 Likes on 0 Posts
Post

... when interviewing, this is the thing (almost above all others) that I look for.
Old 27 September 2002, 09:51 AM
  #19  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

The full MSDN is available on-line. Given that this is overwhelming, try this.

Old 27 September 2002, 12:43 PM
  #20  
Crispin
Scooby Regular
 
Crispin's Avatar
 
Join Date: Jan 2001
Posts: 534
Likes: 0
Received 0 Likes on 0 Posts
Post

GROUPS.GOOGLE.COM


WWW.VBFORUMS.COM


WWW.VBWEB.CO.UK

Just a couple Si - seriously m8 you will find your answers quicker by searching sites like these than you will by asking here. (no offence ppl)

BTW lblname.Caption = lblname.caption & "TEXTHERE" & VbCrLf & "TEXT2" & vbcrlf & "TEXT3"
Old 27 September 2002, 01:23 PM
  #21  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

cheers all
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Abx
Subaru
22
09 January 2016 05:42 PM
Frizzle-Dee
Essex Subaru Owners Club
13
01 December 2015 09:37 AM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
Phil3822
ICE
3
26 September 2015 07:12 PM



Quick Reply: Vb question using select



All times are GMT +1. The time now is 09:46 AM.