Global Variable by file

Product Compare Forums Multi-Edit Support Global Variable by file

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1440
    Leslie Satenstein
    Participant

    Have a requirement to put a workorder number into the preamble of a file (comment area describing maintenance history, etc). It is entered via a template.

    Then, in the source code area, I need a method to extract the workorder number (which was entered above. If a workorder was not entered, then a null string should be returned, otherwise the string with the workorder number should be returned. The workorder number is an alphanumeric.

    EX: In header area
    |* 02-22-02 [15:34] add for loop to redo testing . Workorder 11983
    |* 03-13-03 [10:35] add while loop to adjust value. Workorder 12024

    Along new code..

    while len(string.length) < 3 //SN 12024
    string.length = “0” & string.length
    endwhile //EN 12024

    Thus a history of the code insert or code removal is retained.
    (Due to blank char suppression, formatting is not shown perfectly)

    #5153
    Clay Martin
    Keymaster

    Hi,
    Is the current WON the top one or the bottom (does the template insure this?) or must the date be consulted? Also what is the criteria for knowing if the WON found was old or new, eg, how do you insure that the WON found was put in for this work or for last change to file?

    Sounds interesting,
    Clay

    #5155
    deleyd
    Participant

    Not sure if I understand the problem but sounds like you want to parse the first few lines of a text file. You can use TOF; to position to the top of the file, then GET_LINE to get the current line, then XPOS to search the current line for keywords. Then DOWN; to move to the next line. So something like:

    [code:113ve61f]TOF;
    XPOS("Workorder",GET_LINE,1);[/code:113ve61f]

    You could parse the current line to see if it begins with a date of the format dd-dd-dd using FIND_TEXT (I’m not expert at UNIX regular expressions but I’ll give it a try here)

    [code:113ve61f]IF ( FIND_TEXT("^[0-9]-[0-9]-[0-9]",1,_RegExp) ) {[/code:113ve61f]

    So hopefully these are some ideas.

    #5156
    Leslie Satenstein
    Participant

    I have a template that adds a comment to the source file. I invoke the template at the top of the source where there is room. One of the keywords (without a prefix ) is a workorder number. Ex, sfc066 could be a work order number for shop floor control, as mod 066. There is no specific pattern to the won.

    Now, at every modified group of lines, as a comment,
    I would have //sfc066.sn
    …..
    //sfc066.en

    or …. //sfc066.n single line insert
    for an insert
    and where lines are deleted the text lines are commented out but at the right there is
    //sfc066.so
    …… //sfc066.eo

    So what I want to do is after the template is invoked and the prompt is made for the WON, to remember the WON. and be able to put the WON after the // but before the SN, EN, SO, EO, or .n or .o triggers.

    If you require a code example, review the file I added.

    #5159
    Michal Vodicka
    Participant

    If you don’t need persistent variable which persist MEW restart, use buffer property for current file and access in templates which create EOL comments.

    If you need peristent WON tied to file name, take a look at FileToGlobalVarName() macro in metools.sh file. It creates unique global variable name which is associated with a file pathname. So you can call:

    [code:2sidu6eu]Set_Global_Str(FileToGlobalVarName(File_Name, "WON", WonValue)[/code:2sidu6eu]

    to save a value to a global variable and later restore it as

    [code:2sidu6eu]str WonValue = GlobalStr(FileToGlobalVarName(File_Name, "WON"))[/code:2sidu6eu]

    Variable should be persistent for current session. Of course, you’d have to write simple helper macros and call them in templates which create both header and EOL comments.

    #5160
    Leslie Satenstein
    Participant

    One thing I tried was to add a string variable to a global structure and use a function to set and retrieve the global variable string. It did not work. The string address in the structure did not point to what I needed and crashed MEW32.exe. So that approach is out.

    I also prefer to be an end user, and not a MEW32.exe coder. I would do some coding, but in the cmac manual I found the description of the grammer, but not a description of the “how to”.

    I will certainly look at the hints I receive. Since from a template I can invoke macros, that gives me the means to set and read a string value.

    Thanks to all.

    #5161
    deleyd
    Participant

    Some examples of using global structures and arrays is at [url:z36tc4zl]http://www.multiedit.com/forums/viewtopic.php?t=561[/url:z36tc4zl]

    You also mentioned in a post above that you were supplying some example code of what you’re trying to do but I don’t find any code files attached. Perhaps you could attach an example?

    #5162
    Michal Vodicka
    Participant

    The problem is simple and using structures or arrays won’t give any advantage here. Forget about it. Instead, read Global variables chapter in CMAC manual. CMAC naturally supports named global strings and integers which is sufficient for most of simple tasks.

    I agree CMAC manual could be more detailed but still I believe it is sufficient enough. Anyway, there is almost 7 MB of macro code installed which contain everything necessary to learn “how to”. It is better than any examples because it is MEW itself and you can learn how real problems are solved.

    #5167
    Leslie Satenstein
    Participant

    I can use a function to set a global variable. But I would like to use a prompt to read the work order number (won). The won is an alpha numeric string.

    In the prompt, I would fetch the won, and store in the global. Then with the template, I would emit the string at the appropriate time. Emitting the string via a function call is easy. Reading the won via a prompt so that it is a global appears much more difficult.

    Here is the work flow. I get a work order to change some source code.
    I enter into the source code, via a template prompt for the program id, my name, I use the system date, and I prompt for the WON.

    I then proceed to make changes to the code, using the won as appropriate (as explained in an earlier discussion).
    The WON would ideally have to persist until replaced by the next won. At this time it does not have to persist after the editor is closed, but if it does, all the better.

    So far, Michael and Dave have really made me excited about pursuing this extension to my baan.s file.

    FYI, I can provide my baan.s file and some test sources for you guys that are interested.

    Les.

    #5169
    deleyd
    Participant

    For prompting for the Work Order Number you could use a dialog box such as the code attached. Here routine getwon puts up a dialog box and asks for the work order number. It returns a string containing the work order number, or an empty string. I took this dialog box code from file MeUtil1.s macro RunMac.

    Dialog boxes are one of the under-documented features of Multi-Edit. Some attempts have been made to document the various things you can do, there are a couple tutorials, but they really don’t make it clear how
    you change the size of the box and fields and position of the buttons. I just do the old trick of finding something close to what I want and then modifying it until it does what I want. You can modify this as you like.

    (A nice feature is you get a drop down list history of work order numbers.)
    getwon.zip

    #5171
    Leslie Satenstein
    Participant

    Dave,
    Tried it and I like it. Only now would like to make the wondow less wide. I will explore.

    I see where I can easily integrate getWon into a template.

    Cheers

    BTW, the baan.s file has gradually grown in functionality. I would be happy to send you a copy.

    Regards

    Les

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.