Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Convert.exe

0.00/5 (No votes)
2 Jan 2002 1  
A Utility to converter negative values displayed with trailing minus to a leading minus format

Introduction

This trivial program may be of use to some folks. My company, along with a few hundred others, use a POS program for running the retail business. By design, all reports from this program display negative values with a trailing minus sign. Oddly, most of these companies also use Excel, which refuses to recognize this format when importing a CSV text file from the POS program. This simple utility opens a text file, scans it line by line, and builds a new text file with all the trailing minus signs replaced by leading minus signs. The format is otherwise unchanged.

Usage is simple: 

Convert.exe srcfile destfile

Where the source and destination files are fully specified paths. If the destfile doesn't exist, it will be created; if it does, it will be overwritten. There is one known flaw - if a number is in the first position of any line, it will not be converted. Since this never occurs in any report from the POS software, I didn't bother to fix it, but it should be a simple matter if you need that capability.

Operation is simple. As each line is read, it is examined character by character. When a minus is found, a second loop starts backtracking within the line to the first non-numeric character before the minus sign. It then deletes the original minus and inserts one after the non-numeric character, then resumes the scan. When the scan is complete, the line is written to the destfile and another line is read. During the backtracking process, a decimal point is counted as a numeric, as most of the values encountered are currency values.

There are no code examples included here, as there is nothing particularly interesting in the program. It may, though, be just the thing for certain applications. A know several companies are now enjoying it...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here