Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to copy/paste C# and QM code in the forum (with colors etc)

To copy/paste code from QM to the forum:
- QM: use menu Edit -> Other formats -> Forum. It copies the selected or all text to the clipboard.
- Forum: simply paste in the post. Don't use the Code button.

To copy/paste code from the forum to QM:
- Forum: click the Copy link at the top-right of the code.
- QM: paste in the code editor. If QM displays link 'Click here to correct the pasted code' , click it. See also ForumFunctionsToQm.

QM code in the forum is with commas (,) and semicolons (;) instead of tabs and spaces. It's because tabs and spaces may disappear in the forum. These characters are important. When you copy text using menu Edit -> Other Formats, it replaces tabs and spaces to commas and semicolons. When you copy forum code and paste in QM, QM restores tabs and spaces.

See also: QM dialog code in the forum
Installing and using QM functions from the forum

Assume you have found code like this example:

Function GetWinXY
Copy      Help
function# hwnd [&x] [&y] [&width] [&height] [hwndparent]

;Stores window position and size to int variables x, y, width and height.
;Returns 1 if successful, 0 if not.

;hwnd - handle of the window. Can be top-level or child window.
;hwndparent - handle of the parent window. If used and not 0, the coordinates will be relative to the client area of hwndparent. Otherwise - coordinates in screen.

;int x y cx cy
;GetWinXY(win("Quick Macros") x y cx cy)
;out "%i %i %i %i" x y cx cy

if(!hwnd or !GetWindowRect(hwnd &r)) ret
if(hwndparent) MapWindowPoints(0 hwndparent +&r 2)
if(&x) x=r.left
if(&width) width=r.right-r.left
ret 1

1. Copy the code.
2. In QM, create new function. To create new function, click menu File -> New -> New Function. Name it GetWinXY, or whatever name is given above the code or in examples. If the name is not given, you can name the function as you like.
3. Paste the code in the new empty function. If displays 'Correct...' link, click it.

The code or/and the post usually contains information what the function does and how to use it. Only read the description. Don't need to learn or modify the code.

Testing (optional)
1. Create new macro.
2. If EXAMPLE code is given in the function code, copy it and paste in the macro. If several examples are given, copy/paste one of them. To uncomment, select the code and right click the selection bar at the left.
3. Run the macro.

Sometimes example code is not within the function code, but somewhere else in the post. Copy it and paste in the macro. If example code is missing, create it. Examples:
Copy      Help
FunctionName somevalue somevalue2
somevariable=FunctionName(somevalue somevalue2)
Using in your macros
You can use the function in your macros, functions, menus, etc. Don't paste the code there, but instead use the name, like in examples. In most cases you should not run the function or assign a trigger, but instead run your macros that call the function.

Member functions
Member functions are installed like functions, except that you have to use menu File -> New -> New Member Function.

These functions usually have . in the name, for example str.FunctionName. The part before . is the type of variables with which the function can be used. Examples of calling the function when the type is str:
Copy      Help
str s
s.FunctionName(somevalue somevalue2)
somevariable=s.FunctionName(somevalue somevalue2)
What item type it is (function, macro, etc)?
Usually item type is given in the post. If not, usually you can understand from the code or from the comments. For example, if the code looks like the above example function, or just contains function at the beginning, it's probably function. Otherwise, if it's not menu or toolbar, it's probably macro.

Often there is only small code example, not entire function or macro. It can be placed anywhere. For testing, it is recommended to use a macro.

Sometimes above the code is given the recommended trigger. It is an encoded trigger string. Select the trigger string (not including "Trigger "), copy, and paste in QM, into the Trigger field. The trigger field is on the toolbar, between the Properties and Save buttons.

Attached files
Sometimes code is in an attached file, not in the post text. Then installing is easier. Download the file and open. It opens in the QM file viewer. Click Import. It creates the function(s) for you.


Learn about functions: ... NTIPS.html

That will be very useful for people who didn't know how to do that before. Explained very clearly.
Taking on Quick Macros one day at a time

Forum Jump:

Users browsing this thread: 3 Guest(s)