944,092 Members | Top Members by Rank

Ad:
Nov 3rd, 2009
0

Haw to allow to enter number only from number 1 to 65535.

Expand Post »
i have problem to allow enter only from 1 to 65535 bicouse
example if enter 10000,2000 is ok but enter 99 not.

hire 1 example (not working)
Pascal and Delphi Syntax (Toggle Plain Text)
  1. If somthing.Text > '65535 'then
  2. ShowMessage(' you enter biger Number from 65535');
  3. Exit;

hire 2 example (not working)
Pascal and Delphi Syntax (Toggle Plain Text)
  1. var
  2. result : Integer;
  3. string1: String;
  4. string2: String;
  5. begin
  6. string1:='65535';
  7. string2:= somthing.Text;
  8. result := AnsiCompareStr(string1, string2);
  9. if result < 0 then ShowMessage(string1+' < '+string2);

please help haw to solve this.
Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
especta is offline Offline
24 posts
since Aug 2009
Nov 3rd, 2009
1

2 solutions

Click to Expand / Collapse  Quote originally posted by especta ...
i have problem to allow enter only from 1 to 65535 bicouse
example if enter 10000,2000 is ok but enter 99 not.

hire 1 example (not working)
Pascal and Delphi Syntax (Toggle Plain Text)
  1. If somthing.Text > '65535 'then
  2. ShowMessage(' you enter biger Number from 65535');
  3. Exit;

hire 2 example (not working)
Pascal and Delphi Syntax (Toggle Plain Text)
  1. var
  2. result : Integer;
  3. string1: String;
  4. string2: String;
  5. begin
  6. string1:='65535';
  7. string2:= somthing.Text;
  8. result := AnsiCompareStr(string1, string2);
  9. if result < 0 then ShowMessage(string1+' < '+string2);

please help haw to solve this.
Thanks.
[DELPHI]

1. Convert your string to a number and test that.

2. create the following function and pass the string as

IF Between(Atextbox.Text,1,65535)
THEN MessageDlg('Thats OK',MtInformation,[MbOK],0)
ELSE MessageDlg('Bad Number',MtInformation,[MbOK],0);

You could also vary the Value by type and overload this to do any numbers

FUNCTION Between(Value : String;Low,High : LongInt) : BOOLEAN;
VAR
N : Integer;
Begin
TRY
N := StrtoInt(Value);
RESULT := ((N >= Low) AND (N <= High));
EXCEPT ON EConvertError DO
RESULT := FALSE;
End;
End;
Reputation Points: 11
Solved Threads: 3
Newbie Poster
quaifp1 is offline Offline
10 posts
since Oct 2009
Nov 3rd, 2009
0
Re: Haw to allow to enter number only from number 1 to 65535.
Click to Expand / Collapse  Quote originally posted by quaifp1 ...
[DELPHI]

1. Convert your string to a number and test that.

2. create the following function and pass the string as

IF Between(Atextbox.Text,1,65535)
THEN MessageDlg('Thats OK',MtInformation,[MbOK],0)
ELSE MessageDlg('Bad Number',MtInformation,[MbOK],0);

You could also vary the Value by type and overload this to do any numbers

FUNCTION Between(Value : String;Low,High : LongInt) : BOOLEAN;
VAR
N : Integer;
Begin
TRY
N := StrtoInt(Value);
RESULT := ((N >= Low) AND (N <= High));
EXCEPT ON EConvertError DO
RESULT := FALSE;
End;
End;
thanks to replay (FUNCTION is ok i have test it ) but i got strange agan i can enter example 2000,23222, but if enter 88 i got error...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
especta is offline Offline
24 posts
since Aug 2009
Nov 4th, 2009
1
Re: Haw to allow to enter number only from number 1 to 65535.
I made a pascal source code
pascal Syntax (Toggle Plain Text)
  1.  
  2. program sablon;
  3.  
  4. uses crt;
  5.  
  6. type range = 1..65535;
  7.  
  8. const ok = 'ok.';
  9. error = 'error';
  10. min = 1;
  11.  
  12. var one:longint;
  13. two:range;
  14. user,temp:string;
  15.  
  16. function converter(x:string):string;
  17. var code:integer;
  18. begin
  19. two:=65535;
  20. {$I-}
  21. val(x,one,code);
  22.  
  23. if (ioresult <> 0) then begin
  24. converter:=error;
  25. exit;
  26. end;
  27. if (code <> 0) then begin
  28. converter:=error;
  29. exit;
  30. end;
  31. if (one > two) or (one < min) then converter:=error else converter:=ok;
  32. {$I+}
  33. end;
  34.  
  35. begin
  36. clrscr;
  37. temp:=error;
  38. while temp <> ok do begin
  39. write('please enter a number from 1 to 65535: ');
  40. readln(user);
  41. temp:=converter(user);
  42. writeln(temp);
  43. end;
  44.  
  45. readln;
  46. end.
  47. {created by FlamingClaw 2009}
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Nov 4th, 2009
1
Re: Haw to allow to enter number only from number 1 to 65535.
var
xx:Integer;
begin
try
xx:=strtoint(something.text);
if xx<1 then showmessage('number too small') else
if xx>65535 then showmessage('number too big') else
Showmessage('number accepted');
except
showmessage('Not a valid number');
end;
end;
cao
Reputation Points: 11
Solved Threads: 5
Newbie Poster
cao is offline Offline
12 posts
since Oct 2009
Nov 4th, 2009
0

Big Thanks

BIG Thanks for replay to:
quaifp1
cao
FlamingClaw

i have solved .........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
especta is offline Offline
24 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Creating Simple Login Screen In DevPas
Next Thread in Pascal and Delphi Forum Timeline: runtime error as IOresult<>0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC