-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???? 8 1439
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(SubTot al) 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(SubTot al)
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 "TotalPerce nt" displays the assigned percentage of
sum(amount) * ?, and the last field "TotalAndPercen t" 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 ***
salad <oi*@vinegar.co mwrote in
news:Ms******** ***********@new sread2.news.pas .earthlink.net:
Public Function GetTotal(SubTot al) 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(SubTot al 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/
salad <oi*@vinegar.co mwrote in
news:Ms******** ***********@new sread2.news.pas .earthlink.net:
Public Function GetTotal(SubTot al) 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<=2 5000,.12,IIf(Su bTotal<=100000, .1,.07)))
--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
David W. Fenton wrote:
salad <oi*@vinegar.co mwrote in
news:Ms******** ***********@new sread2.news.pas .earthlink.net:
>>Public Function GetTotal(SubTot al) 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(SubTot al 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=Subtota l+(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.
salad <oi*@vinegar.co mwrote in
news:fp******** **********@news read4.news.pas. earthlink.net:
David W. Fenton wrote:
>salad <oi*@vinegar.co mwrote in news:Ms******* ************@ne wsread2.news.pa s.earthlink.net :
>>>Public Function GetTotal(SubTot al) 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(SubTot al 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/
David W. Fenton wrote:
salad <oi*@vinegar.co mwrote in
news:fp******** **********@news read4.news.pas. earthlink.net:
>>David W. Fenton wrote:
>>>salad <oi*@vinegar.co mwrote in news:Ms***** **************@ newsread2.news. pas.earthlink.n et:
Public Function GetTotal(SubTot al) 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(SubTot al 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 declaratio ns 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.
salad <oi*@vinegar.co mwrote in
news:GU******** **********@news read1.news.pas. earthlink.net:
David W. Fenton wrote:
>salad <oi*@vinegar.co mwrote in news:fp******* ***********@new sread4.news.pas .earthlink.net:
>>>David W. Fenton wrote:
salad <oi*@vinegar.co mwrote in news:Ms**** *************** @newsread2.news .pas.earthlink. net:
>Public Function GetTotal(SubTot al) 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(SubTot al 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 declaration s 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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 examples?
|
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 contains
all the "sub" web pages. BUT: NO FRAMES should be used!!!
Instead I am thinking of a mechanism which just concatenates all the
10 different web pages and shows them as ONE page in my browser (IntExp or Firefox).
Be aware of the...
|
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 markups are on top of the base
cost + other markups. I have about 10 markups that can be applied and users
may want to change the order in which the markups are applied. Plus there
may be multiple markups that go just against the base.
Here's...
|
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
500000 to 3200000 of a file whose size is say 20MB...
how do i request a download which starts directly at 500000th byte...
thank u
cheers
|
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 pages.
The code generated is normal HTML code, example
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |