PC Review


Reply
Thread Tools Rate Thread

2 comparison operators in select case at same level without loss in precision

 
 
rd
Guest
Posts: n/a
 
      27th Jul 2007
Hi,

I am not an expert programmer. I want to know if it is possible to use two
comparison operators in a select case statement, at the same level? I want
the code in a UDF function to test whether a certain ratio falls between 2
values, say, 30<x<=40, if it does the function returns a value ; otherwise,
it should test for next higher level 40<x<=50, etc.

Using If...Then...Else code, the UDF looks like this:

Public Function SlidingCommission(pLossRatio As Single) As Single

If pLossRatio <= 0.50 Then
SlidingCommission = 0.275 'Maximium Commission is 27.50%
ElseIf pLossRatio > 0.50 And pLossRatio <= 0.6 Then
SlidingCommission = 0.22
ElseIf pLossRatio > 0.6 And pLossRatio <= 0.7 Then
SlidingCommission = 0.175 .
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      27th Jul 2007
Hi,

This will give the accuracy you require:-

If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("A1:A30")) Is Nothing Then
Select Case Target.Value
Case Is > 0.6
SlidingCommission = 0.175
Case Is > 0.5
SlidingCommission = 0.22
Case Is > 0
SlidingCommission = 0.275
End Select
End If
Target.Offset(0, 1).Value = SlidingCommission
End Sub

Mike

"rd" wrote:

> Hi,
>
> I am not an expert programmer. I want to know if it is possible to use two
> comparison operators in a select case statement, at the same level? I want
> the code in a UDF function to test whether a certain ratio falls between 2
> values, say, 30<x<=40, if it does the function returns a value ; otherwise,
> it should test for next higher level 40<x<=50, etc.
>
> Using If...Then...Else code, the UDF looks like this:
>
> Public Function SlidingCommission(pLossRatio As Single) As Single
>
> If pLossRatio <= 0.50 Then
> SlidingCommission = 0.275 'Maximium Commission is 27.50%
> ElseIf pLossRatio > 0.50 And pLossRatio <= 0.6 Then
> SlidingCommission = 0.22
> ElseIf pLossRatio > 0.6 And pLossRatio <= 0.7 Then
> SlidingCommission = 0.175 .
> .
> .
> End If
> End Function
>
> My question is: can a select case be used instead of the If...Then...Else
> code without losing precsion.
>
> You input is greatly appreciated.
>
> RD
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison performance - String.compare vs Select Case =?Utf-8?B?UkpC?= Microsoft VB .NET 2 12th Nov 2004 10:50 PM
Using SELECT...CASE with comparison operators? Toby Erkson Microsoft Excel Programming 7 14th Jul 2004 09:52 PM
Comparison Operators Carlo Microsoft VB .NET 3 26th Feb 2004 02:00 PM
Comparison Operators J Jones Microsoft VB .NET 2 24th Dec 2003 09:03 AM
Using logical operators in a Select Case Statement Mota Microsoft Access Form Coding 3 4th Jul 2003 05:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:58 PM.