calculate string+integer..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zivon
    New Member
    • Aug 2007
    • 59

    calculate string+integer..

    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
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Try this replacing your control names:

    Code:
    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
    Originally posted by zivon
    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

    Comment

    • zivon
      New Member
      • Aug 2007
      • 59

      #3
      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)




      Originally posted by mshmyob
      Try this replacing your control names:

      Code:
      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

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Code:
        ' extract out the 1st character from the string
        ' this will give you either * or -
        Operation = Mid(Me.Text11, 1, 1)
        Originally posted by zivon
        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)

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Maybe

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

          Linq ;0)>

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            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 +/-.

            Comment

            Working...