Select Case pulling wrong value (1 Viewer)

skwilliams

Registered User.
Local time
Today, 10:16
Joined
Jan 18, 2002
Messages
516
I have a select case statement that is pulling the wrong value.

QuSe1 is returning a value of 2.5 but it should be 3.25

Here's the code (I've put the values of each field in red and enclosed with asterisks for illustration):
Code:
Select Case Quality
    Case BiNeOs.Visible = False[COLOR="Red"]*True*[/COLOR], NeIS [COLOR="Red"]*2*[/COLOR] > 0
    QuSe1[COLOR="Red"]*2.5*[/COLOR] = ((IsRating[COLOR="Red"]*4*[/COLOR] * 0.25) + (OsRating[COLOR="Red"]*2*[/COLOR] * 0.75))
    Case BiNeOs.Visible = True[COLOR="Red"]*True*[/COLOR], NeIS [COLOR="Red"]*2*[/COLOR]> 0
    QuSe1[COLOR="Red"]*2.5*[/COLOR] = ((IsRating[COLOR="Red"]*4*[/COLOR] * 0.25) + (((BiOsRating[COLOR="Red"]*4*[/COLOR] + OsRating[COLOR="Red"]*2*[/COLOR]) / 2) * 0.75))
    Case BiNeOs.Visible = False[COLOR="Red"]*True*[/COLOR], NeIS [COLOR="Red"]*2*[/COLOR]= 0
    QuSe1[COLOR="Red"]*2.5*[/COLOR] = OsRating[COLOR="Red"]*2*[/COLOR]
    Case BiNeOs.Visible = True[COLOR="Red"]*True*[/COLOR], NeIS [COLOR="Red"]*2*[/COLOR]= 0
    QuSe1[COLOR="Red"]*2.5*[/COLOR] = (BiOsRating[COLOR="Red"]*4*[/COLOR] + OsRating[COLOR="Red"]*2*[/COLOR]) / 2
End Select

The criteria being matched are that of the 2nd select case statement, but it seems to be using the equation from the 1st select case statement.

I inserted a breakpoint and ran the code, it verified that the 2nd statement should be used based on the criteria.

Any ideas??
 

KenHigg

Registered User
Local time
Today, 10:16
Joined
Jun 9, 2004
Messages
13,327
I don't think I've ever seen a select case statement used like that. I think I would run these test through a series of if statements...
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:16
Joined
Sep 12, 2006
Messages
15,653
it must be an issue with the calc itself in the second case (although the answer returned appears to be the value from case 1 - are you sure bineos.visible is TRUE)

i would use msgboxes to break it down into sections and see how the calc is being done.

i didnt realise you could have multiple conditions in a case statement as you have done - but i guess if the compiler is not complaining, that cant be a problem.

you have already used other stuff like setting breakpoints.
 

skwilliams

Registered User.
Local time
Today, 10:16
Joined
Jan 18, 2002
Messages
516
After setting the breakpoint, it is telling me that BiNeOs is true.
 

skwilliams

Registered User.
Local time
Today, 10:16
Joined
Jan 18, 2002
Messages
516
Running into a similiar problem with another Select Case statement although not as complex as the other one.

IsRating is returning a 0 value but should be 3.5

Code:
Select Case OdEr [COLOR="Red"]*19.33*[/COLOR]
    Case 0.001 To frmISScale!a [COLOR="Red"]*13.99*[/COLOR]
    IsRating = 0
    Case frmISScale!c [COLOR="Red"]*14.00*[/COLOR] To frmISScale!b [COLOR="Red"]*15.74*[/COLOR]
    IsRating = 1
    Case frmISScale!e [COLOR="Red"]*15.75*[/COLOR] To frmISScale!d [COLOR="Red"]*17.49*[/COLOR]
    IsRating = 2
    Case frmISScale!g [COLOR="Red"]*17.5*[/COLOR] To frmISScale!f [COLOR="Red"]*19.24*[/COLOR]
    IsRating = 3
    Case frmISScale!i [COLOR="Red"]*19.25*[/COLOR] To frmISScale!h [COLOR="Red"]*20.99*[/COLOR]
    IsRating = 3.5
    Case Is >= frmISScale!j [COLOR="Red"]*21.00*[/COLOR]
    IsRating = 4
    Case Is = 0
    IsRating = 4
End Select

Ugh
 

namliam

The Mailman - AWF VIP
Local time
Today, 16:16
Joined
Aug 11, 2003
Messages
11,695
the comma used in each case is a OR not an AND...

The case is beeing used wrongly in this *erm* case...
Code:
Select Case Quality
    Case "good", "best"
    Case "Not so good", "Medium"
etc...
Is the way one "should" use a case... not the way it is done here... Instead use a IF/Then/elseif structure or even If/then/else structure....
Code:
If BiNeOs.Visible = False then
    if NeIS *2* > 0 then
    elseif NeIS *2* = 0 then
    else 
    endif
else
...
endif

Your second issue, make sure you are working with numbers, not strings...
 

Users who are viewing this thread

Top Bottom