Hello People, I am trying to convert a Code value for eg. the Document No. in Sales Header to a Binary Value, I know it would seem funny but its a requirement. Can it be done or is there a functions which can help. Any Ideas !!! Regards
Isnt there any way to do this ? in SQL there is a CONVERT function which does exactly what I want but I have to this in Navision Regards
could you give an example of the docno and the respectet binary value? Do you realy need the 0010001001?
Hi, Im not sure how to use the binary datatype effectively within Navision, but using functions, it shouldnt be too difficult to convert a code to a binary code. Ive drafted a quick and dirty sample below which should convert codes to 8 bit binary values. Be aware that it doesnt do any error checking! (eg. convert value > 255 = failure). Not sure whether this is whats required! Regards, Edward. CreateBoolFromCode(Input : Code[20]) Output : Code[20] EVALUATE(Int,Input); FOR Counter := 1 TO 8 DO BEGIN IF (Int - GetNextInt(Counter)) < 0 THEN Output := Output + ‘0’ ELSE BEGIN Output := Output + ‘1’; Int -= GetNextInt(Counter); END; END; GetNextInt(Counter : Integer) : Integer CASE Counter OF 1: EXIT(128); 2: EXIT(64); 3: EXIT(32); 4: EXIT(16); 5: EXIT(8); 6: EXIT(4); 7: EXIT(2); 8: EXIT(1); END;
Finally atleast some one replied, thanx a ton Edward. I shall let you know if it works fine… Appreciate !! Prince
Here’s another way: Dec2Bin(Dec : Code[20]) Bin : Code[20] IF NOT EVALUATE(Quotient, Dec) THEN ERROR(‘Not a valid number.’); WHILE Quotient > 0 DO BEGIN Remainder := Quotient MOD 2; Quotient := Quotient DIV 2; Bin := FORMAT(Remainder) + Bin; END; Regards, Steffen
Hello people actually i had lost hope of replies hence didnt check the forum, sorry about that… thedoucment number can be “SO12345” etc… Evaluate will not work in the above scenario. any other suggestions…appreciate the effort thanx a ton Prince
Well, obviously only a valid decimal number can be converted to it’s binary counterpart. If you simply wish to avoid an error you could replace the code: IF NOT EVALUATE(Quotient, Dec) THEN ERROR(‘Not a valid number.’); with: IF NOT EVALUATE(Quotient, Dec) THEN EXIT; thereby returning a blank instead. Otherwise you have to isolate the number part of the “Doc. No.” (using EVALUATE) and convert this separately. But what if there’s more than one, say A4B3C2. Should this convert to A100B11C10? Regards, Steffen