Converting the the first character to numbers.
asembereng
Member Posts: 220
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
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
-
NewCodeField := COPYSTR(YourCodeField,1,1)
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.. :-#0 -
if this field is not an primary key, or part of them. Than you can do following.
YourTable.findset(true) repeat case copystr(YourTable."YourCodeField",1,1) of 'A': begin YourTable."YourCodeField" := '01' + copystr(YourTable."YourCodeField",2,Strlen(YourTable."YourCodeField")); //or 01' + DELCHR(YourTable.YourCodeField,'<',DELCHR('A'); YourTable.modify; end; 'B': begin YourTable."YourCodeField" := '02' + copystr(YourTable."YourCodeField",2,Strlen(YourTable."YourCodeField")); YourTable.modify; end; 'C': begin end; end; until YourTable.next = 0;Do you make it right, it works too!0 -
-
#-o another one, that savatage are faster. fuck, i should press the "turbo" button on my old 386 computer :-DDo you make it right, it works too!0
-
To avoid writting code that is specific to each letter of the alphabet you can use
STRPOS('ABCDEFGHIJKLNOPQRSTUVWXYZ',COPYSTR(OriginalCode,1,1))to convert the leading letter to an integer. You can then format the integer and go from there.0 -
I understand what savatage said but jreynolds i am a bit confuse about you said, would you mind explaining further? thanks0
-
garak wrote:i should press the "turbo" button on my old 386 computer :-D
Always wondered why you wouldn't want that button pressed? :-k0 -
than my old DOS Navision application is to fast :-DDo you make it right, it works too!0
-
Savatage wrote:garak wrote:i should press the "turbo" button on my old 386 computer :-D
Always wondered why you wouldn't want that button pressed? :-k
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.0 -
Hey guys, why you are doing it in this hard way? You need just one line of code...

b := FORMAT(a[1]-'A'+1,2,'<integer,2><filler character,0>')+COPYSTR(a,2);
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...
0 -
to hard way --> he can learn loops, if or Case statemant and string function ;-)
one line coding is for old navision coder
Do you make it right, it works too!0 -
That's why he has 6220 posts - he's really great at this Nav stuff \:D/0
-
Not old, just REALLY goodgarak wrote:one line coding is for old navision coder
0 -
garak wrote:#-o another one, that savatage are faster. fuck, i should press the "turbo" button on my old 386 computer :-D
HAAHHAHA.... Oh my god... This has to be the post of the month!
Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
kine wrote:Hey guys, why you are doing it in this hard way? You need just one line of code...

b := FORMAT(a[1]-'A'+1,2,'<integer,2><filler character,0>')+COPYSTR(a,2);
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...
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.Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
Kine i am confuse can you explain what that simple line does?0
-
asembereng wrote:Kine i am confuse can you explain what that simple line does?
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)0 -
Alex Chow wrote: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.
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... :-)0 -
with format(a[1] - 'A' + 1) the programm do following:
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 beginDo you make it right, it works too!0 -
ah, forgotten to press Submit instead of Preview ](*,)Do you make it right, it works too!0
-
Thanks garak for making this simple description... may be it will be much more understandable than my one... :whistle:0
-
PleaseDo you make it right, it works too!0
-
Alex Chow wrote: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.
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.David Singleton0 -
David Singleton wrote: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)0 -
kine wrote: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)
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?David Singleton0 -
David Singleton wrote:Mhh 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... :-k0 -
1 personal question about this:
DOES THIS REALLY WORK? :shock:To avoid writting code that is specific to each letter of the alphabet you can useCode:
STRPOS('ABCDEFGHIJKLNOPQRSTUVWXYZ',COPYSTR(OriginalCode,1,1))
to convert the leading letter to an integer. You can then format the integer and go from there.
doesn't nav search ABCDEFGHIJKLNOPQRSTUVWXYZ in the substring that is e.g. 'A' or 'D'? :shock: :shock:0 -
kine wrote:But still I do not understand about what you are still talking... I do not know anything which can have impact to this... :-k
Impact to what? I think we are both lost here. :?:David Singleton0 -
David Singleton wrote:kine wrote:But still I do not understand about what you are still talking... I do not know anything which can have impact to this... :-k
Impact to what? I think we are both lost here. :?:
It seems... we can go through it elsewhere than on this forum...
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions



