+ Reply to Thread
Results 1 to 3 of 3

Type Mismatch in a UserForm Calculation

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    54

    Type Mismatch in a UserForm Calculation

    Hello,

    I have a userform that takes the side lengths of an oblique triangle and uses Heron's formula to calculate the area, but I am getting a type mismatch if the user inputs different number types. If they input all integers, for example, everything works just fine but if they input 12, 5.42, and 19.0006 then I get the error.

    How do I convert all of these numbers to the same type?

    Here is my code:

    Please Login or Register  to view this content.
    Thanks so much for the help!

    -Mike

  2. #2
    Registered User
    Join Date
    04-22-2012
    Location
    Syracuse, NY, USA
    MS-Off Ver
    Office 365
    Posts
    61

    Re: Type Mismatch in a UserForm Calculation

    It seems that the error is resulting from (using your example) the user entering different types of input: 12 (Long), 5.42 & 19.006 (both Double). The code below should take care of the problem by explicit defining the values as all being Double.

    If I remember right Heron's formula is A=sqr(s(s-a)(s-b)(s-c)); where a,b and c are the sides and s is the semi-perimeter, it's been about 12 years since I was in college as a math major.

    Please Login or Register  to view this content.
    Notes:
    1) I didn't include the =True in the If statement because the If statement checks logical values. The variables in it are Boolean and therefore are considered logical values. It will still fail if any of the Test# varaibles come back as a False.
    2) Mathematically you may want to change the IsNumeric boolean tests to something else that will not allow a negative number or zero as a length.
    Last edited by RGrunden; 06-19-2012 at 11:32 PM.
    Reality is stranger than fiction.

  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Type Mismatch in a UserForm Calculation

    That did the trick except that I had to move the initializations of A,B,C,H,S to after the numeric tests and into the If statement because when the userform initializes I have those text boxes initializing to strings, so I was getting a type mismatch again.

    Thanks so much for your help!

    -Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1