Hi all,
im learning delphi, I need help with a simple piece of code
I have 3 off Tmemo fields
Tmemo1
Tmemo2
Tmemo3
What is the code for...
if tmemo1 = 'Input number of 10'
if tmemo2 = 'Input number of 20'
Tmemo3 = tmemo2+tmemo1
Tmemo3 = 30
My current code makes tmemo3 = 2010
Any help would be helpfull??
Applications → Programming Solutions → Delphi help - Simple code14 Apr 2010, 09:44 You have to login or register to post comments. |



tmemo1=StrToInt('10')
tmemo2=StrToInt('20')
You need to convert the strings in the tmemo field to integers, in order to add them together as numbers, otherwise they are joined as two strings.
This is what i was chasing...
Edit3.Text := IntToStr(StrToInt(Edit1.Text) + StrToInt(Edit2.Text));
This is my code so far,
if edit11.Text >= IntToStr(StrToInt(Edit2.Text)+1)then
edit11.Text := IntToStr(0)
else if edit10.Text >= IntToStr(StrToInt(Edit2.Text)+1)then
edit10.Text := IntToStr(0)
else if edit9.Text >= IntToStr(StrToInt(Edit2.Text)+1) then
edit9.Text := IntToStr(0)
else if edit8.Text >= IntToStr(StrToInt(Edit2.Text)+1)then
edit8.Text := IntToStr(0)
else if edit7.Text >= IntToStr(StrToInt(Edit2.Text)+1)then
edit7.Text := IntToStr(0)
else if edit6.Text >= IntToStr(StrToInt(Edit2.Text)+1)then
edit6.Text := IntToStr(0)
it works but will execute the first if statement which is true then ends, there may be 3 true answers and 3 false answers, what code will i need to execute all the if statements?
any help would be apriciated
BEGIN/END in ur statement blocks
or you can try
Case of statement
any suggestions on the code?
if edit11.Text > IntToStr(StrToInt(Edit2.Text)+1)then
begin
edit11.Text := IntToStr(0)
end
else if edit10.Text > IntToStr(StrToInt(Edit2.Text)+1)then
begin
edit10.Text := IntToStr(0)
end
else if edit9.Text > IntToStr(StrToInt(Edit2.Text)+1) then
begin
edit9.Text := IntToStr(0)
end
else if edit8.Text > IntToStr(StrToInt(Edit2.Text)+1)then
begin
edit8.Text := IntToStr(0)
end
else if edit7.Text > IntToStr(StrToInt(Edit2.Text)+1)then
begin
edit7.Text := IntToStr(0)
end
else if edit6.Text > IntToStr(StrToInt(Edit2.Text)+1)then
begin
edit6.Text := IntToStr(0)
end
else
Also I would have thought that you would need to do:
as comparing strings with < and > often leads to odd outcomes, depending on the language, some will compare the length, some will compare the binary value of the string and some will event put them in alphabetical order :m
tobyb
if StrToInt(edit10.Text) >= (StrToInt(Edit2.Text)+1) then
if StrToInt(edit10.Text) >= (StrToInt(Edit2.Text)+1) then