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

Thread: Subcode.vdm : The Macro Subroutines Project

  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
    315
    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
    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).

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

    I think this will help you.

    1. change to your user_macro folder and create a folder called: vdmhelp
    2. copy *.txt files related to macro instructions such as the 3 for Scribe, subcode.txt, etc to this new folder.
    3. assign the vdmhelp.vdm to a keystroke

    Now when you execute vdmhelp.vdm, you can easily select and open a text help file using the keyboard.

    This would be a really complex macro without the subcode.vdm subroutines, really demonstrates the reason for the whole Subcode project.

    PS: the Forum for some reason changed the filename to vdmhelp.vd.vdm, (tried twice) just rename it once you have downloaded it.

    Helpful ??

    Scott
    Last edited by Scott Lambert; October 26th, 2015 at 04:01 PM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  7. #7
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    315
    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

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

    I think this will help you.

    1. change to your user_macro folder and create a folder called: vdmhelp
    2. copy *.txt files related to macro instructions such as the 3 for Scribe, subcode.txt, etc to this new folder.
    3. assign the vdmhelp.vdm to a keystroke

    Now when you execute vdmhelp.vdm, you can easily select and open a text help file using the keyboard.

    This would be a really complex macro without the subcode.vdm subroutines, really demonstrates the reason for the whole Subcode project.

    PS: the Forum for some reason changed the filename to vdmhelp.vd.vdm, (tried twice) just rename it once you have downloaded it.

    Helpful ??

    Scott
    Hello Scott,

    I believe that I have done something similar. Specifically, similarly to the Vedit Doco Project, I have created a Scribe Doco Project. Well, Vedit has both, a doco project and an On-Line-Documentation. So, I thought that it would be nice if Scrbe and subcode also had both.

    I have a hunch that the ideas behind your vdmhelp.vdm macro are similar to the ideas behind the vedit doco project. So, I shall try to use it as a tutorial for the vedit doco project. After all, I like to see what is under the hood.


    Thanks as always,

    -peter
    Last edited by rejto12; October 25th, 2015 at 12:10 AM. Reason: correct typos

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

    I think this will help you.

    Now when you execute vdmhelp.vdm, you can easily select and open a text help file using the keyboard.


    Scott
    Hi Scott,

    I tried to use your macro and I had a minor problem. Specifically, when I executed the macro it displayed the list of txt files in the newly created directory user-mac\vdmhelp directory. However, I could not get out of the macro and could not use ant vedit command. In particular I could not open any file.

    I tried Ctrl-E to get out of the macro but it did not work. I have a hunch that this is a totally routine problem.



    Thanks as always,

    -peter

  10. #10
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    315
    Quote Originally Posted by rejto12 View Post
    Hi Scott,

    I tried to use your macro and I had a minor problem. Specifically, when I executed the macro it displayed the list of txt files in the newly created directory user-mac\vdmhelp directory. However, I could not get out of the macro and could not use ant vedit command. In particular I could not open any file.

    I tried Ctrl-E to get out of the macro but it did not work. I have a hunch that this is a totally routine problem.

    Thanks as always,

    -peter
    Hi Scott,

    Hi,

    I did some more experiments with your macro. Specifically, I did open it up in a directory and used the {Misc, Execute
    Current Buffer}} command. If I opened up the macro in my USER_MACRO directory, it worked fine. However, if I opened it up in another directory it did get hung up.

    Thanks as always.

    -peter

+ 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