Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TIP of the Day: GETWORDNUM
Message
From
03/04/2003 03:10:07
Walter Meester
HoogkarspelNetherlands
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
TIP of the Day: GETWORDNUM
Miscellaneous
Thread ID:
00773431
Message ID:
00773431
Views:
75
All,

Just wanted to point out the value of the GETWORDNUM function.

Before I used this function (which also has an equivalent in FoxTools) I programmed blocks like this:
DO CASE
   CASE nNumber = 1
        cOutPut = "Output string1"

   CASE nNumber = 2
        cOutPut = "Output string2"

   CASE nNumber = 3
        cOutPut = "Output string3"

   CASE nNumber = 4
        cOutPut = "Output string4"

   ....
ENDCASE
with the GETWORDNUM function you can do this:
cOutput = GETWORDNUM("Output string1~Output string1~Output string1~Output string1, nNumber, "~")
which clearly save lots of coding and does not distract you from more important programming lines.

But what to do with a character denominator
DO CASE
   CASE cVar = "X1"
        cOutPut = "Output string1"

   CASE cVar = "X2"
        cOutPut = "Output string2"

   CASE cVar = "X3"
        cOutPut = "Output string3"

   CASE cVar = "X4"
        cOutPut = "Output string4"

   ....
ENDCASE
Well then you could use something like this:
cOutput = GETWORDNUM("Output string1~Output string2~Output string3~Output string4, (AT(cVar,"X1 X2 X3 X4 ")+2)/3, "~")
Also handy for filling arrays:
DIMENSION aArray[5,2]
FOR nT = 1 TO 5
   aArray[nT,1] = GETWORDNUM("Item 1~Item 2~Item 3~Item 4~Item 5",nT,"~")
   aArray[nT,2] = VAL(GETWORDNUM("1 2 3 4 5",nT))
ENDFOR
Not to mention decoding fields in delimited ASCII files or HL7 strings.

Walter,
Next
Reply
Map
View

Click here to load this message in the networking platform