Code data type can specify index like dimension??
teckpoh
Member Posts: 271
Dear all,
i upgraded my nav from v3 to v5SP1 then i noted my customized code in v3 was not working in v5 the coding is as below:
GetPrefix(Param_Cust : Record Customer) : Code[2]
IF Param_Cust.Type = Param_Cust.Type::Members THEN BEGIN
Var_Result[1] := 'K';
IF Param_Cust.Area <> '' THEN Var_Result[2] := Param_Cust.Area[1];
END;
IF Param_Cust.Type = Param_Cust.Type::Students THEN BEGIN
Var_Result[1] := 'S';
//MESSAGE(FORMAT(Var_Result[1]));
Var_Cust.RESET;
IF Var_Cust.GET(Param_Cust."Student's Parent Member No.") THEN
IF Var_Cust.Area <> '' THEN Var_Result[2] := Var_Cust.Area[1];
END;
EXIT(Var_Result);
i noted "Var_Result" datatype=code and its dimension =0 i juz curious how come we can specify Var_Result[1] or [2] to it since its dimension =0...and i do wonder whether v3 support index[1] or [2] for code..and it was not support by v5..coz when i run in v3..the EXIT(Var_Result) has value but in v5 the EXIT(Var_Result) return null value...correct me if i'm wrong..
i upgraded my nav from v3 to v5SP1 then i noted my customized code in v3 was not working in v5 the coding is as below:
GetPrefix(Param_Cust : Record Customer) : Code[2]
IF Param_Cust.Type = Param_Cust.Type::Members THEN BEGIN
Var_Result[1] := 'K';
IF Param_Cust.Area <> '' THEN Var_Result[2] := Param_Cust.Area[1];
END;
IF Param_Cust.Type = Param_Cust.Type::Students THEN BEGIN
Var_Result[1] := 'S';
//MESSAGE(FORMAT(Var_Result[1]));
Var_Cust.RESET;
IF Var_Cust.GET(Param_Cust."Student's Parent Member No.") THEN
IF Var_Cust.Area <> '' THEN Var_Result[2] := Var_Cust.Area[1];
END;
EXIT(Var_Result);
i noted "Var_Result" datatype=code and its dimension =0 i juz curious how come we can specify Var_Result[1] or [2] to it since its dimension =0...and i do wonder whether v3 support index[1] or [2] for code..and it was not support by v5..coz when i run in v3..the EXIT(Var_Result) has value but in v5 the EXIT(Var_Result) return null value...correct me if i'm wrong..
0
Comments
-
Each string (text or code) is in real "Array of chars". It means you can use the indexes to access each char in the string. That's ok and is working.
But to be able to assign the chars, you need to create string with correct length. Try to assign some string to the variable first, and after that you will be able to assign specific char to each position.
It means, try to do something like this first:Var_result := ' ';
0 -
GetPrefix(Param_Cust : Record Customer) : Code[2]
Var_Result[1] :='y';
Var_Result[2] :='z';
MESSAGE('%1....%2',Var_Result[1],Var_Result[2]);
MESSAGE(Var_Result);
EXIT(Var_Result);
hi kine, 10s 4 d replied...i use above code for my testing. The 1st message line(MESSAGE('%1....%2',Var_Result[1],Var_Result[2]);) gave me the value BUT second message line gave me blank value..how come ar? #-o
and the EXIT(Var_Result) shown blank as well...
Any idea?? 10s in adv 0 -
teckpoh wrote:GetPrefix(Param_Cust : Record Customer) : Code[2]
Var_Result[1] :='y';
Var_Result[2] :='z';
MESSAGE('%1....%2',Var_Result[1],Var_Result[2]);
MESSAGE(Var_Result);
EXIT(Var_Result);
hi kine, 10s 4 d replied...i use above code for my testing. The 1st message line(MESSAGE('%1....%2',Var_Result[1],Var_Result[2]);) gave me the value BUT second message line gave me blank value..how come ar? #-o
and the EXIT(Var_Result) shown blank as well...
Any idea?? 10s in adv
Try this:Var_Result := ' '; Var_Result[1] :='y'; Var_Result[2] :='z'; MESSAGE('%1....%2',Var_Result[1],Var_Result[2]); MESSAGE(Var_Result); EXIT(Var_Result);
In PASCAL (which is base language for C/AL), the string internal representation is, that on the first position (first byte of the string, index 0) is saved length of the string, after that each byte is one char. If you assign only the chars, you still have wrong string length. If you assign first some string, the length will be set to correct value and thus functions using the string will show correct output. Else the string is still "0" length, regardless you set some "char" of the string to some value. This is how it works in PASCAL. In C/AL it works in similar way, of course, because there are strings longer than 255 bytes, the internal representation is not in bytes, but it seems they are in words...0 -
i tried...and MESSAGE(Var_Result) still gave me blank value...0
-
Than problem must be somewhere else. For me it is working on all versions I tested it (4SP3, 5SP1).
Did you tried to debug it?0
Categories
- All Categories
- 75 General
- 75 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
