Autor Beitrag
delphistart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119



BeitragVerfasst: Di 26.12.06 16:56 
Habe mal wieder eine einfache Frage zu der ich einfach keine Antwort finde:

Ich habe eine Integervariable von der ich nicht weis ob der Wert den Sie enthält über oder unter 0 liegt oder gar genau 0 ist. Wenn der Wert negativ, also unter 0 ist soll er zu einem positiven wert umgewandelt werden. Ansonsten zu 0.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if variable<0 then
  //Hier müsste dann ein befehl rein, der das - entfernt und die Zahl
  //als positiven Wert ausgibt
  variable:=//positiver wert
else
  variable:=0;
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 26.12.06 16:58 
variable := -variable; ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
delphistart Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119



BeitragVerfasst: Di 26.12.06 17:06 
user profile iconChristian S. hat folgendes geschrieben:
variable := -variable; ;-)


DANKE!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 26.12.06 17:28 
Und dann gibts da noch die Funktion Abs, die lässt eine positive Zahl positiv und macht eine negative positiv...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 26.12.06 17:48 
user profile iconChristian S. hat folgendes geschrieben:
variable := -variable; ;-)

Er möchte aber den Betrag einer Zahl, also nicht grundsätzlich das Vorzeichen vertauschen ;-). Abs() ist - wie user profile iconjaenicke bereits sagte - das richtige.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Di 26.12.06 17:55 
Wenn man aber den Code von TUFKAPL in delphistarts if-Bedingung einsetzt, isses auch das, was er will. Und so wars ja IMHO auch gemeint.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 26.12.06 17:58 
Stimmt - hab wieder nur die Hälfte gelesen - ändert aber nix daran, dass Abs(); kürzer ist ;-).

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Di 26.12.06 18:04 
Außer dass Werte > 0 anders behandelt werden. Bei der TUFKAPL+Delphistart-Lösung werden Werte > 0 zu 0, bei ABS zu negativen Werten.

@GTA: jetz haste 3/4 gelesen^^

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 26.12.06 18:17 
Ich meinte ja gar nicht, dass Abs hier unbedingt verwendet werden sollte, aber ich wollte es doch dazusagen, falls es später mal gebraucht wird.
Schließlich liest den Thread ja vielleicht später auch mal jemand anderes... ;-)

user profile iconjakobwenzel hat folgendes geschrieben:
Außer dass Werte > 0 anders behandelt werden. Bei der TUFKAPL+Delphistart-Lösung werden Werte > 0 zu 0, bei ABS zu negativen Werten.

Ähh, sieh dir Abs mal nochmal an... :lol:

Abs gibt den Absolutwert, den Betrag eines Werts zurück. Ist der Wert größer oder gleich 0, dann bleibt er unverändert, ist er kleiner als 0 wird -1 mal der Wert (also der positive Wert) zurückgegeben.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 26.12.06 18:18 
Falsch, |-3| wird zu 3, |0| bleibt 0 und |3| bleibt 3. Das ist der Sinn von Abs() [Absolute] ;-).


EDIT: Das "Falsch" bezog sich auf user profile iconjakobwenzel; Ich war zu langsam ;-).

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)


Zuletzt bearbeitet von GTA-Place am Di 26.12.06 18:19, insgesamt 1-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 26.12.06 18:18 
user profile iconGTA-Place hat folgendes geschrieben:
Falsch, |-3| wird zu 3, |0| bleibt 0 und |3| bleibt 3. Das ist der Sinn von Abs() [Absolute] ;-).

Zu spät... Musst schneller tippen... :P
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 26.12.06 18:24 
Siehe mein Edit. Aber ich hab auch gesehen, dass du deinen Beitrag gerade eben editiert hast. Das "musst schneller tippen" war noch nicht da ;-).

Hier noch ein Beispiel aus dem Alltag:
Ich z.B. verwende immer diese Funktion, wenn ich auf der Bank meinen Kontostand auslesen will:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function GetKontostand(BLZ, Ktn, PIN: Integer;): Extended;
var
  Bank: TBank;
begin
  Bank := TBank.Create(BLZ, fmConnect);
  Bank.Ktn := Ktn;
  Bank.PIN := PIN;
  Result := Abs(Bank.GetKontoStand);
  Bank.Free;
end;

:mrgreen:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 26.12.06 18:26 
:rofl: :rofl: :rofl:
[OT] Wenn die Banken das nur genauso machen würden... ;-) [/OT]