473,396 Members | 2,013 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,396 software developers and data experts.

calculate string+integer..

59
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
Feb 15 '08 #1
5 3223
mshmyob
904 Expert 512MB
Try this replacing your control names:

Expand|Select|Wrap|Line Numbers
  1. Dim vString As String
  2. Dim vLen As Integer
  3. Dim vNumber As Double
  4. ' get the length of the string    
  5. vLen = Len(Trim(Me.Text11))
  6. ' extract out the number
  7. vString = Mid(Me.Text11, 2, vLen - 1)
  8. ' convert the string to a double number with 2 decimal places
  9. vNumber = CDbl(FormatNumber(vString, 2))
  10. ' display the result to a control on your form
  11. Me.Result = Me.Price * vNumber
  12.  
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
Feb 15 '08 #2
zivon
59
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:

Expand|Select|Wrap|Line Numbers
  1. Dim vString As String
  2. Dim vLen As Integer
  3. Dim vNumber As Double
  4. ' get the length of the string    
  5. vLen = Len(Trim(Me.Text11))
  6. ' extract out the number
  7. vString = Mid(Me.Text11, 2, vLen - 1)
  8. ' convert the string to a double number with 2 decimal places
  9. vNumber = CDbl(FormatNumber(vString, 2))
  10. ' display the result to a control on your form
  11. Me.Result = Me.Price * vNumber
  12.  
Feb 15 '08 #3
mshmyob
904 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. ' extract out the 1st character from the string
  2. ' this will give you either * or -
  3. Operation = Mid(Me.Text11, 1, 1)
  4.  
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)
Feb 15 '08 #4
missinglinq
3,532 Expert 2GB
Maybe

x =iif(Operation = "*", UPrice * Discount, UPrice - Discount)

Linq ;0)>
Feb 15 '08 #5
mshmyob
904 Expert 512MB
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 +/-.
Feb 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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.
6
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...
5
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
5
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...
15
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,...
6
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'));...
12
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,...
2
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...
9
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...
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
Oralloy
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,...
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
agi2029
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,...

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.