|
-
Sep 4th, 2008, 03:26 AM
#1
Thread Starter
Lively Member
[RESOLVED] Why is "10" in a label less than "7" in a textbox?
I have a label that increases by +1 on the push of a button.
It then checks to see if the label contents is more than (using ">") a textbox value and displays a msgbox if it is more.
Now this works until it gets to 10. The textbox is set to 7 and it displays a msgbox on 8 and 9 then when it gets to 10, 11, 12 etc.. it just stops displaying the msgbox.
Anyone know why?
-
Sep 4th, 2008, 04:04 AM
#2
Re: Why is "10" in a label less than "7" in a textbox?
You cannot compare the .Text value of two controls for a numeric value.
You must do something like
If CLng(Text1.Text)>CLng(Label1.Caption) Then
You must convert to a numeric datatype.
You are falling into the trap of datatype coercion - search the forum here for that and you will find lots of posts about it.
-
Sep 4th, 2008, 04:04 AM
#3
Junior Member
Re: Why is "10" in a label less than "7" in a textbox?
i can i see your code...
but i think... you should make sure that logical operation(>) is using integer as data type....
-
Sep 4th, 2008, 04:30 AM
#4
Re: Why is "10" in a label less than "7" in a textbox?
 Originally Posted by djwk
I have a label that increases by +1 on the push of a button.
It then checks to see if the label contents is more than (using ">") a textbox value and displays a msgbox if it is more.
Now this works until it gets to 10. The textbox is set to 7 and it displays a msgbox on 8 and 9 then when it gets to 10, 11, 12 etc.. it just stops displaying the msgbox.
Anyone know why?
You're comparing text, not numerical values. In alphanumeric sorting, "1" comes before "7".
-
Sep 4th, 2008, 05:48 AM
#5
Thread Starter
Lively Member
Re: Why is "10" in a label less than "7" in a textbox?
Thanks guys, I've actually had this problem before but just forgot. I went through some of my old code. I changed my textboxes to labels and used the following:
Val(Label1)
-
Sep 4th, 2008, 05:49 AM
#6
Hyperactive Member
Re: Why is "10" in a label less than "7" in a textbox?
 Originally Posted by leinad31
You're comparing text, not numerical values. In alphanumeric sorting, "1" comes before "7".
Just to clarify this a bit further, as 1 also comes before 7 in numerical sorting.
For ASCii values 0 - 127, sorting alphanumerically is the same as sorting by the ASCii values of the characters, e.g. a < A (65 < 97), however once you get past 128 the sorting goes a bit erratic, fortunately all the commonly typed characters are in the 0 - 127 range.
If anyone wants to take a look at how weird things go from 128 onwards, make a new form and put a list box on it, then stick this code in:
Code:
Private Sub Form_Load()
Dim blnCharacterUsed(0 To 255) As Boolean
Dim lngCurrentLowest As Long
Dim i As Long
Dim j As Long
List1.Clear
For i = 0 To 255
lngCurrentLowest = -1
For j = 0 To 255
If Not blnCharacterUsed(j) Then
If lngCurrentLowest = -1 Then
lngCurrentLowest = j
Else
If Chr(lngCurrentLowest) > Chr(j) Then
lngCurrentLowest = j
End If
End If
End If
Next j
blnCharacterUsed(lngCurrentLowest) = True
List1.AddItem CStr(lngCurrentLowest)
Next i
End Sub
I'm quite curious about this now so does anyone know why VB treats the higher value characters like this?
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Sep 4th, 2008, 05:55 AM
#7
Hyperactive Member
Re: [RESOLVED] Why is "10" in a label less than "7" in a textbox?
As this thread is resolved I've continued the discussion here for anyone who's interested
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|