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

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2009
Posts: 21
Reputation: especta is an unknown quantity at this point 
Solved Threads: 0
especta especta is offline Offline
Newbie Poster

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

 
0
  #1
Nov 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: quaifp1 is an unknown quantity at this point 
Solved Threads: 3
quaifp1 quaifp1 is offline Offline
Newbie Poster

2 solutions

 
1
  #2
Nov 3rd, 2009
Originally Posted by especta View 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.
[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;
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 21
Reputation: especta is an unknown quantity at this point 
Solved Threads: 0
especta especta is offline Offline
Newbie Poster
 
0
  #3
Nov 3rd, 2009
Originally Posted by quaifp1 View Post
[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...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 473
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 114
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training
 
1
  #4
Nov 4th, 2009
I made a pascal source code
  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}
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: cao is an unknown quantity at this point 
Solved Threads: 4
cao cao is offline Offline
Newbie Poster
 
1
  #5
Nov 4th, 2009
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;
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 21
Reputation: especta is an unknown quantity at this point 
Solved Threads: 0
especta especta is offline Offline
Newbie Poster

Big Thanks

 
0
  #6
Nov 4th, 2009
BIG Thanks for replay to:
quaifp1
cao
FlamingClaw

i have solved .........
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 697 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC