Topic: Concatenate String and Variable (1 of 7), Read 37 times
Conf: Hints, tips, shortcuts
From: LeRoy Stevens
Date: Tuesday, November 25, 2008 02:12 PM

Sorry to put this up. New to VEdit.

The intent is to scan a file and append blocks to another file. I also wanted a report (in a separate file) of how many times I copied the blocks and the line numbers that are in the original file. While this works I know it is not the preferred method but I do not understand how to create the report file so I am redirecting a message string (If there is any way to concatenate these two strings into one line that would be great).
Any help would be appreciated.

The files involved:
CTXSample.txt - origianl file we are scanning to find blocks
CTXSampleOut.txt - blocks copied from original file
CTXLineCount.txt - report of blocks copied and line number

//////////////////////////////////////////////////////////
if (File_Exist("C:\Program Files\VEdit\Temp\CTXSampleOut.txt")) {
File_Delete("C:\Program Files\VEdit\Temp\CTXSampleOut.txt", OK)}

if (File_Exist("C:\Program Files\VEdit\Temp\CTXLineCount.txt")) {
File_Delete("C:\Program Files\VEdit\Temp\CTXLineCount.txt", OK)}

if (File_Exist("C:\Program Files\VEdit\Temp\CTXSample.txt")) {
File_Open("C:\Program Files\VEdit\Temp\CTXSample.txt", OK)

Out_File("C:\Program Files\VEdit\Temp\CTXLineCount.txt", NOMSG)

#12 = 1

Begin_Of_File()

while (! At_EOF) {
Search("|<5200PAYMAP, INC.|*CTX|*|N|<6|*0110001997|*|N|<7|*|N|<7|*|N|<7|*|N|<7|*|N|<7|*|N|<8|*|N",ERRBREAK)
Block_Begin(Cur_Pos)
Message("CTX record:")#12
Message("Line number:")Num_Type(Cur_Line)
Search("|<5200PAYMAP, INC.|*CTX|*|N|<6|*0110001997|*|N|<7|*|N|<7|*|N|<7|*|N|<7|*|N|<7|*|N|<8|*|N", ADVANCE)
Block_End(Cur_Pos)
Reg_Copy_Block(#10,Block_Begin,Block_End) Reg_Save(#10,"C:\Program Files\VEdit\Temp\CTXSampleOut.txt",APPEND)
Block_Begin(CLEAR) //Clear both the block-begin and block-end markers.
#12++
}
File_Close(OK+NOMSG) // Close the CTXSample.txt file

Xall()

 


Topic: Concatenate String and Variable (2 of 7), Read 45 times
Conf: Hints, tips, shortcuts
From: Christian Ziemski
Date: Tuesday, November 25, 2008 05:28 PM

On 11/25/2008 2:12:44 PM, LeRoy Stevens wrote:
>While this works I know it is not the preferred method
>but I do not understand how to create the
>report file so I am
>redirecting a message string (If there is any way to
>concatenate these two strings into one line that would be
>great).

I would recommend to open the report file in a second buffer and append the message string(s) there, step by step.

Perhaps like so:
(Just from memory. Not complete and untested!)

//...
#12 = 1
#13=Buf_Num // buffer# of the data file in the current buf

Buf_Switch(Buf_Free)
File_Save_As("report.txt")
#14=Buf_Num // buffer of the report file


Buf_Switch(#13) // switch to data file

Begin_Of_File()

while (! At_EOF) {
Search("|<5200PAYMAP, ......
Block_Begin(Cur_Pos)

#15=Cur_Line // remember the line#

Search("|<5200PAYMAP, .....
Block_End(Cur_Pos)

Reg_Copy_Block(#10,Block_Begin,Block_End)
Reg_Save(#10,"CTXSampleOut.txt",APPEND)

Block_Begin(CLEAR)

Buf_Switch(#14) // switch to report
Ins_Text("CTX record: ")
Num_Ins(#12)
Ins_Text(" Linenumber:")
Num_Ins(#15)
Ins_Newline(1)
Buf_Switch(#13) // switch to data again
#12++
}
File_Close(OK+NOMSG)

Buf_Switch(#14) // switch to report
File_Save()


Christian

 


Topic: Concatenate String and Variable (3 of 7), Read 47 times
Conf: Hints, tips, shortcuts
From: LeRoy Stevens
Date: Tuesday, November 25, 2008 08:04 PM

Thank you, it helps to see a solution to a specific problem you are working on.

When I changed the Xall() to FileSave(), I get a Flow Control Statement Still Open (and it leaves the report.txt file open).

Did you intend for me to replace the Xall() with the FileSave() (your last line) or was the FileSave() in addition and just prior to the Xall()?

Thank you again for your help.

 


Topic: Concatenate String and Variable (4 of 7), Read 45 times
Conf: Hints, tips, shortcuts
From: Christian Ziemski
Date: Wednesday, November 26, 2008 03:09 AM

On 11/25/2008 8:04:18 PM, LeRoy Stevens wrote:
>
>When I changed the Xall() to FileSave(), I get a Flow
>Control Statement Still Open

I think you already have the command Out_File() in your macro? That one isn't necessary any more here.

>(and it leaves the report.txt file open).
>Did you intend for me to replace the Xall() with the
>FileSave() (your last line) or was the FileSave() in
>addition and just prior to the Xall()?

I usually use explicit File_Save() to be sure.
But XAll() does it as well.


Two more suggestions:

1) You can remove the if(File_Exist(...)..) constructs at the beginning by using the NOERR option:
File_Delete("....txt", OK+NOERR)

2) The two commands
Reg_Copy_Block(#10,Block_Begin,Block_End)
Reg_Save(#10,".....txt",APPEND)

can be done by a single one:
Block_Save_As("...", Block_Begin, Block_End, APPEND)

So you don't need a text register.
And are not restricted to it's size limit.


Christian

 


Topic: Concatenate String and Variable (5 of 7), Read 46 times
Conf: Hints, tips, shortcuts
From: LeRoy Stevens
Date: Wednesday, November 26, 2008 12:55 PM

Christian, that worked perfectly and cleaned up the macro.
Hopefully the last question.

Another scenario, in this case I want to create separate files for each search block found. Trying to use buffer#12 and concatenate that variable to filename (I don't need extension but it would be helpful) with command:

Block_Save_As("C:\Temp\CTX|@(12)", Block_Begin, Block_End)

was attempting to create file "C:\Temp\CTX 6" or what ever number the register 12 is at.

If I could create "C:\Temp\CTX 6.txt" that would be great.

macro below
/////////////////////////////////////////////////////
File_Delete("C:\Temp\CTXSampleOut.txt", OK+NOERR)
File_Delete("C:\Temp\CTXLineCount.txt", OK+NOERR)

if (File_Exist("C:\Temp\CTXSample.txt")) {
File_Open("C:\Temp\CTXSample.txt", OK)
#12=1 //counter
#13=Buf_Num //buffer# of the data file in buffer
Buf_Switch(Buf_Free)
File_Open_Write("C:\Temp\CTXLineCount.txt",OVERWRITE)
#14=Buf_Num //buffer of the report file
Buf_Switch(#13) //switch to data file
Begin_Of_File()
while (! At_EOF) {
Search("|<5200PAYMAP, ....,ERRBREAK)
Block_Begin(Cur_Pos)
#15=Cur_Line //remember the line#
Search("|<5200PAYMAP,....., ADVANCE)
Block_End(Cur_Pos)
//Block_Save_As("C:\Temp\CTXSampleOut.txt", Block_Begin, Block_End, APPEND)
Block_Save_As("C:\Temp\CTX|@(12)", Block_Begin, Block_End)
Block_Begin(CLEAR) //clear both the block-begin and block-end markers.
Buf_Switch(#14) //switch to report
Ins_Text("CTX record: ")
Num_Ins(#12)
Ins_Text(" Line number:")
Num_Ins(#15)
Ins_Newline(1)
Buf_Switch(#13) //switch to data again
#12++
}
Buf_Close(OK+NOMSG) //close open buffer
Buf_Switch(#14) //switch to report
Buf_Close(OK+NOMSG) //close open buffer
}

 


Topic: Re: Concatenate String and Variable (6 of 7), Read 50 times
Conf: Hints, tips, shortcuts
From: Christian Ziemski
Date: Wednesday, November 26, 2008 02:33 PM

On 26.11.2008 19:20 in vtech-tips LeRoy Stevens wrote:
>
> Another scenario, in this case I want to create separate files for
> each search block found. Trying to use buffer#12 and concatenate
> that variable to filename (I don't need extension but it would be
> helpful) with command:
>
> Block_Save_As("C:\Temp\CTX|@(12)", Block_Begin, Block_End)
>
> was attempting to create file "C:\Temp\CTX 6" or what ever number
> the register 12 is at.
>
> If I could create "C:\Temp\CTX 6.txt" that would be great.
>
> [...] Block_Save_As("C:\Temp\CTX|@(12)", Block_Begin, Block_End)

// Create files with name like "C:\Temp\CTX00006.txt"
// (if #12 contains the value 6 in this example)
//
Reg_Set(103, "C:\Temp\CTX") // beginning of filename
Num_Str(#12, 103, FILL+NOCR+APPEND) // append 0-padded number
Reg_Set(103, ".txt", APPEND) // append extension
Block_Save_As("|@(103)", Block_Begin, Block_End) // use t-reg 103


Christian

 


Topic: Re: Concatenate String and Variable (7 of 7), Read 51 times
Conf: Hints, tips, shortcuts
From: LeRoy Stevens
Date: Wednesday, November 26, 2008 03:56 PM

Thank you, worked like a charm.