+ Reply to Thread
Page 1 of 12 12311 ... LastLast
Results 1 to 10 of 120

Thread: Subcode.vdm : The Macro Subroutines Project

Hybrid View

  1. #1
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383

    Subcode.vdm : The Macro Subroutines Project

    The Macro Subroutines Project

    The attached Subcode.vdm contains a number of useful subroutines that your macros can use. Put subcode.vdm in your USER_MACRO folder. To call one of these subroutines, use:

    call_file(r,"subcode.vdm","label")

    where r<>100 and label is the name of the subroutine

    There are several reasons behind the Macro Subroutine Project:

    - why write the same code more then once? Every time you do, there is the chance for typos and logic errors. Seems better to use (proven) code located in a subroutine library

    - if you only recently began Vedit macro programming, these subroutine will allow you to write macros that otherwise may be beyond your current skill level.

    - think of these subroutine as "commands created by users". Ever wished for a command that would eliminate writing many lines of code?

    To make these subroutine work, there are some register usage rules in both creating and using them:

    - Text & numeric registers between 10 and 19 are for Input values

    - Text & numeric registers between 20 and 29 are for Output values

    - Text & numeric registers between 30 and 49 are subroutine working registers. At the start of each subroutine, these registers are pushed to the stack, and are restored just before returning.

    The current subroutines :

    Clipreg puts the contents of t-reg 10 into the Windows clipboard.

    Getcal puts a calender for any month, year, into t-reg 23. calls getdate

    Getdate provides the full date (October 10, 2015), day of week (Monday), Month name (October), day of week number (Sunday=0), and number of days in month.

    Getfile asks user to select a file using Vedit internal command get_filename and returns component parts (path, filename, extension, etc)

    Onecol lets the user select an item from one column using the keyboard and puts item into t-reg 20. Line number of item selected is also returned. Provides ability to restrict user movement to a line range.

    Clipreg puts the contents of the Windows clipboard into t-reg 20

    Reset empties text registers and sets numeric registers to zero in range 10-29

    The subroutine are fully documented in the attached Subcode.txt.

    Please see the code to the included cal-demo.vdm which demonstrates the getcal and getdate subroutines. Consider how much code writing was saved by using these subroutines.

    (if you rather write your own code then use these subroutines, and you have the time and skill, more power to you!)

    It is my hope that one day Subcode.vdm will be to macro subroutine what Key-mac.lib is to keystroke macros. I hope other users will suggest additional subroutines, improve existing ones, and contribute their own subroutines.

    (WARNING: Massively Unwarranted Optimism Detected)

    Comments, code, suggestions, etc...

    Scott
    Attached Files Attached Files
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    The attached subcode2.zip adds the following subroutines to subcode.vdm :

    binary : converts the number in #10 to binary, result is stored in t-reg 20 (max number for #10 is 131071)

    getdir : gets a directory listing and returns the buffer# holding it. Can specify number of columns and whether to display directories

    multicol : allows user to select an item from a multi-column list and returns item in t-reg 20. Can limit user to a line range, same as with onecol

    isdir : determines if result from using onecol or multicol with getdir is a directory

    These subroutine are documented in the enclosed subcode.txt.

    The included keyopen.vdm demonstrates using getdir, multicol, and isdir in a single macro, allowing you to select and open a file using the keyboard from a 4 column directory list. Again consider the amount of code writing that was saved by using the subroutines.

    Comments....

    Scott
    Attached Files Attached Files
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  3. #3
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi,

    The attached subcode3.zip adds to the list of subroutines:

    A slightly altered version of Pauli's random number generator subroutine

    Keystat & Keytest act as front-ends to the internal command key_shift_status allowing you to test which key was pressed by key name (caps, num, scroll, alt, ctrl, shift).

    Both are documented in enclosed subcode.txt.

    Come on, surprise me and reply.... Least communicative group of users ever. I must be the only one who enjoys writing Vedit macros. Oh well...

    Scott
    Attached Files Attached Files
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  4. #4
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    321
    Hello Scott,

    I would like to suggest a help subroutine. That is to say a subroutine that would display the subcode.txt file.

    PS.

    I have highlighted the convert binary subroutine. Then I copied it to a new buffer and executed it via the {Misc, Execute Buffer} command. It worked like a charm. May be you could mention this as an alternate way to execute subcode.vdm.


    Actually, I am using Pauli's Execute Highlighted Block macro. So, a belated thank you to Pauli. Also, this macro would be a wonderful addition to subcode.vdm. So, I am asking Pauli too submit it. Certainly this macro ought to be better known.


    Thanks as always,

    -peter

    Thanks as always,

    -peter

  5. #5
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    321
    Quote Originally Posted by Scott Lambert View Post
    Hi,

    The attached subcode3.zip adds to the list of subroutines:

    A slightly altered version of Pauli's random number generator subroutine

    Keystat & Keytest act as front-ends to the internal command key_shift_status allowing you to test which key was pressed by key name (caps, num, scroll, alt, ctrl, shift).

    Both are documented in enclosed subcode.txt.

    Come on, surprise me and reply.... Least communicative group of users ever. I must be the only one who enjoys writing Vedit macros. Oh well...

    Scott

    Hi Scott,

    I would like to suggest a subroutine of mine, sync(#1,#2).vdm , to add to your subcode.vdm library.

    Before, uploading it, let me give you a short description. It synchronizes the cursor movement between win#1/bu#1 and win#2/buf#2. Here the parameters #1 andf #2 have to be either set manually or set by a calling macro. At present that subroutine moves the cursor only down in each of the the windows #1 and #2. It would be easy to
    synchronize the remaining 3 cursor movements as well.

    I gleaned the code from the Vedit distribution macro, COMPARE.VDM. I also slightly enhanced that code. Specifically, the original code synchronized win1 and win2. I enhanced it to includ any two windows, with any give window numbers.

    I believe that this simple enhancement is also useful. Specifically, I use it together with the {Search, compare buffs..} menu command. Now suppose that I have several buffers open. Suppose also that Vedit gave these buffers the numbers 1,2,...n. Let #1 and #2 denote those buffer numbers that I wish to compare. Then it is useful to
    sychronize the cursor movements between these two buffers.

    I have a hunch that in the special case of #1=1 and #2=2, that synchronization idea was implemented by Christian. In short my subroutine is a minor enhancement of his.

    Now I shall upload my subroutine:
    Attached Files Attached Files

  6. #6
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    321
    Quote Originally Posted by Scott Lambert View Post
    Hi,

    The attached subcode3.zip adds to the list of subroutines:

    A slightly altered version of Pauli's random number generator subroutine

    Keystat & Keytest act as front-ends to the internal command key_shift_status allowing you to test which key was pressed by key name (caps, num, scroll, alt, ctrl, shift).

    Both are documented in enclosed subcode.txt.

    Come on, surprise me and reply.... Least communicative group of users ever. I must be the only one who enjoys writing Vedit macros. Oh well...

    Scott

    Hi,Scott,

    I have added the SETUP-HTTP subroutine from the VEDITPDF.VDM macro. At the same time, as per your instructons, I have renamed the T-reg, where the macro
    gives the shell command for the browser to T-reg 20.

    Now, a belated thank you to Pauli Lindgren for his elegant subroutine.

    -peter
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    "That is to say a subroutine that would display the subcode.txt file."

    You don't need a subroutine, you want a keystroke macro such as:

    [visual exit]file_open("|(user_macro)\subcode.txt")

    Yes, you can certainly copy code from subcode.vdm to your own macro. I would say the downside to doing that is I hope the subrountine code will be continuously improved & enhanced, so by copying you are stuck with that particular version of the code in your macro unless you recopy. Whereas if you do a call_file, you know you are always using the latest and greatest version of the code.

    I should explain that difference between these subrountines and normal macros. A normal macro does something useful and is complete as far as the code goes. These subrountines require additional code from the parent macro to really do something useful. Pauli's Execute Highlighted Block macro is a normal macro, no additional code is needed.

    When you used the binary subroutine, there was no user interface to ask for the decimal number and to display the binary result. A subroutine macro is designed to interact with another macro as opposed to interacting with the user directly.

    I hope the above makes sense, I feel I could phrase it better, but it is 5:20 am when I write this.

    Scott
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  8. #8
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    321
    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    When you used the binary subroutine, there was no user interface to ask for the decimal number and to display the binary result. A subroutine macro is designed to interact with another macro as opposed to interacting with the user directly.

    I hope the above makes sense, I feel I could phrase it better, but it is 5:20 am when I write this.

    Scott
    Hello Scott,

    Yes your above comment makes very good sense. I just realized that many many years ago I have written my own Subroutine.vdm. This was restricted to subroutines that I use in connection with my user.mnu files. So, I called it
    pr_menu.vdm.

    Now one of the useful features of your subroutine macro is that I can use your standard for naming T-registers.


    Well, here is one of my old subroutine. ( I have done some updating, but not much.)


    //
    // "USER_MENU" Deletes EXTRA(path) from FILENAME & puts result to T reg 85.
    // Chooses a .mnu file without extension name & puts the result into the T reg 84.
    // Then it sets the USER_MENU configuration string to this name.

    //
    :USER_MENU:
    Get_Filename(89,`"|(USER_MACRO)\user-mnu\*.mnu"`) //Get by point and shoot an .mnu file
    // and place it into T-reg 89.
    Reg_Load(124,@89) //Load the content of T-Reg 89 into the "{USER}" register.
    Buf_Switch(20)
    Reg_Set(90,`"`) // Place the quotation charecter into T-reg 90.
    Reg_Set(90,@89,APPEND) // Append T-reg 89 to T-reg 90. In other words prepand the " character.
    Reg_Set(90,`"`,APPEND) // Finally append the " character to the T-reg 90.
    File_Open(@90) // Open the file whose complete file name is in T_Reg 90.
    Reg_Set(91,FILE_ONLY) // Put the FILE_ONLY predefined string into T-Reg 91.
    // In other words, delete extension.
    File_Close(NOMSG) // Close this file.
    Buf_Close(20) // Close this buffer.
    Reg_Set(85,"&U-")
    Reg_Set(85,@91,APPEND)
    Config_String(USER_MENU,@85)
    Return

    I would like to submit it to you. At the same time, I am asking you edit it to confirm to your subroutines.


    Thanks as always.

    -peter

  9. #9
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    I missed this post until now:

    //
    // "USER_MENU" Deletes EXTRA(path) from FILENAME & puts result to T reg 85.
    // Chooses a .mnu file without extension name & puts the result into the T reg 84.
    // Then it sets the USER_MENU configuration string to this name.

    //
    :USER_MENU:
    Get_Filename(89,`"|(USER_MACRO)\user-mnu\*.mnu"`) //Get by point and shoot an .mnu file
    // and place it into T-reg 89.
    Reg_Load(124,@89) //Load the content of T-Reg 89 into the "{USER}" register.
    Buf_Switch(20)
    Reg_Set(90,`"`) // Place the quotation charecter into T-reg 90.
    Reg_Set(90,@89,APPEND) // Append T-reg 89 to T-reg 90. In other words prepand the " character.
    Reg_Set(90,`"`,APPEND) // Finally append the " character to the T-reg 90.
    File_Open(@90) // Open the file whose complete file name is in T_Reg 90.
    Reg_Set(91,FILE_ONLY) // Put the FILE_ONLY predefined string into T-Reg 91.
    // In other words, delete extension.
    File_Close(NOMSG) // Close this file.
    Buf_Close(20) // Close this buffer.
    Reg_Set(85,"&U-")
    Reg_Set(85,@91,APPEND)
    Config_String(USER_MENU,@85)
    Return

    Nice macro. Attached is a version that uses subcode.vdm. Notice how much smaller it is.

    Scott
    Attached Files Attached Files
    Last edited by Scott Lambert; October 31st, 2015 at 10:07 AM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  10. #10
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    321

    Another proposed subroutine.

    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    I missed this post until now:

    //
    // "USER_MENU" Deletes EXTRA(path) from FILENAME & puts result to T reg 85.
    // Chooses a .mnu file without extension name & puts the result into the T reg 84.
    // Then it sets the USER_MENU configuration string to this name.

    //
    :USER_MENU:
    Get_Filename(89,`"|(USER_MACRO)\user-mnu\*.mnu"`) //Get by point and shoot an .mnu file
    // and place it into T-reg 89.
    Reg_Load(124,@89) //Load the content of T-Reg 89 into the "{USER}" register.
    Buf_Switch(20)
    Reg_Set(90,`"`) // Place the quotation charecter into T-reg 90.
    Reg_Set(90,@89,APPEND) // Append T-reg 89 to T-reg 90. In other words prepand the " character.
    Reg_Set(90,`"`,APPEND) // Finally append the " character to the T-reg 90.
    File_Open(@90) // Open the file whose complete file name is in T_Reg 90.
    Reg_Set(91,FILE_ONLY) // Put the FILE_ONLY predefined string into T-Reg 91.
    // In other words, delete extension.
    File_Close(NOMSG) // Close this file.
    Buf_Close(20) // Close this buffer.
    Reg_Set(85,"&U-")
    Reg_Set(85,@91,APPEND)
    Config_String(USER_MENU,@85)
    Return

    Nice macro. Attached is a version that uses subcode.vdm. Notice how much smaller it is.

    Scott
    Hi Scott,

    A big thank you for your subroutine. It sure simplified my macro.

    Now, I would like to submit another subroutine. Specifically, the one tht searches for a word. That is to say, for astring
    of letters.

    At first I thought that it is in the On-Line_Help. First I thought to try the Search"|W") command. However, here W stands for White Space. Then I found a macro/subroutine in Chapter 3 of the Macro Language Manual.

    The following is a slight adaptation:

    -------------------------------------------------------------------------------------

    Search("|A",ADVANCE)
    repeat (ALL)
    { if ((Cur_Char >= 'A' && Cur_Char <= 'Z') || (Cur_Char >= 'a' && Cur_Char <= 'z')) {Char(1)} else {break} }

    -----------------------------------------------------------------------------------------------

    Actually, it would be ice if you could copy other examples as well from the Manual. Most of the time they are simple, so your subroutine.vdm would have something for beginning vedit users as well.


    I simply copied it from the Vedit Macro Language Manual Chapter 3. At the same time the ( ) string had to be replaced by the string, (). Similarly for the Logical or string, | | had to be replaced by ||. To automate this procedure, I edited the
    ClipclatchX.vdm. So, just use the {Misc. More Macros, Clipclatch} Menu command with the attache ClipclatchX.vdm.


    Happy Clipcatching.

    -peter

    OOPs, I forgot to rename ClipclatchX.vdm to ClipclatchX.txt

    I shall do it in my next message.
    Attached Files Attached Files

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts