Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.
USING THE VFP7 INTELLISENSE MANAGER (PART 1 OF 2)

Taking a shortcut
This article is about one new feature that comes with VFP7, the intelliSense manager. It’s a great tool for creating shortcuts and have it filled out for you.
Those who worked with Cobb’s Editor Extension know what I mean. Well here’s a secret, IntelliSense makes it possible to work with VFP in a way that you did use CEE.

An example
Essentially it comes down to this:
You type in some shortcut, it is picked up by CEE and transformed into a complete block of code, or documentation for that matter. Later more on that one.

The example I give you here is typing “DOC”.
This could be a shortcut for :
DO CASE
    CASE
    CASE
    OTHERWISE
ENDCASE



And wouldn’t it be nice if the cases to test would be filled into this code as well? So time for some coding samples. After this you could, with a bit of fantasy, work out your own shortcuts.

- Start VFP and choose tools->IntelliSense Manager.
- On the “custom” tab type the abbreviation in the replace textbox.
- Press Add and the text is added to the foxcode table.



In the next step you select the record with DOC and click the Script button. A memofield is opened and the first line is immediately filled in.
LPARAMETER oFoxCode

This is a reference to an object that contains a lot of information that is partially coming from the record and partially from other sources, like the location. More about that in the next article.

In the memofield type in the following code:
* In the following block of code there are 11 positions that are explained in the text of this article.
LPARAMETERS oFoxcode
LOCAL lcList, lcRetVal
LOCAL CRLF
CRLF = chr(13)+chr(10)
lcList = "0123456789"
* do this everywhere but not in the command window
IF oFoxcode.Location = 0 && Position 1
    RETURN "DOC"
ENDIF
* we will return a value after finishing this code.
oFoxcode.valuetype = "V" && Position 2
* Determine how many cases there are.
lcNumOfCases = "2"
lcNumOfCases = inputbox(" Number of cases: ",_screen.caption, lcNumOfCases) && position 3
IF AT( lcNumOfCases, lcList)>0 && position 4
    lnNumOfCases = val( lcNumOfCases )
ENDIF
IF lnNumOfCases > 0
    lcCase = ""
    FOR lnI = 1 to lnNumOfCases && position 5
        lcCase = lcCase+"CASE "+inputbox("CASE #"+Alltrim(str(lnI))+": ",_screen.caption) + CRLF + CRLF + CHR(9)
    ENDFOR
ENDIF
lcCase = lcCase+"OTHERWISE "+CRLF+CRLF && position 6
TEXT TO lcRetVal TEXTMERGE NOSHOW
DO CASE && position 7
    ~your code goes here~ && position 8
    <<lcCase>> 
ENDCASE && position 9
ENDTEXT && position 10
RETURN lcRetVal &&position 11

In the above code I point to 11 places where something interesting happens, in the remainder of this article I explain what happens. At point 1 of the code you read a line “oFoxCode.location = 0”. The location property of the foxcode object is the place where you’re editing the code. There are 5 location possible:


Location Meaning 0 Command Window 1 Program File 8 Menu Snippet (like a menu option starting a procedure) 10 Code Snippet (same as method) 12 Stored Procedure (in the database container)

At point 2 we determine that we return a value to display, these are the possibilities:

L displays a drop-down list populated from the Items array V Displays Value T Displays a Quick Info Tip from ValueTip

At point 3 we determine the number of cases in our structure. Using the inputbox() function returns a character value. As we do not know whether a readable value is placed in the inputbox we have to check that. This is done at position 4.

At position 5 a for … endfor loop is used to fill in a variable. This starts with the “CASE” word and is followed with a double carriage return+Linefeed and a TAB. Thus creating an extra line for some code for you to fill in with things that should happen. On position 6 I complete the structure with the OTHERWISE clause.

On position 7 the BIG TRICK is shown, filling one variable with a complete block of text through the textmerge possibility that VFP offers. Apart from one particular use, shown to me by John Zijlstra, I never saw the real use for textmerge possibilities. THIS, however is quite different stuff! On position 8, the line is “~your code goes here~”. The tilde is quite a character. It shows VFP where it has to place the cursor. Once this code is running it will fill in the structure and place the cursor on this line and select the entire line.

On position 9 another trick of textmerging is shown. <> places the contents of that variable literally into the text.
lcCase, as used here, is the internal structure of the do case …endcase. We filled that before.

On position 10 the textmerge stops. The variable is completely filled. On position 11 the variable is returned.

It’s about time to see what happens when we run this code. Let’s modify our command to test.prg. We typ in DOC.



After typing “DOC” the first question is asked, how many cases are there to test, I take a default value of 2. Less then that could be handled in an IF statement.



Next we get the question about the cases to test for. Here is the first case in the inputbox. I spare you for the second inputbox. I guess you know what’s in there. (Right, test=2).



and this is the result. As you can see, the line “Your code goes here” is selected.
Nifty tool, this Intellisense manager. In my next article I go deeper into scripts and how to call them. Hope you liked this so far. May the fox be with you and may you be Foxited about this site!

ABOUT THE AUTHOR: BOUDEWIJN LUTGERINK

Boudewijn Lutgerink Programming is one of the many hobbies of Boudewijn. He has worked with computers since 1985 and is the author of two books from Sybex. He has a weblog at http://weblogs.foxite.com/boudewijnlutgerink.

FEEDBACK

jav nik @ 7/16/2010 3:04:28 PM
hi
i have a problem can you help me?
im converting a fox software to .net software (converting from dos to windows)
i have a problem i have a function which i can not convert it to c# can you help me i put this function code here .



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: