Can anyone tell me how to do the following in CSide?
(1)
>>>>>How to get the current position of the cursor<<<<<
The Selection object's information property can tell you this. Here's an example:
VertPos := Word.Selection.Information [wdVerticalPositionRelativeToPage];
HorizPos := Word.Selection.Information[wdHorizontalPositionRelativeToPage];
(2)
This code will tell you the vertical position of the selection - which is the cursor (insertion point) if no text is selected. The answer will be in twips, or 1/1440ths of an inch. To get the line number the cursor is on, you'd use
Word.Selection.Information[wdFirstCharacterLineNumber];
0
Comments
Basically, the route to go is creating a variable of the type Automation and read/write to its functions/properties/methods.
For example, let's look at working with Word. Create the Automation variable and call it "myWord". Select the correct Automation Server and the correct basic object (that would be 'Microsoft Word 8.0 Object Library'.Application in this case). Now when you call up the C/AL Symbol Menu (F5), you will see an extensive list with Methods and Properties for myWord.
To start using Automation, first thing to do is to initialize the connection with a CREATE(myWord) statement.
Now we come to the interesting part - how to use it. There's a plethora of functions, methods and properties available, and how to know what and which and how. Well, it's the macro language of Word, a.k.a. Visual Basic for Applications or VBA, that will be indispensible for you. Start "Record a Macro" in Word, do what you want Word to do for you, and look in the Macro Editor what code has been generated for performing this function. You will see which of, and in what way, the many methods and properties are used in the code. As the method/function/porperty names are the same, you can copy a lot of the code to Navision (just make the syntax correct, i.e. VBA has double quotes around text, Navision single quotes).
A tricky part are the constants. VBA uses these very often at many places and each constant represents a value to set an option or parameter. Many constants starts with the letters "wd" (for a typical Word constant, like "xl" stands for Excel, or "pj" for MS Project).
The "wdVerticalPositionRelativeToPage" in your question is a fine example of such a constant. To get the numeric value this constant represents, you call up the "Object Overview" (F2) under the menu View in VBA. Type (or copy/paste) the name of the constant in the search box. When found, the numeric value is displayed at the bottom of the window. The constant in this example has a value of 6. In Navision you have to create your own constants (integer variables), or use the numeric value directly if you have a very good memory for numbers.
Make extensive use of the Intellisense (a.k.a. Auto Complete) function in VBA - give it the name of the method and it will show all parameters/properties to select from. Also know that VBA has a context sensitive Help - put the cursor on a (key)word and press F1 for explanations, details and examples.
Taking it all together, your question can be replied as follows:
Variables:
myWord : Automation, value: 'Microsoft Word 8.0 Object Library'.Application
CursorVert : Decimal
CursorHor : Decimal
LineNumber : Integer
Code:
CREATE(myWord);
CursorVert := myWord.Selection.Information(6);
CursorHor := myWord.Selection.Information(5);
LineNumber := myWord.Selection.Information(10);
MESSAGE('Word cursor is at %1 vertical and %2 horizontal,\'+
'which corresponds to line %3',
CursorVert, CursorHor,LineNumber);
Happy expirementing!
John