nested select case

S

Slightly Befuddled

I have a sizable select module for determining points based on a number of
criteria, I am not a programmer as will be evident by the code below. The
problem is only the first Select Case statement is properly evaluated, the
rest are assigned a zero value. I have verified that the variables used for
evaluation are correctly assigned and that they have good numbers. Any help
with this is greatly appreciated.

Private Sub Command20_Click()

Dim intAge As Integer
Dim strMessage As String
Dim intTC As Integer
Dim strSmoker As String
Dim intHdl As Integer
Dim intBP As Integer
Dim strBPmed As String
Dim intpoints As Integer
Dim intRisk As Integer
Dim intAgepoint As Integer
Dim intTcPoint As Integer
Dim intSmokerPoint As Integer
Dim intHdlPoint As Integer
Dim intBpPoint As Integer


intAge = Me.PtAge
intTC = Me.TC
strSmoker = Me.Smoker
intHdl = Me.HDL
intBP = Me.SBP

'evaluate patient age and assign score
Select Case intAge
Case 1 To 19
MsgBox "you are too young"
Case 20 To 34
intAgepoint = -9
Case 35 To 39
intAgepoint = -4
Case 40 To 44
intAgepoint = 0
Case 45 To 49
intAgepoint = 3
Case 50 To 54
intAgepoint = 6
Case 55 To 59
intAgepoint = 8
Case 60 To 64
intAgepoint = 10
Case 65 To 69
intAgepoint = 11
Case 70 To 74
intAgepoint = 12
Case 75 To 79
intAgepoint = 13
Case Else
MsgBox "you are outside the range of this measurement"
End Select

'evaluate Total Cholesterol level and assign points based on age
Select Case intTC
Case Is < 160
intTcPoint = 0
Case 160 To 199
Select Case intAge
Case 20 To 39
intTcPoint = 4
Case 40 To 49
intTcPoint = 3
Case 50 To 59
intTcPoint = 2
Case 60 To 69
intTcPoint = 1
Case 70 To 79
intTcPoint = 0
Case Else
MsgBox "you are outside the range of this measurement"
End Select
Case 200 To 239
Select Case intAge
Case 20 To 39
intTcPoint = 7
Case 40 To 49
intTcPoint = 5
Case 50 To 59
intTcPoint = 3
Case 60 To 69
intTcPoint = 1
Case 70 To 79
intTcPoint = 0
Case Else
MsgBox "you are outside the range of this measurement"
End Select
Case 240 To 279
Select Case intAge
Case 20 To 39
intTcPoint = 9
Case 40 To 49
intTcPoint = 6
Case 50 To 59
intTcPoint = 4
Case 60 To 69
intTcPoint = 2
Case 70 To 79
intTcPoint = 1
Case Else
MsgBox "you are outside the range of this measurement"
End Select
Case Is >= 280
Select Case intAge
Case 20 To 39
intTcPoint = 11
Case 40 To 49
intTcPoint = 8
Case 50 To 59
intTcPoint = 5
Case 60 To 69
intTcPoint = 3
Case 70 To 79
intTcPoint = 1
Case Else
MsgBox "you are outside the range of this measurement"
End Select
End Select
MsgBox "Your TCscore is " & intTcPoint & " your inttc is " & intTC

'Determine if patient is a smoker and assign points based on age
Select Case strSmoker
Case "yes"
Select Case intAge
Case 20 To 39
intSmokerPoint = 8
Case 40 To 49
intSmokerPoint = 5
Case 50 To 59
intSmokerPoint = 3
Case 60 To 69
intSmokerPoint = 1
Case 70 To 79
intSmokerPoint = 1
Case Else
MsgBox "you are outside the range of this measurement"
End Select
Case "no"
intSmokerPoint = 0
End Select

'assign points for HDL levels
Select Case intHdl
Case Is >= 60
intHdlPoint = -1
Case 50 To 59
intHdlPoint = 0
Case 40 To 49
intHdlPoint = 1
Case Is < 40
intHdlPoint = 2
End Select

'Assign points for treated and untreated Bloodpressure
Select Case intBP
Case Is < 120
intBpPoint = 0
Case 120 To 129
Select Case strBPmed
Case "yes"
intBpPoint = 1
Case "no"
intBpPoint = 0
End Select
Case 130 To 139
Select Case strBPmed
Case "yes"
intBpPoint = 2
Case "no"
intBpPoint = 1
End Select
Case 140 To 159
Select Case strBPmed
Case "yes"
intBpPoint = 2
Case "no"
intBpPoint = 1
End Select
Case Is >= 160
Select Case strBPmed
Case "yes"
intBpPoint = 3
Case "no"
intBpPoint = 2
End Select
End Select


'Quick box to tell separate point totals, to be replaced with sum function
MsgBox "your score is " & intpoints & intBpPoint & intHdlPoint &
intSmokerPoint



End Sub
 
K

Klatuu

If you are not a programmer, you should be. The code is excellent. I don't
understand the problem. I copied you code and stepped through it in debug
mode and in every case, the correct values were returned with the exception
of intpoints. You Dim it and use it in your last message box, but it is not
referenced anywhere in your code. Try stepping through it in Debug, and let
me know what you see.
 
S

Slightly Befuddled

For some reason I am not able to step through this in debug, even if I set a
breakpoint it ignores it. Thank you for the compliment, I am having to learn
programming in a hurry so it is good to know I am on the right track.
 
K

Klatuu

Now I am befuddled as well. Can't understand why you can't debug. So are
you opening the VB Editor, clicking on a line where you want to stop then
pressing F9? It should turn color. One thing to watch for is that the line
must be an executable line, not a comment line or a Dim, or any other non
executable line. The only other thing I can think of is to put a Stop
statement where you want to begin your trace and see if you can step through
the code from there.
 
S

Slightly Befuddled

I had tried all of that to no avail, since I did not write the original
database I decided to create a blank database and import the data and
modules. Low and behold that worked. Thank you for looking at the code
though, once you said it should work I had to look outside the module for the
problem.

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top