Thursday, June 8, 2017

How to check the string is number or letter in Microsoft Dynamics NAV

Hi everybody, today I would like to share a function that probably valuable for you. Sometime you need to investigate whether it is a number form, absolutely Dynamics NAV does not have a standard function like that. This function needs a parameter (text). It is the string in which you want to investigate whether it is a number form. The result of the function returns “TRUE” or “FALSE” as Boolean.

Example

Declare the following variables:

Text Constant  
ENU Value
Text000 
100,000.00
Text001
It is a number form.
Text002
It isn’t a number form.

IF IsNumeric(Text000) THEN
  MESSAGE(Text001)
ELSE
  MESSAGE(Text002);

The message window displays:  It is a number form.

Now let’s see the code.

LOCAL PROCEDURE IsNumeric@1(p_gText@1000 : Text) : Boolean;
VAR
  i@1001 : Integer;
BEGIN
  FOR i := 1 TO STRLEN(p_gText) DO
    IF (FORMAT(p_gText[i]) IN  ['0'..'9']) OR (FORMAT(p_gText[i]) IN  ['.']) THEN
      IF STRLEN(DELCHR(p_gText, '=', DELCHR(p_gText,'=', '.'))) <= 1 THEN
        EXIT(TRUE)
      ELSE
        EXIT(FALSE)
    ELSE
      EXIT(FALSE);
END;

Documentation

Parameter
String
Type: Text constant or code
The string in which you want to investigate whether it is a number form.

Return Value
Type: Boolean
The result of function returns “TRUE” or “FALSE” as Boolean.

Remark
The IsNumeric function can detect comma (,) and dot (.) in the string so you not need to delete that characters before sent value to the function.

3 comments:

  1. Awesome Content, this is really informative blog on Microsoft Dynamics NAV, please keep sharing this intersting stuff for us, and we provides MS Dynamics Nav Jobs in USA

    ReplyDelete
  2. Apply online for Microsoft Recruitment. Get the information about the current and upcoming vacancies here.

    ReplyDelete
  3. If you use Exit, it exits the function. So your function only checks the following:
    Is the first sign a number or a '.' and is there not more than one '.'
    testresults of your function:
    '1test' returns true
    ' 10.00' returns false
    '.test' returns true

    ReplyDelete

Powered by Blogger.

About me

Popular Posts

Adbox