Hello everyone !
I made a price calculator for a guest house.
I have diffrent sale campaigns, all the time, I made a table with campaign name and discount, for example: name "pensioners" discount "*0.9".
10% discount, now I want calculate this with the price.
The price is integer, and the discount must be a string, because of the */-
how can I calculate them anyway ?
I have tried with len/right to separate * and the number to two diffrent variables.
and then I experience two problams. one, it rounds the 0.9 to 1.
and I still can't calculate even with the 1.
UPrice & Operation & Discount ?
UPrice + Operation + Discount ?
hope you can help me out...
thanks in advance, Idan
5 3223
Try this replacing your control names: -
Dim vString As String
-
Dim vLen As Integer
-
Dim vNumber As Double
-
' get the length of the string
-
vLen = Len(Trim(Me.Text11))
-
' extract out the number
-
vString = Mid(Me.Text11, 2, vLen - 1)
-
' convert the string to a double number with 2 decimal places
-
vNumber = CDbl(FormatNumber(vString, 2))
-
' display the result to a control on your form
-
Me.Result = Me.Price * vNumber
-
Hello everyone !
I made a price calculator for a guest house.
I have diffrent sale campaigns, all the time, I made a table with campaign name and discount, for example: name "pensioners" discount "*0.9".
10% discount, now I want calculate this with the price.
The price is integer, and the discount must be a string, because of the */-
how can I calculate them anyway ?
I have tried with len/right to separate * and the number to two diffrent variables.
and then I experience two problams. one, it rounds the 0.9 to 1.
and I still can't calculate even with the 1.
UPrice & Operation & Discount ?
UPrice + Operation + Discount ?
hope you can help me out...
thanks in advance, Idan
thank you
it solved only one problam... the rounding of the number.
I have two types of discounts one using * and the other using -
this solve the other problam but uses two lines.. is there another options ?
If Operation = "*" Then x = (UPrice * Discount)
If Operation = "-" Then x = (UPrice - Discount)
Try this replacing your control names: -
Dim vString As String
-
Dim vLen As Integer
-
Dim vNumber As Double
-
' get the length of the string
-
vLen = Len(Trim(Me.Text11))
-
' extract out the number
-
vString = Mid(Me.Text11, 2, vLen - 1)
-
' convert the string to a double number with 2 decimal places
-
vNumber = CDbl(FormatNumber(vString, 2))
-
' display the result to a control on your form
-
Me.Result = Me.Price * vNumber
-
-
' extract out the 1st character from the string
-
' this will give you either * or -
-
Operation = Mid(Me.Text11, 1, 1)
-
thank you
it solved only one problam... the rounding of the number.
I have two types of discounts one using * and the other using -
this solve the other problam but uses two lines.. is there another options ?
If Operation = "*" Then x = (UPrice * Discount)
If Operation = "-" Then x = (UPrice - Discount)
Maybe x =iif(Operation = "*", UPrice * Discount, UPrice - Discount) Linq ;0)>
Just as a side note.....
You now have the code to convert the string to a number and the code to determine if it is an increase or decrease. But would it not make more sense to just make the discount field a numeric field and enter either a positive number or a negative number to determine increase or decrease?
Just my 2 cents worth - you may have other reasons for creating a text field, then converting to numeric, then trying to determe +/-.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul E Collins |
last post by:
Given a string variable (form input), how can I determine whether it
represents a valid integer?
is_numeric is true for floats as well as integers, and is_int always
fails on a string.
P.
|
by: Chris Michael |
last post by:
I've got a string of numbers, say 123456 (the actually number is 12 digits
long). I need to calculate the sum of each individual number in the string
of numbers, so in the example of 123456 the sum...
|
by: Tony Vasquez |
last post by:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <--- here. Please advice, or post scriptlette. Thanks
Tony Vasquez
|
by: Jepsensen |
last post by:
Dear Everybody.
I got a problem with my cpp code.
I'm trying to calculate a very simple Discrete Cosine Transform (DCT),
but my c++ code seams to calculate a wrong result.
I have just started...
|
by: Teresa |
last post by:
1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)
2) And is it better to use the string class to trim, get length,...
|
by: comp.lang.php |
last post by:
I'm involved in a rather nasty debate involving a strange issue
(whereby the exasperated tell me to RTFM even after my having done so),
where this is insanely possible:
print_r(is_int('1'));...
|
by: paii, Ron |
last post by:
Sorry about that last one.
Does anyone know how to calculate the width a string of text for given Font
name and size?
I want to buildup a block of text strings to display in a unbound control,...
|
by: Chicken15 |
last post by:
Hi Group.
First of all I'm sorry for asking (maybe) such easy questions. But I'm
quite stuck now and couldn't come up with a solution by using my C#
book or googling. So it would be nice if...
|
by: Freddy Coal |
last post by:
How convert a number for the string equivalent?
For example:
I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".
Thanks in...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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,...
| |