Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Help! detect if label1.caption is less than label2.caption

Ok heres wha i've got:

1 form
1 timer

On create timer 1 containing the following code adds '1' to label1.caption at a 3000 interval

If label1.caption < label2.Caption then label1.caption :=IntToStr(StrToInt(label1.caption+1);

(automatically another timer counts the number of messages on a mail server and the count is put in caption2)

This code is to stop the number in label1 exceeding label2. and if this happens there is a seperate piece of code which makes the whole process start over again.

It all works fine when

label1.caption = Between 1-9
label2.caption Between 1-9

But as soon as Label2 = more than 9 (i.e 10) it goes wrong because it is almost like timer 1 reads label2 as being 1 and not 10 and so starts back at 1 again because by now label1 will = 2/3/4//5 etc...

Using the above code how do i get timer 1 to only add '1' to label1 if this will not exceed label2 - and to get timer 1 to recognize that if label2 = 10 it it is 10 and not 1?????? therefore meaning that label2 is more than label1 so procced adding 1 to label1.

Hope this all maks sense!!!!

If you are able to help please provide full source code (its far better to spell it out than waste time going backwards and forwards)


1 Solution
when you do this comparison you don't compare two numbers, you compare two strings.

If label1.caption < label2.Caption then label1.caption :=IntToStr(StrToInt(label1.caption+1);

so if you convert the two labelcaptions to numbers before you compare them it should work

If StrToInt(label1.caption) < StrToInt(label2.Caption) then label1.caption :=IntToStr(StrToInt(label1.caption+1);

hope this helps

harry_belaAuthor Commented:
Hi helgesen,

I have taken your code an have improved it so thanks....

300 points coming your way.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now