+ Reply to Thread
Results 1 to 3 of 3

strange behaviour when comparing 2 values in a userform

  1. #1
    Registered User
    Join Date
    12-13-2014
    Location
    Netherlands
    MS-Off Ver
    excel 2007
    Posts
    3

    strange behaviour when comparing 2 values in a userform

    Hello guys,

    I am new in the forum. I am posting beacuse I have an issue with my userform, where I am triyng to compare 2 values through a simple routine.

    The value are entered by the user in 2 textboxt. The code attached to my button is someting like:

    if A > B then
    textbox3.value = A
    else
    textbox3.value = B

    the point is that, for example, if A = 256 and B = 166,6 the result of A > B is "true", but if A = 1000 and B = 166,6 then the result of A > B is "false". Please see the 2 attached screenshot that explain this.

    Here is my code:
    -----------------------------------------------------------------------------------------------------------------
    Private Sub CalculateButton_Click()

    Me.TboDimweight.Value = (Me.TboHeight.Value * Me.TboLenght.Value * Me.TboWidth.Value) / 6000

    MsgBox Me.TboWeight.Value > Me.TboDimweight.Value

    If Me.TboWeight.Value > Me.TboDimweight.Value Then

    Me.TboCharweight.Value = Me.TboWeight.Value

    Else

    Me.TboCharweight.Value = Me.TboDimweight.Value

    End If

    End Sub
    -----------------------------------------------------------------------------------------------------------------

    Please help me!
    Thank you.
    Attached Images Attached Images

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: strange behaviour when comparing 2 values in a userform

    Text box entries are strings. Your code is not comparing the numerical values, its comparing the alphabetical values.

    Just as "ABBBB" < "ACC,C", as strings "10000" < "166.6"

    To compare as numbers one has to convert to a number format


    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-13-2014
    Location
    Netherlands
    MS-Off Ver
    excel 2007
    Posts
    3

    Re: strange behaviour when comparing 2 values in a userform

    Thanks Mikerikson, now it is working!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] strange result of values comparing
    By blackarrow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2013, 08:55 AM
  2. Strange Behaviour
    By Mark@Work in forum Excel General
    Replies: 2
    Last Post: 09-30-2008, 12:22 PM
  3. [SOLVED] Strange if(***) behaviour?
    By Excel 2003 - SPB in forum Excel General
    Replies: 6
    Last Post: 08-06-2006, 12:35 PM
  4. [SOLVED] Strange VBA Behaviour
    By Ricko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2005, 03:05 AM
  5. [SOLVED] Strange behaviour
    By Edgar Thoemmes in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2005, 12:06 PM

Tags for this Thread

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