459,702 Members | 1,760 Online
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
5 Replies

 Expert 100+ P: 904 Try this replacing your control names: Expand|Select|Wrap|Line Numbers 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 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 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   Feb 15 '08 #3

 Expert 100+ P: 904 Expand|Select|Wrap|Line Numbers ' 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) Feb 15 '08 #4

 Expert 2.5K+ P: 3,532 Maybe x =iif(Operation = "*", UPrice * Discount, UPrice - Discount) Linq ;0)> Feb 15 '08 #5

 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