Autor Beitrag
elduchte
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Di 04.10.05 16:49 
Hallo,
ich möchte einen Wert in einer Edit-Komponente mit einer Zelle in einer Excel-Tabelle vergleichen.

Ich probierte folgendes:
ausblenden Delphi-Quelltext
1:
If Edit1.Text = ExWS.Cells.Item[zeile, spalte] then ....					

bzw.
ausblenden Delphi-Quelltext
1:
If ExWS.Cells.Item[zeile, spalte] = Edit1.Text then ....					


Bei beiden Varianten bekomme ich eine Exception.

Wie kann ich nun den Vergleich durchführen?

Vielen Dank für Eure Hilfe
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 04.10.05 17:54 
Moin!

user profile iconelduchte hat folgendes geschrieben:
Hallo,
ich möchte einen Wert in einer Edit-Komponente mit einer Zelle in einer Excel-Tabelle vergleichen.
[...]
Bei beiden Varianten bekomme ich eine Exception.

Auf den glorreichen Gedanken, die Art der Exception, ja vielleicht sogar den exakten Wortlaut wiederzugeben, bist du ja leider nicht gekommen, bleibt also nur raten...

Vielleicht paßt der Datentyp nicht, wenn in der Excel-Zelle ein Zahlenwert steht, düfte der Vergleich String <> Extended schwer werden.

cu
Narses
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Di 04.10.05 18:05 
Hallo,

tja, hatte wirklich die Idee, aber warum ich es nicht umgesetzt habe....

hier die Exception:

.... ist eine Exception der Klasse EVariantInvalidOpError aufgetreten. Meldung: Ungültige Variant-Operation....


Ich kann damit nicht viel anfangen, die Werte, die ich vergleiche, sind keine Zahlen.

Danke für die Hilfe
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 04.10.05 18:27 
ausblenden Delphi-Quelltext
1:
If Edit1.Text = ExWS.Cells.Item[zeile, spalte].Value then ....					


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Di 04.10.05 18:33 
Hi,

@Keldorn:

Wenn ich dass so mache, bekomme ich folgende Exception:

.... der Klasse EVariantTypeCastError aufgetreten. Meldung: Variante des Typs (String) konnte nicht in Typ (Date) konvertiert werden.

In meiner Excel-Tab sind die Felder als "standard" formatiert....

So langsam versteh ich nix mehr...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 04.10.05 18:41 
Moin!

user profile iconelduchte hat folgendes geschrieben:
.... der Klasse EVariantTypeCastError aufgetreten. Meldung: Variante des Typs (String) konnte nicht in Typ (Date) konvertiert werden.

In meiner Excel-Tab sind die Felder als "standard" formatiert....

Und der Inhalt deiner Zelle ist nicht zufällig ein Datum?

Probier doch mal das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  test: TDateTime;

test = ExWS.Cells.Item[zeile, spalte].Value;

Wenn das ohne Exception abläuft, dann brauchst du das doch nur mit DateTimeToStr() umwandeln, fertig.

cu
Narses
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 04.10.05 18:42 
Dann probier mal .text statt .Value

wenn das auch nicht geht, poste ein Bsp, was in den Zellen steht.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Di 04.10.05 18:49 
Hi,

vielen Dank für den schnellen Support, habe folgendes gemacht:

ausblenden Delphi-Quelltext
1:
if Edit1.Text = DateTimeToStr(ExWS.Cells.Item[zeile, spalte].Value then ..					

und bekam dann folgende Exception:

... der Klasse EVariantTypeCastError aufgetreten. Variante des Typs (OleStr) konnte nicht in Typ (Double) konvertiert werden.


Habe nochmals meine Excel-Tabelle kontrolliert. Die Felder sind als "Standard" formatiert.

Danke
Gruß
Andreas
elduchte Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 199

Win 2000, Win XP
Delphi 7
BeitragVerfasst: Di 04.10.05 18:59 
@Keldorn:

Mit .text funzte es, warum nur plötzlich, meine, dass ich das auch schon getestet habe.

Vielen Dank
Gruß
Andreas