Convert Variant

Hi, How do I convert a variant to any other type of variable? And while we talking about variants… Why does Navision crash when I try to call a function with a record as variant parameter? Hope to hear from you soon!

Hi Emiel

quote:


Originally posted by eromein
… How do I convert a variant to any other type of variable? …


Without testing it: tmptxt:=Format(YourVariant); Evaluate(YourOtherVar,tmptxt); bye André

You even don’t need to use FORMAT or EVALUATE. Integer := Variant; Decimal := Variant; … and so on.

You can also use Variant.ISDECIMAL, Variants.ISINTEGER, Variant.ISTEXT etc. functions to check if variant contains needed data type.

Hi Athur

quote:


Originally posted by Arthur
You even don’t need to use FORMAT or EVALUATE. Integer := Variant; Decimal := Variant; … and so on.


Yes. Indeed! If I know what kind of Variant it is I can fill the other variable direct. It was to easy [8D]. bye André

Thing is, I want to compare fields. The fields I’m compairing could be anything possible. The real problem is options. I’m going to try your solution (In fact, I was already buzy on it) but I’m really looking for a nicer, better en more easy solution. Condition.setrange(foo,bar); IF Condition.FIND('-') THEN REPEAT CopyOfCurrentRecordField := CopyOfCurrentRecord.FIELD(Condition."Field No."); ConditionsMatch := CopyOfCurrentRecordField.VALUE = Condition.Value; UNTIL (Condition.next = 0) OR NOT ConditionsMatch; If Condition.Value is a tekststring and CopyOfCurrentRecordField.VALUE is a option, I’m compairing “string = integer”.

Why do you need to make comparing so difficult? Anyway you can use FORMAT to convert Option to Text.

I used this for exporting and importing unspecified tables to Excel: IF ExcelZuordnung.Feldtyp = ‘Option’ THEN BEGIN Integer := 0; REPEAT IF ExcelBuffer.“Cell Value as Text” = FORMAT(FldRef.VALUE(Integer)) THEN BEGIN FldRef.VALUE(Integer); Integer := -1; END ELSE Integer += 1; UNTIL Integer = -1; END; The drawback is that you have to know the type of the field you need to handle. Alex

1.) User defines in the Conditions table the fields that have to be compared. It’s quite understandable if you see the whole application, trust me on that one! 2.) Format does not work. If I format CopyOfCurrentRecordField.VALUE, which is a option field, it will return the integer value of the field. B.t.w. I’m going for a whole other solution now, but I still want to know the answer to this one, so keep on post’n

Hi Emiel

quote:


Originally posted by eromein
… 2.) Format does not work. If I format CopyOfCurrentRecordField.VALUE, which is a option field, it will return the integer value of the field. …


I don’t understand! Just a test. “Item Ledger Entry”.“Entry Type” is an optionfield. If I run Format(“Item Ledger Entry”.“Entry Type”) it shows me the text option not only the integer value. Am I wrong? bye André

SalesLine.get(foo,foo,foo); recref.gettable(SalesLine) fieldref := recref.field(5) // Type field; message(format(fieldref.value)); // Outputs integer value. So, if you format the value of a option field as a fieldref, it will return the integer value not the option value. I know there is a way to get the option string from this field from which the right value can be substracted but in my application I will not know in advance what type the field will have that I want to compare. B.t.w, the other solution I was talking about will not work either, I’m not able to make a temporary recref. Logicly…

Hi Emiel

quote:


Originally posted by eromein
SalesLine.get(foo,foo,foo); recref.gettable(SalesLine) fieldref := recref.field(5) // Type field; message(format(fieldref.value)); // Outputs integer value.


Uops. RecRef! FieldRef! I’m working with 3.01B [:(]. Is it necessary to work with with RecRef / FieldRef in this case? bye André

Andre, I’ll tell you what I want… I want to find records. A sample of a search command that could exist is : Search from Sales Line from field No. WHERE Type CONST item IN Item where name contains the searchstring. It’s more complex, but this should give you a good idear of what’s asked. The user can link a condition to a search command. This condition could be “Type CONST Item”. The user is able to define more then one conditions. It is for me so see if the current record (from which I’m searching) complies with all conditions. So That’s why I wrote the code below. The only problem is that the record from which I’m searching must exist in the database. But I’m working on that. CopyOfCurrentRecord := CurrentRecord; Condition.SETRANGE("Source Table No.",SearchFrom."Table No."); Condition.SETRANGE("Source Field No.",SearchFrom."Field No."); Condition.SETRANGE("Source Line No.",SearchFrom."Line No."); IF NOT Condition.FIND('-') THEN // Find all condition this record should comply with EXIT(TRUE); REPEAT CopyOfCurrentRecordField := CopyOfCurrentRecord.FIELD(Condition."Field No."); // Setfilter on the field in condition(Type) CopyOfCurrentRecordField.SETFILTER(Condition.Value); // With condition value from condition(Item) UNTIL (Condition.NEXT = 0); EXIT(CopyOfCurrentRecord.FIND); // Return if record is complying to all conditions Did I make any sence?

Hi Emiel It seems I can’t help you (today) [:(]. If I have an idea how to solve your problem with the options - I will post it here. bye André