Topic: Working With Dates (1 of 6), Read 18 times
Conf: Other, General, etc.
From: Dale Cook
Date: Wednesday, January 30, 2008 03:35 PM

I've embarked upon a new project, and for the first time I am trying to manipulate dates in Vedit. I'm working with the output of a program that, each day, creates a text file for the following day. Today is 30-Jan-2008, and the output file created today will be named "mmddyy.evr" where "mmddyy" is tomorrow's date.

What I am working on is a macro that will do several things:

1) Get today's date from the system, increment it by one day to get tomorrow's date, convert the result to the string "mmddyy" and open the file "mmddyy.evr".

2) Manipulate the contents of the file in several ways (all of which I have working correctly), then increment tomorrow's date by one day, convert the result to the string "mmddyy" and insert the string "mmddyy.evr" at the edit point.

3) Save and close the file.

I can get today's date from the system with the Date(NOMSG|NOCR) function, but where I'm having trouble is in figuring out how to increment that date, and turn the result into the string "mmddyy". Does anyone have any suggestions?

Dale H. Cook, Chief Engineer, Centennial Broadcasting, Roanoke/Lynchburg, VA - WZZI / WZZU / WLNI / WLEQ
http://members.cox.net/dalehcook/starcity.shtml

 


Topic: Working With Dates (2 of 6), Read 18 times, 1 File Attachment
Conf: Other, General, etc.
From: Ian Binnie
Date: Wednesday, January 30, 2008 05:43 PM

On 1/30/2008 3:35:15 PM, Dale Cook wrote:
>I've embarked upon a new
>project, and for the first
>time I am trying to manipulate
>dates in Vedit. I'm working
>with the output of a program
>that, each day, creates a text
>file for the following day.
>Today is 30-Jan-2008, and the
>output file created today will
>be named "mmddyy.evr" where
>"mmddyy" is tomorrow's date.

I would strongly advise you to use a better date format (i.e. one which is unambiguous, and sortable), but it can be done with any format.

>I can get today's date from
>the system with the
>Date(NOMSG|NOCR) function, but
>where I'm having trouble is in
>figuring out how to increment
>that date, and turn the result
>into the string "mmddyy". Does
>anyone have any suggestions?

It can be done with something like:-
#31=Num_Eval_Date(BEGIN) // Evaluate a date dd/mm/yyyy or dd-mm-yyyy

It does involve a bit of manipulation.

I have attached one of my date manipulating macros, which may make this clearer.

 
DATE2ISO.VDM (2KB)

 


Topic: Working With Dates (3 of 6), Read 22 times
Conf: Other, General, etc.
From: Dale Cook
Date: Wednesday, January 30, 2008 06:48 PM

> I would strongly advise you to use a better date format
> (i.e. one which is unambiguous, and sortable)

Ian -

I have no choice about the mmddyy format - I am working with files created by an application, and it names the files it creates using the mmddyy format.

> I have attached one of my date manipulating macros,
> which may make this clearer.

Thanks - a working example is what I need to see how this sort of thing works.

Dale H. Cook, Chief Engineer, Centennial Broadcasting, Roanoke/Lynchburg, VA - WZZI / WZZU / WLNI / WLEQ
http://members.cox.net/dalehcook/starcity.shtml

 


Topic: Working With Dates (4 of 6), Read 20 times
Conf: Other, General, etc.
From: Dale Cook
Date: Wednesday, January 30, 2008 08:23 PM

Ian's macro answered some questions, but I still have one central problem to solve. How can I save the output of Date(NOMSG+NOCR) as a string that I can then manipulate into a filename? I've tried saving it to a text file with:

Reg_Set(10, Date(NOMSG+NOCR))
Reg_Save(10,"temp.txt",OK)

but that doesn't work - temp.txt ends up as a zero-length file.

Dale H. Cook, Chief Engineer, Centennial Broadcasting, Roanoke/Lynchburg, VA - WZZI / WZZU / WLNI / WLEQ
http://members.cox.net/dalehcook/starcity.shtml

 


Topic: Working With Dates (5 of 6), Read 19 times
Conf: Other, General, etc.
From: Ian Binnie
Date: Wednesday, January 30, 2008 09:10 PM

On 1/30/2008 8:23:46 PM, Dale Cook wrote:
>Ian's macro answered some
>questions, but I still have
>one central problem to solve.
>How can I save the output of
>Date(NOMSG+NOCR) as a string
>that I can then manipulate
>into a filename? I've tried
>saving it to a text file
>with:

Reg_Set(10,
>Date(NOMSG+NOCR))
Reg_Save(10,
>"temp.txt",OK)

but that
>doesn't work - temp.txt ends
>up as a zero-length
>file.

The following (my adaption of the User Menu item) Insert date and time into the current file.

Out_Ins() Date(NOMSG|REVERSE|NOCR) Type_Space(1) Time(NOMSG|NOCR) Type_Space(1) Out_Ins(CLEAR)

The following will insert date into a register.

#28=Buf_Switch(Buf_Free) // working buffer
Out_Ins() Date(NOMSG|REVERSE|NOCR) Out_Ins(CLEAR)
BOF
Reg_Copy(10,1)

 


Topic: Working With Dates (6 of 6), Read 18 times
Conf: Other, General, etc.
From: Pauli Lindgren
Date: Thursday, January 31, 2008 10:19 AM

On 1/30/2008 9:10:42 PM, Ian Binnie wrote:
> On 1/30/2008 8:23:46 PM, Dale Cook wrote:

>> Reg_Set(10,Date(NOMSG+NOCR))
>> Reg_Save(10,"temp.txt",OK)
>>
>> but that doesn't work - temp.txt ends
>> up as a zero-length file.

Date()does not return a string value.
To put date into register 10, use the following:

Out_Reg(10)
Date(NOMSG+NOCR)
Out_Reg(CLEAR)

However, you do not need to write date in a register to get it in file. Just switch to the file (or tmp buffer) and use Out_Ins instead of Out_Reg.

>
> The following will insert date into a register.
>
> #28=Buf_Switch(Buf_Free) // working buffer
> Out_Ins() Date(NOMSG|REVERSE|NOCR)
> Out_Ins(CLEAR)
> BOF
> Reg_Copy(10,1)

You can insert date directly to register using Out_Reg, see above.
However, since manipulation is needed (increment date, add the filename extension), you need to insert it in a buffer.
Here is a test macro I made:

Buf_Switch(Buf_Free)
Out_Ins()
Date(NOMSG+NORMAL)
Out_Ins(CLEAR)
BOF
#10 = Num_Eval_Date() // #10 = Today's date as Julian number
Del_Char(ALL)
Num_Ins_Date(#10+1,NORMAL+NOCR+VALUE,0) // write tomorows date
Char(-4)
Del_Char(2) // remove first 2 digits of year
EOL
Ins_Text(".evr")
Reg_Copy_Block(10,BOL_pos,CP)
Buf_Quit(OK)
File_Open(@10)

--
Pauli