Do things differently

To start our discussion, let’s take a simple topic -

Few months back, in one of Orkut forum somebody had posted a problem as follows:

'I have to pick out a digit frm a code field. E.g. Code is '50123AD786' n I have to select 7th character from this field How can this be done...'

You all know it's simple and the common way to achieve this is:

Copystr([ur code variable],[position, say 7 for 7th position],[length, here for u its 1])

We have designed a new form here. Taken a new global variable called ‘Name’ of data type Text and inserted a textbox to display the variable.



We also have written a single line code as per the above syntax to display the 7th character of the ‘Name’ in a message box.

Now, can we do it in not so common way?

Yes, we can if we know that a text string in Navision is nothing but an array of characters (literally). So here ‘Name’ variable is nothing but an array of its length and we can fetch out the 7th character of it by simply referring it as Name[7]. To validate it, let us change the code in the ‘OnPush’ trigger of the Button as below:

Message (FORMAT (Name [7]));

Why we needed a FORMAT command? Just because the message box can only display text not character.

Here I entered ‘Snehanshu Mandal’ in the textbox and clicked on the button ‘Click me’. It’s displaying the 7th character of my name ‘s’.

Don’t you think it’s interesting?


Reblog this post [with Zemanta]

0 comments: