Macro: Need to return Linenumber of current insertion point

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Macro: Need to return Linenumber of current insertion point

Post by Ed Grossheim »

6/25/2007 1:31:50 PM

Hi- I am trying to evaluate Zeus. My control using macros is important to me.

Within a macro I would like to return the value of the line number of the current insertion point.

I am editing huge (?) vbs scripts. I need to automatically put in Msgboxes on a particular line in my vbs document via a macro (that I will write in vbs).

Currently my macro which works in Zeus is:

Code: Select all

Function key_macro()
    call zeus.screen_update_disable
    call zeus.write("Msgbox " &Chr(34) &"This is line Number    " & Chr(34))
    call zeus.screen_update_enable
    call zeus.screen_update
End Function

key_macro() 'run the macro
Now I guess I will somehow set a string variable to be equal to a macro_tag.

I see: "int get_char_at([line number] [,cursor]) " is available.

I see: "int get_line_pos() " is available.

I see: "$Line or $L Current line number" is available to me.

I have tried, but I am clueless as to the contraints of the Zeus object.

How can I set a string variable = the appropriate macro_tag, so I can have it return it and insert it in my Msgbox line (written by the macro)?

I have tried several things, and I do not come close. I just don't see enough examples, and I stuggle to translate meaning from a recipe in an alien script language.

I want to be sure that Zeus can help me or I must move on to evaluate another editor.

I would like to see a Macro repository categorized in the various scripting languages that we could all donate to and each learn from others!

Thanks in advance.

- Ed
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,
Within a macro I would like to return the value of the line number of the current insertion point.

Now I guess I will somehow set a string variable to be equal to a macro_tag.
The macro tag will return the line number but you can also use a Zeus builtin function to do this.

For example this VbScript macro will displays the current line and cursor position in the message bar:

Code: Select all

Function key_macro()
    call zeus.screen_update_disable

    ' get current line position using the tag
    tag_line_num = zeus.macro_tag("$Line")

    ' get current line position
    line_num = zeus.get_line_pos()

    ' get current cursor position
    cursor_pos = zeus.get_cursor_pos()

    ' build up a message
    message = "Tag Line: " & tag_line_num & " Line: " & line_num & " Cursor: " & cursor_pos

    ' display message in status bar
    call zeus.message(message)
    call zeus.screen_update_enable
    call zeus.screen_update
End Function

key_macro() 'run the macro
You should see that the details displayed on the bottom left of the status bar match the line and column values shown on the right of the status bar ;)
I have tried, but I am clueless as to the contraints of the Zeus object.
The Zeus documentation is defintiely not as good as it could be, but if you post a question to the forum I will be more than happy to help fill in the gaps :)

Basically all the Zeus keyboard functions can be run from within a macro, or you can also run one of the built-in macro functions.

To get help on a Zeus macro or keyboard function place the cursor on the function name and then use the Help Quick Help Current Word option and if help is available it will be displayed.

Make sure you have enabled VbScript as the default macro engine using the Options Editor, Options menu, Scripting Panel section.

This allows you to use the Macros menu to record a macro which will write a basic macro as a starting point that you can view, edit and save.
How can I set a string variable = the appropriate macro_tag, so I can have it return it and insert it in my Msgbox line (written by the macro)?
I think the macro given above should help with what you want to do, but if it does not just add a further reply to this forum message.
I want to be sure that Zeus can help me or I must move on to evaluate another editor.
I agree 100%. If Zeus does provide everything you need in an editor then there is no point in registering. I certainly suggest taking your time to fully evaluate the editor before even considering whether or not to register.

Cheers Jussi
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Thanks Jussi

Post by Ed Grossheim »

6/25/2007 7:53:10 PM

Back to you from Ed,

Wow
How impressive!!! Now which is most impressive, the speed of your response, the quality of your response, the useful-ness of your response, or the fact that you responded (incredible for many forums)l!!!!!!!

Thank you. In a bit I will register Zeus and hopefully could play a role with suggestions, and in the forums.

I will send this and more, as a response to your post, in the forum in a day or so.

I've tried it already and it solves my problem. I am happy.

--Ed

I will have to beg your continued patience, as I may have more problems which For ME are not small!!!!
Thanks again :lol:
Ed Grossheim
Posts: 18
Joined: Mon Jun 25, 2007 6:26 pm

Back one last (I think) time:

Post by Ed Grossheim »

6/26/2007 10:53:01 AM

I am becoming ecstatic about Zeus.

I love being able to be able to quickly be able to insert a Message box and line number in the program I am editing.

My macro in vbs using Jussi's advice, which gives the bonus of more info in the status box is as follows:

Code: Select all

Function key_macro() 
    call zeus.screen_update_disable 

    ' get current line position using the tag 
    tag_line_num = zeus.macro_tag("$Line") 

    ' get current line position 
    line_num = zeus.get_line_pos() 

    ' get current cursor position 
    cursor_pos = zeus.get_cursor_pos() 

    ' build up a message 
    message = "Tag Line: " & tag_line_num & " Line: " & line_num & " Cursor: " & cursor_pos 

    ' display message in status bar 
    call zeus.message(message) 
    call zeus.screen_update_enable 
    call zeus.screen_update

    call zeus.write("Msgbox " &Chr(34) &"This is line Number    "  &line_num & Chr(34) )

End Function 

key_macro() 'run the macro
From another Jussi solution (an answer to a different post I made),

I see another (and I like this better) way to go. It is to use Options/Default Document Type/Templates

I added a smart template as follows:

Smart Template created "M"
Menu Text: &Msgbox and Line No at Ins Pt
Keyword: M
Template Text: Msgbox "This is Line No. " $line
And checked box: Add to pop-up menu

=============================================
=============================================
In Use ...............

OK I am "in the program I am editing", I create a blank line where I am wanting to troubleshoot:

Type m spacebar and Voila.
============================================

Using Jussi's answer for running my program from the Dos problem (See http://www.zeusedit.com/forum/viewtopic.php?p=2583#2583)

I get to run my program with my program document visible.

The message box pops up, halting program execution, I then scroll up and down my program to find that line number:

Then scratch my head to figure out what kind of bone-head mistake I am making in my code!

Works great !!!!!!

I have been comparing EIGHT editors (VbsEdit, ScriptDebugger IDE, Web-Ed Editor, PrimalScope, PrimalScript 4.1 Pro, EditPlus2, and AdminScripEditor) side by side for days. I am looking for the most program per dollar spent (that is powerful To ME).

Looks like the better I understand Zeus, the more powerful a program it is for me, and the happier I am !!!

I am becoming more and more thankful that Zeus exists !!!!!!

---- Ed in Brighton, Illinois
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ed,
I see another (and I like this better) way to go.
One of the major problems new Zeus users face is just trying to learn what Zeus can and can't do :(

Zeus is very flexible and highly configurable and this can make it seem very complicated at first.

But with a bit of time and patience I promise Zeus will eventually start to make some sense ;)
I added a smart template as follows:

You might also want to look at the $MacroExcute and $ExpandTemplate tags which can also be used within a template. For more information just look for the Macro Tags page in the index of the Zeus help file.

These tags make it possible to create even more powerful templates ;)

Cheers Jussi
PS: I added some

Code: Select all

[/b] tags to you earlier posts to better highlight the code ;)
Post Reply