473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

multiple markups



-if the Subtotal is equal to or less than 25000, multiply subtotal by
12%, if not set to 0
- If the Subtotal is greater than 25000 but less than or equal to
10000, multiply subtotal by 10%, if not set to 0
- f the Subtotal is greater than 10000, multiply subtotal by 7%, if not
set to 0

Total=Subtotal+(one of the values above)

Can anyone help, i must be writing the expressions incorrectly????

Oct 20 '06 #1
8 1432
dynomite wrote:
>
-if the Subtotal is equal to or less than 25000, multiply subtotal by
12%, if not set to 0
- If the Subtotal is greater than 25000 but less than or equal to
10000, multiply subtotal by 10%, if not set to 0
- f the Subtotal is greater than 10000, multiply subtotal by 7%, if not
set to 0

Total=Subtotal+(one of the values above)

Can anyone help, i must be writing the expressions incorrectly????
I'll assume you meant 100,000, not 10,000.

Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function

Total=Subtotal+GetTotal(SubTotal)
Oct 20 '06 #2
you can do something like this:

select sum(amount) As Total, IIf(sum(amount) 100000, sum(amount) *
.07, IIf(sum(amount) >= 25000, sum(amount) * .1, sum(amount) * .12) As
TotalPercent, Total + TotalPercent As TotalAndPecent From table1

The statement uses the immediate If (IIf) statement and nests additional
IIfs so that the statement is really saying this:

If sum(amount) 100000 then
result = sum(amount) * .07
ElseIf sum(amount) >= 25000 Then
result = sum(amount) * .1
Else
result = sum(amount) * .12
End If

So the first field of the query above "Total" displays sum(amount), the
next fields "TotalPercent" displays the assigned percentage of
sum(amount) * ?, and the last field "TotalAndPercent" displays the sum
of Total And TotalPercent. Note: this is the Access version. In sql
server you would use a Case statement.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Oct 20 '06 #3
salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas.eart hlink.net:
Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function
Naturally, for your function declaration you meant:

Public Function GetTotal(SubTotal As Variant) As Currency

because without it, it's completely invalid (parameter types have to
be declared).

I also never declare variables in the middle of code. I used to, on
the theory that if you don't need a variable, declaring it only when
you need it would use less memory. But the memory involved would be
so tiny, seems to me, that it's not justified given the problems it
causes in searching for the variable declarations for someone
reading the code later.

Also, your terminology is confusing. What you're calculating is the
amount to be added to the subtotal, as the OP asked:
Total=Subtotal+(one of the values above)
You're providing the value indicated by "(one of the values above)",
so calling it "GetTotal" is misleading, as what you're getting is
the percent of markup or commission or tax or whatever.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 20 '06 #4
salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas.eart hlink.net:
Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function
In a query you could do this without a function with this:

SubTotal + (SubTotal *
IIf(SubTotal<=25000,.12,IIf(SubTotal<=100000,.1,.0 7)))

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 20 '06 #5
David W. Fenton wrote:
salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas.eart hlink.net:

>>Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function


Naturally, for your function declaration you meant:

Public Function GetTotal(SubTotal As Variant) As Currency

because without it, it's completely invalid (parameter types have to
be declared).
Really? I was under the impression if you don't declare the type, it is
a variant. Ex:
Public Function Sum2Vars(var1, var2) As Integer
Sum2Vars = var1 + var2
End Function
? Sum2Vars(1,2)
3

I always explicitly define the type in my apps, but I wasn't aware it
was mandatory.
>
I also never declare variables in the middle of code. I used to, on
the theory that if you don't need a variable, declaring it only when
you need it would use less memory. But the memory involved would be
so tiny, seems to me, that it's not justified given the problems it
causes in searching for the variable declarations for someone
reading the code later.
For the most part, neither do I. In this case, I view it as an example
that works and won't get perturbed by putting a Dim inside the IF.

Sometimes I will read something someone is doing that I consider a bit
radical...not a normal way of doing things...but I will rarely question
why they are going down that path...I'll simply pass a response back
that hopefully works for the person. I suppose I could berate the
person for their stupidity for doing it a particular way...but I'm not
that judgemental. As a manager once said, "An ugly program that works
is preferable to an pretty one that doesn't."
>
Also, your terminology is confusing. What you're calculating is the
amount to be added to the subtotal, as the OP asked:

>>Total=Subtotal+(one of the values above)


You're providing the value indicated by "(one of the values above)",
so calling it "GetTotal" is misleading, as what you're getting is
the percent of markup or commission or tax or whatever.
You are correct. Next time I write this function for someone on this
newsgroup I will call it AddToTotal.
Oct 20 '06 #6
salad <oi*@vinegar.comwrote in
news:fp******************@newsread4.news.pas.earth link.net:
David W. Fenton wrote:
>salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas.ear thlink.net:

>>>Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function

Naturally, for your function declaration you meant:

Public Function GetTotal(SubTotal As Variant) As Currency

because without it, it's completely invalid (parameter types have
to be declared).

Really? I was under the impression if you don't declare the type,
it is a variant. Ex:
Public Function Sum2Vars(var1, var2) As Integer
Sum2Vars = var1 + var2
End Function
? Sum2Vars(1,2)
3

I always explicitly define the type in my apps, but I wasn't aware
it was mandatory.
Well, just try it. While one can declare variables implicitly, as
you say, in function/subroutine declarations, it won't compile. It
gives an error as soon as you leave the declaration line (i.e., the
precompile check for validity).
>I also never declare variables in the middle of code. I used to,
on the theory that if you don't need a variable, declaring it
only when you need it would use less memory. But the memory
involved would be so tiny, seems to me, that it's not justified
given the problems it causes in searching for the variable
declarations for someone reading the code later.

For the most part, neither do I. In this case, I view it as an
example that works and won't get perturbed by putting a Dim inside
the IF.

Sometimes I will read something someone is doing that I consider a
bit radical...not a normal way of doing things...but I will rarely
question why they are going down that path...I'll simply pass a
response back that hopefully works for the person. I suppose I
could berate the person for their stupidity for doing it a
particular way...but I'm not that judgemental. As a manager once
said, "An ugly program that works is preferable to an pretty one
that doesn't."
But a pretty program that also works is better than either of those.

My concern here is maintainability of the code. The code will be
read many more times than it will be written, and shortcuts in the
coding process itselve often make maintenance of that code much
harder.

I try to code so that another programmer coming to the code sometime
in the future will be able to understand the code at a glance, with
a minimum of poking around to figure out where the variables are
declared. One thing I've started doing more is not using
module-level variables for things being looked up and used in
functions. Instead I use Static variables within the functions. If
the value of the variable has to be assigned, I'll use a
module-level private variable and a property Let/Get. The whole
reason for this is to cut down on the use of global and public
module-level variables so that the values can be much more easily
controlled.

Sure, not doing it that way can work, but having these strict
restrictions produces code that is less prone to being accidentally
misused, and is thus easier to maintain in the long run.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 21 '06 #7
David W. Fenton wrote:
salad <oi*@vinegar.comwrote in
news:fp******************@newsread4.news.pas.earth link.net:

>>David W. Fenton wrote:
>>>salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas.e arthlink.net:

Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
End Function

Naturally, for your function declaration you meant:

Public Function GetTotal(SubTotal As Variant) As Currency

because without it, it's completely invalid (parameter types have
to be declared).

Really? I was under the impression if you don't declare the type,
it is a variant. Ex:
Public Function Sum2Vars(var1, var2) As Integer
Sum2Vars = var1 + var2
End Function
? Sum2Vars(1,2)
3

I always explicitly define the type in my apps, but I wasn't aware
it was mandatory.

Well, just try it. While one can declare variables implicitly, as
you say, in function/subroutine declarations, it won't compile. It
gives an error as soon as you leave the declaration line (i.e., the
precompile check for validity).
I did compile and save the above Sum2Vars function....A97 Works fine.
Does it not compile in later versions?
>>>I also never declare variables in the middle of code. I used to,
on the theory that if you don't need a variable, declaring it
only when you need it would use less memory. But the memory
involved would be so tiny, seems to me, that it's not justified
given the problems it causes in searching for the variable
declarations for someone reading the code later.

For the most part, neither do I. In this case, I view it as an
example that works and won't get perturbed by putting a Dim inside
the IF.

Sometimes I will read something someone is doing that I consider a
bit radical...not a normal way of doing things...but I will rarely
question why they are going down that path...I'll simply pass a
response back that hopefully works for the person. I suppose I
could berate the person for their stupidity for doing it a
particular way...but I'm not that judgemental. As a manager once
said, "An ugly program that works is preferable to an pretty one
that doesn't."

But a pretty program that also works is better than either of those.

My concern here is maintainability of the code. The code will be
read many more times than it will be written, and shortcuts in the
coding process itselve often make maintenance of that code much
harder.

I try to code so that another programmer coming to the code sometime
in the future will be able to understand the code at a glance, with
a minimum of poking around to figure out where the variables are
declared. One thing I've started doing more is not using
module-level variables for things being looked up and used in
functions. Instead I use Static variables within the functions. If
the value of the variable has to be assigned, I'll use a
module-level private variable and a property Let/Get. The whole
reason for this is to cut down on the use of global and public
module-level variables so that the values can be much more easily
controlled.

Sure, not doing it that way can work, but having these strict
restrictions produces code that is less prone to being accidentally
misused, and is thus easier to maintain in the long run.
Interesting. About the only place I use Global variables, application
wide, is in WinAPI calls...like you see at mvps.org and sometimes in
Form modules. In forms, I may also create a control to stuff data and
make them invisible.
Oct 21 '06 #8
salad <oi*@vinegar.comwrote in
news:GU******************@newsread1.news.pas.earth link.net:
David W. Fenton wrote:
>salad <oi*@vinegar.comwrote in
news:fp******************@newsread4.news.pas.eart hlink.net:

>>>David W. Fenton wrote:

salad <oi*@vinegar.comwrote in
news:Ms*******************@newsread2.news.pas. earthlink.net:

>Public Function GetTotal(SubTotal) As Currency
If Not IsNull(SubTotal) Then
Dim curPercent As Currency
Select Case SubTotal
Case Is <= 25000
curPercent = .12
Case Is <= 100000
curPercent = .1
Case Else
curPercent = .07
End Select
GetTotal = SubTotal * curPercent
Endif
>End Function

Naturally, for your function declaration you meant:

Public Function GetTotal(SubTotal As Variant) As Currency

because without it, it's completely invalid (parameter types
have to be declared).

Really? I was under the impression if you don't declare the
type, it is a variant. Ex:
Public Function Sum2Vars(var1, var2) As Integer
Sum2Vars = var1 + var2
End Function
? Sum2Vars(1,2)
3

I always explicitly define the type in my apps, but I wasn't
aware it was mandatory.

Well, just try it. While one can declare variables implicitly, as
you say, in function/subroutine declarations, it won't compile.
It gives an error as soon as you leave the declaration line
(i.e., the precompile check for validity).

I did compile and save the above Sum2Vars function....A97 Works
fine. Does it not compile in later versions?
Well, what do you know. It compiles now. When I cut and pasted it
before it wouldn't compile, and I have no idea why.

In any event, *not* declaring parameter types is terrible
programming practice even when the implicit typing is the same as
the explicit (i.e., it will be a variant).

I thought I'd just cut and pasted, but apparently I was typing and
not typing the same thing. I did it twice, once in response to the
first post, the second time in response to the above post.

I wonder what I was doing wrong? :)
>>>>I also never declare variables in the middle of code. I used to,
on the theory that if you don't need a variable, declaring it
only when you need it would use less memory. But the memory
involved would be so tiny, seems to me, that it's not justified
given the problems it causes in searching for the variable
declarations for someone reading the code later.

For the most part, neither do I. In this case, I view it as an
example that works and won't get perturbed by putting a Dim
inside the IF.

Sometimes I will read something someone is doing that I consider
a bit radical...not a normal way of doing things...but I will
rarely question why they are going down that path...I'll simply
pass a response back that hopefully works for the person. I
suppose I could berate the person for their stupidity for doing
it a particular way...but I'm not that judgemental. As a manager
once said, "An ugly program that works is preferable to an pretty
one that doesn't."

But a pretty program that also works is better than either of
those.

My concern here is maintainability of the code. The code will be
read many more times than it will be written, and shortcuts in
the coding process itselve often make maintenance of that code
much harder.

I try to code so that another programmer coming to the code
sometime in the future will be able to understand the code at a
glance, with a minimum of poking around to figure out where the
variables are declared. One thing I've started doing more is not
using module-level variables for things being looked up and used
in functions. Instead I use Static variables within the
functions. If the value of the variable has to be assigned, I'll
use a module-level private variable and a property Let/Get. The
whole reason for this is to cut down on the use of global and
public module-level variables so that the values can be much more
easily controlled.

Sure, not doing it that way can work, but having these strict
restrictions produces code that is less prone to being
accidentally misused, and is thus easier to maintain in the long
run.
Interesting. About the only place I use Global variables,
application wide, is in WinAPI calls...like you see at mvps.org
and sometimes in Form modules. In forms, I may also create a
control to stuff data and make them invisible.
Public/global constants are fine. It's variables whose values can be
changed that don't belong at the global level.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 21 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
4
by: Wladimir Borsov | last post by:
Ok, think of let say 10 different web pages on the internet. Each of them are usual html web pages. Nothing special. What I want to do now is to create a new meta resp. grouping web page which...
3
by: rdemyan via AccessMonster.com | last post by:
My app contains data on projects. I've recently added functionality to allow for markups on a base cost. The code currently applies any markup to the base cost only. However, in reality, some...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
3
by: jackson.rayne | last post by:
Hello, Another newbie question here. Let me explain my situation first. I have bought a 3rd party tool that runs a PHP script and gives me some HTML code which I can directly use in my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.