By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

calculate string+integer..

P: 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
Share this Question
Share on Google+
5 Replies


mshmyob
Expert 100+
P: 904
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

P: 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
Expert 100+
P: 904
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
Expert 2.5K+
P: 3,532
Maybe

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

Linq ;0)>
Feb 15 '08 #5

mshmyob
Expert 100+
P: 904
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

Post your reply

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