Hi,
i am face with a challenge of converting the first character of a datatype code to number.
For example
A556 will be 01556
B556 will be 02556
Basically taking the alphabets to number,
A==01
B==02
C==03
D==04
E==05 , etc
all the program should do is take the first character converts it to number then add it to the reminding characters.
Can some help me on this?
Thank you
0
Comments
If NewCodeField = 'A'
then begin
NewCodeField := DELCHR(YourCodeField,'<',DELCHR(NewCodeField);
YourCodeField := '01'+ NewCodeField;
End;
if NewCodeField = 'B'
then Begin
NewCodeField := DELCHR(YourCodeField,'<',DELCHR(NewCodeField);
YourCodeField := '02'+ NewCodeField
end;
etc for c & d & e;
Is this a Primary key field?
I'm sure there is a prettier way.. :-#
http://www.BiloBeauty.com
http://www.autismspeaks.org
http://www.BiloBeauty.com
http://www.autismspeaks.org
Always wondered why you wouldn't want that button pressed? :-k
http://www.BiloBeauty.com
http://www.autismspeaks.org
I wish to have the turbo button on laptops.
My laptop runs very hot it's a HP NC 6230. The fan is on all the time. That way I can lower the CPU clock speed so it runs just like it's on battery.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
a - is variable of type Code with the original string.
b - is variable of type Code with result
Do you know how it works? I will let you some time to think about it, if you want I can describe it for the rest, who do not understand...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
one line coding is for old navision coder
http://www.BiloBeauty.com
http://www.autismspeaks.org
RIS Plus, LLC
HAAHHAHA.... Oh my god... This has to be the post of the month!
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
I understand the code. What I want some explaining on is how are you able to figure out that you can use a string variable with an array syntax.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
Thanks Daniel, that you have taken my side...
I do not feel old... but it is true, that my first computer was Atari 800XE... :whistle:
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Ok, I will try.
First some basics:
Datatype Text (or Code) is defined as ARRAY of CHARs. Char is a datatype, which has size of one byte and it means that the values are 0-255. The char datatype can be used as number (0-255) or as a Character ('A', 'B', '$' etc.). Relation between character and number is, that each character has some ordinal number which is defined by ASCII table. It means, that e.g. 'A' = 65, 'B' = 66, 'Z'= 90 etc. You can use mathematical operators with both "notations" (number and character) - it means you can do e.g. 'A'-'B' = 1, if both operators are of type char. And this is the base of the expression.
Ok, let's go:
*** a[1]-'A'+1
a[1] = first char from the "String" (variable) a - it is the first character in the text saved in variable a. Because Text (Code) datatype is ARRAY of chars, you can use indexing to read some component of the array... it means that a[1] is of type Char and it is the char on position 1...
By substracting 'A' from any char (if we are using just uppercase characters from period A..Z), you will get the position of the character in the alphabet (A=0, B=1,...). And because you want to have A as 1, I am adding 1 to the result.
***FORMAT(Something,2,'<integer,2><filler character,0>')
this will format the number in "Something" into text with length 2 filled with 0 from left. It means e.g. 1 is formated as '01' etc.
***+COPYSTR(a,2)
add the rest of the text, without first character (take substring, starting on 2nd character, to the end)
As you can see, it is about understanding the datatypes and some basic things from programming languages (arrays, string representation, ,,mathematical operations over the different datatypes).
I hope that this description will help you to understand more deeply some things, and that it will not discourage you from NAV... 8)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Because C/AL is based on Pascal, the "Text" and "Code" datatype is same as String in pascal. And String in Pascal is defined as ARRAY of CHAR... :-)
For me it is obvious - I started to use Pascal 17 year ago on my first PC of 286 class... :-)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
he use the first charakter of String a. This is an Letter. The Letter A has the AsCII Code 65. B has the Code 66 .....
Now whe subtract from ASCII 65 the Value of 'A' (this is 65)
So 65 - 65 + 1 is 1. With the second parameter ",2,'<integer,2><filler character,0>'" we say the lenght must be 2. with the 3 parameter wie say that if the lenght is < 2 we will out this wit 0 at begin
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Its much like += its one of those things that had been there all the time, (it used to be in the STX file I think) but took a while before everyone started to use it. The reason being fear that it would not work in the next version. But once NAV started using += in the base app, its seems acceptable for us to do it to.
Unfortunately with the Text as array of CHAR, we now know that support for this undocumented "feature" will not be around in future versions of NAV. So we are all going to have to go around and do some code clean up I guess.
Why? This is common for all languages I know. Difference is jsut if text is array of char or wide char. But it is from basic definition of the text string... :-) I am not afraid that this will be not supported in next versions. Every language is using indexing to access elements of the string. 8)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Hmm I think you missunderstood. I didn't say you shoudln't use it. I use it my self. I just said it WILL NOT BE SUPPORTED in future versions of NAV.
Its not NDA anymore, so we are allowed to say this right?
But still I do not understand about what you are still talking... I do not know anything which can have impact to this... :-k
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
doesn't nav search ABCDEFGHIJKLNOPQRSTUVWXYZ in the substring that is e.g. 'A' or 'D'? :shock: :shock:
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Impact to what? I think we are both lost here. :?:
It seems... we can go through it elsewhere than on this forum...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.