Topic: Delimiter Count Macro? (1 of 12), Read 35 times
Conf: VEDIT Macro Library
From: Shane Presley
Date: Thursday, July 01, 2004 02:53 PM

I am new to VEdit and am currently using a trial version. Does anyone know of a macro to verify the number of delimiters per line in a file? I have searched the board and a few user sites but no luck.

This is currently a challenge for us and it would help in justifying the purchase of VEdit. I am looking at writing the macro myself but no sense in reinventing the wheel if someone has done it.

Thanks,
Shane

 


Topic: Re: Delimiter Count Macro? (2 of 12), Read 35 times
Conf: VEDIT Macro Library
From: Fritz Heberlein
Date: Thursday, July 01, 2004 03:20 PM

> Does anyone
> know of a macro to verify the number of delimiters per line in a file?

What's your definition of "delimiter"? in which way differs it from
Vedit's concept of "separators" ("... separator - a character which
is not a letter, a digit or underscore "_". Space, Tab and all
control characters are separators. Graphics characters (value 128-
255) are not separators)?


Fritz

 


Topic: Re: Delimiter Count Macro? (3 of 12), Read 40 times
Conf: VEDIT Macro Library
From: Shane Presley
Date: Thursday, July 01, 2004 03:28 PM

For my purposes a delimiter is a character (printable or non-printable) that is used to designate one column from another within a data file. For example a csv file (comma-separated value) is an example of a delimited file. Other common delimiters are |, \tab and Ç.

What I would need the macro to do is verify that each record has the same number of delimiters. If a record has more or less delimiters than the expected (user-defined) then it causes data processing errors.

Does that answer your question?

Thanks,
Shane

 


Topic: Re: Delimiter Count Macro? (4 of 12), Read 48 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Thursday, July 01, 2004 05:09 PM

On Thu, 01 Jul 2004 15:28:00 -0400, Shane Presley wrote:

>What I would need the macro to do is verify that each record has
>the same number of delimiters.

Shane:

here a quick-shot macro to do what you described.
It needs some more comfort for the input of course but should show one
possible way.



Reg_Set(103, ",") // set delimiter character
#103=5 // number of delimiters per line

#104=0 // error flag
Begin_Of_File

while (! At_EoF) {
// check for at least #103 occurrences
Search_Block("|@(103)", BoL_Pos, EoL_Pos, NOERR+ADVANCE+COUNT, #103)
if (Error_Match) { // if too few delimiters
#104=1
break
}
// check for additional occurrence
Search_Block("|@(103)", Cur_Pos, EoL_Pos, NOERR)
if (! Error_Match) { // if too many delimiters
#104=1
break
}
Line(1, NOERR+ERRBREAK)
}

if (#104) {
Dialog_Input_1(105,"`Error!`,
`There is at least one line with wrong number of delimiters!`",
WORKAREA+CENTER,0,0)
} else {
Dialog_Input_1(105,"`Success`,
`All lines are having the same number of delimiters!`",
WORKAREA+CENTER,0,0)
}




Christian

 


Topic: Re: Delimiter Count Macro? (5 of 12), Read 42 times
Conf: VEDIT Macro Library
From: Shane Presley
Date: Thursday, July 01, 2004 07:19 PM

Christian,
Wow, that was quick and it worked like a charm!! I put in the purchase request today for VEdit!

Thanks a lot,
Shane

 


Topic: Re: Delimiter Count Macro? (6 of 12), Read 38 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, July 02, 2004 10:25 AM

On Thu, 01 Jul 2004 19:19:00 -0400, Shane Presley wrote:

>Wow, that was quick and it worked like a charm!!

Fine!

>I put in the purchase request today for VEdit!

Ditto!


And I couldn't resist again and enhanced the macro with some dialogs.

It now asks for the delimiter character and optionally the number of
them. If no number is given it tries to determine it and then presents
a confiramtion dialog before starting.

http://ziemski.privat.t-online.de/vedit/macros/check-dpl.vdm

Christian

 


Topic: Re: Delimiter Count Macro? (7 of 12), Read 39 times
Conf: VEDIT Macro Library
From: Ted Green
Date: Friday, July 02, 2004 11:27 AM

At 10:26 AM 7/2/2004, you wrote:
>It now asks for the delimiter character and optionally the number of
>them. If no number is given it tries to determine it and then presents
>a confiramtion dialog before starting.

Thank you for the macro Christian; and the great support you give. :-))

It doesn't seem necessary to prompt for the number of delimiters - this can be determined from the first line/record. If the first line is wrong, then the macro will stop on the 2nd line; in any case it will report a problem.

Ted.

 


Topic: Re: Delimiter Count Macro? (8 of 12), Read 39 times
Conf: VEDIT Macro Library
From: Shane Presley
Date: Friday, July 02, 2004 11:36 AM

>Thank you for the macro Christian; and the great support you give. :-))

Yes Christian, thank you! The macro does exactly what I need! I've already used it on several files.

It would have taken me a little while to learn the language and do what you did. It serves as a great learning tool as well.

I hope to expand the macro to move exceptions to a reject file, and produce a detailed execution report (file name, delimiter, del. count, # of lines matching, # of lines not matching, avg row length, execution time, etc.) of course I will post all mods for the group.

Thanks again!
Shane

 


Topic: Re: Delimiter Count Macro? (9 of 12), Read 41 times
Conf: VEDIT Macro Library
From: Ted Green
Date: Friday, July 02, 2004 11:45 AM

At 11:36 AM 7/2/2004, you wrote:
>I hope to expand the macro to move exceptions to a reject file, and produce a detailed execution report (file name, delimiter, del. count, # of lines matching, # of lines not matching, avg row length, execution time, etc.) of course I will post all mods for the group.

Shane:

In that case you should check out the supplied extract.vdm macro. It is a relatively simple macro which can extract selected line and move them to another file.

Ted.

 


Topic: Re: Delimiter Count Macro? (10 of 12), Read 42 times
Conf: VEDIT Macro Library
From: Shane Presley
Date: Friday, July 02, 2004 11:46 AM

I'll be sure to do that Ted, thanks for the tip.

 


Topic: Re: Delimiter Count Macro? (12 of 12), Read 33 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, July 02, 2004 01:19 PM

On Fri, 02 Jul 2004 11:36:00 -0400, Shane Presley wrote:

>It serves as a great learning tool as well.

That was the second reason for me to write it!

>I hope to expand the macro to move exceptions to a reject file,
>and produce a detailed execution report (file name, [...])
>of course I will post all mods for the group.

Hey, that seems to become a really useful macro!


And this time I'll try hard to hold back myself to avoid too much
forestalling. (You know, Fritz?) ;-)))

Christian

 


Topic: Re: Delimiter Count Macro? (11 of 12), Read 36 times
Conf: VEDIT Macro Library
From: Christian Ziemski
Date: Friday, July 02, 2004 12:55 PM

On Fri, 02 Jul 2004 11:27:00 -0400, Ted Green wrote:

>It doesn't seem necessary to prompt for the number of delimiters -
>this can be determined from the first line/record.

Yes, that was how I did it first.

But I wanted to have the possibilty to let it check against a *given*
number too.

BTW: One problem remains: The macro in it's current version can't be
used with the delimiter "TAB" (0x09).
Even if the dialog would allow to do an input like "|H09" that
wouldn't work since the Search() would interpret that as text and not
as pattern matching code.

There is a solution for that problem (e.g. used in LINEFILT.VDM), but
it wouldn't be really easy to understand - for a simple macro.

So there is some potential for enhancements... ;-)


Christian