Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Number Only Edit Box =) Please?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 20th October 05:36
name
External User
 
Posts: 1
Default Number Only Edit Box =) Please?



if Key in ['a'..'z'] + ['A'..'Z'] then Key:=#0;
^I had that code in my notes.

If not key in ['0'..'9'] then key := #0;

^ Thats what i attempted to do but delphi wont let me use the not word like
that.


if Key in ['0'..'9'] then Key:= Key else Key := #0;

^ is what i came up with -- is there a better way to do it?

- - Thank -You


my ascii art skills are improving ^_^
  Reply With Quote


 


2 20th October 05:36
steven
External User
 
Posts: 1
Default Number Only Edit Box =) Please?



If not (key in ['0'..'9']) then key := #0;
  Reply With Quote


 


3 20th October 05:36
maarten wiltink
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


Type "operator precedence", press "Google Search", read help.

"Not" goes before "in". Therefore, "key" binds to "not", not to "in".
(This formulation borrowed from associativity.) There is no "not"
operator for characters. Kaboom.

Precedence can be overridden by parentheses.
"if not (key in ['0'..'9']) then key:=#0;" works. [...]

That wasn't ASCII-art.

_,,_,,,.._ <-.
,' _____,_`-. `\
/ .' ``^,'.__ //
I / '---''
| I
j \
\ \.
`. \,. ,__
_,,-~`--..-~-'_,/`--,,,____
`\,_,/',_.-~_..-~/' ,/---~~~"""`\
_,_,,,\q\q/' \,,-~'_,/`````-,7. ___,,-
`@v@`\\,,,,__ \,,-~~"__/` ",,/ `-. ___.----~~~' __/
`--''_..-~~\ \,-~~"" `\_,/ `^__.'--~~ __ ,--""`
,|``-~~--./_,,_ _,,-~~'/ \.-~' __.--~ _,"
,/ `\,_,,/`\ `\,__,\,V /' ,-",-'/ _/
; _,,/__..-|| / /\,_|_,| __' __)
.' /' / | \ \ _/'__/\,' _ '.__/
,-'.-'----""/ l \ "\_/\__/\," _"
/ _"....___,/ / \ L\-\_.// _/
\/ | 1 / K/ /__( ." \
|--.....--"| | ," / / __) \ \
| I \_/ /_ /\__> _/ | Y
_\_ ,,T ( / _ " / / / l
/ l "----"" \ '_/___/^^~~'/"__,,,_,/ ./_
l \ \ 7 / @ )
\ \_ _,,-\ \,---~\ __ /
] \""---"' '\ / \"__." _/
____/ (_`~._ _.-`, ,___/ (_
_,-'/,-/,_._ \ `."----"" `, ___/_/ 7`,-._\__
\[ {( {( `_} `-.. \, _\[_\({(/ `~_}
` `` ""--..--"---""" ` `

THIS is ASCII-art! (Picture by Marcin Glinski, diddled by n4biS.)

Groetjes,
Maarten Wiltink
  Reply With Quote
4 20th October 05:36
name
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


My art was just smaller... & operator presidence got me again O_O. I'm going
on google to download a list and print out because this is the second time
it happened to me.

Thank you for the extreamly fast responces!
  Reply With Quote
5 20th October 05:36
name
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


if Key in ['0'..'9',#08] then Key := Key else Key := #0;

//If not (key in ['0'..'9',#08]) then key := #0;

What code is "better"? They both do the same thing but the first one, to me
anyway, is extreamly readable while the other one is ify =)
  Reply With Quote
6 20th October 05:37
bjørge sæther
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


"name" <e@mail.add> skrev i melding
news:0V9%a.20811$vo2.9893@newsread1.news.atl.earth link.net...

me


The upper version is pure nonsense. I'd have to look at it twice to


possibly use one more minute trying to figure out what on earth he'd been up
to.

Another point: A "Negative" statement is slightly harder to comprehend than
the "positive" one:

"negative":

if not Button1.Enabled then
DoIfDisabled
else
DoIfEnabled;

vs. "positive":

if Button1.Enabled then
DoIfEnabled
else
DoIfDisabled;

The other principle is that the "most likely", or "what the routine is made
for" is placed first, if a test splits up execution routes like in these
examples.
Which one is most important, I won't say for sure...

--
Regards,

Bjørge Sæther
bjorge@haha_itte.no
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.
  Reply With Quote
7 1st November 16:46
bjørge sæther
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


"name" <e@mail.add> skrev i melding
news:PFc%a.16022$BC2.10485@newsread2.news.atl.eart hlink.net...

It's setting Key := Key, which is a NOP (No OPeration).

More clear:

if Key in ['0'..'9',#08] then
// do nothing...
else
Key := #0;


--
Regards,

Bjørge Sæther
bjorge@haha_itte.no
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.
  Reply With Quote
8 1st November 16:48
steven
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


Here "Key := Key" is a NOP, but if Key is a property with a read function
and/or write procedure it may actually do something. Even a lot of things.
Vely dangelous.
  Reply With Quote
9 1st November 16:48
alanglloyd
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


In article <iEe%a.22948$vo2.19745@newsread1.news.atl.earthlin k.net>, "name"
<e@mail.add> writes:

Few procedures define something which leaves everything as it is. In general
the program sets values by option depending on values, or alters a default
action in certain conditions. Only for aditional clarity is a "do-nothing"
action declared.

The default activity is to have no action on an event, only if action is
desired is an event handler defined. I do not know of any increase in clarity
by filling one's program with ...

procedure TMyForm.SomeEvent(Sender : TObject);
begin
// do nothing
end;

So an event handler changes values. In this particular case code only for
changes to implement the pseudo-code ...

if the key pressed is not 0 - 9 or backspace, then stop the key having any
effect.

Done clearly, succintly, and effectively by ...

const
BackSpace = #8;

if not Key in ['0'..'9', Backspace] then
Key := #0;

Any additional code is verbiage - which is usually (and is so in this case)
confusing.

Please "name" (whoever you may be but are afraid to reveal your name) do not
reply - I feel an attack of irrascible irritation coming on <g>.

Alan Lloyd
alanglloyd@aol.com
  Reply With Quote
10 1st November 16:48
erewhon
External User
 
Posts: 1
Default Number Only Edit Box =) Please?


Personally I would go for :-

if (Key in ['0'..'9', #8]) = False then
Key := #0;

I detest the use of Else

I am also wary about the use of :-

If Not Something = True Then
DoSomething

Perhaps because I evaluate from Right to Left, as I am reading from
Right to Left
- I get a mental 'blip' when I find myself having to remember that
earlier modifier ...

In speech people often use double negatives incorrectly.
  Reply With Quote
Reply


Thread Tools
Display Modes




666