Importing Text, Excel style

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
mfstuart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 16
Joined: Sun Apr 09, 2006 9:49 pm
Location: Irvine, CA, USA

Importing Text, Excel style

Post by mfstuart » Mon May 15, 2006 3:52 pm

Hi all,

I have a columnar formatted text file that I'd like to "import" into a SQL
database, using RunRev on WinXP.

I'd like the RunRev program to have features similar to Excel's Text Import
Wizard:

- open file dialog
- raw display of first 100 or so lines of chosen text file
- allow user to define the column breaks
- based on users column breaks, read text file and put into a table
field for final approval to import into database
- read into SQL table


Again, features similar to Excel's Text Import Wizard.

Especially the part where the user defines the distinction of column
placements - Excel's "set field widths (column breaks)"

I've managed to develop the first two steps in the wizard, but I need help
with the third and fourth steps.

That is, how to handle the placement and movement of the vertical line for
column breaks.


TIA,
Mark

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5147
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon May 15, 2006 7:11 pm

Hi Mark,

One possibility would be to have buttons on top of your field, each with the same with as the colomns below them. Group the headers and in a mouseMove handler in that group, checkl the mouseLoc. If the mouseLoc is near the edger of a header button, check whether the mouse is down. If so, move the header buttons with the mouse and adjust the tabStops property accordingly.

Another possibility might be to have a similar mouseMove handler in the actualy table field. This is not always practical, but the user might expect to be able to drag the grid lines.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mfstuart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 16
Joined: Sun Apr 09, 2006 9:49 pm
Location: Irvine, CA, USA

Post by mfstuart » Mon May 15, 2006 9:09 pm

Hi Mark, thanx for your reply.

With that situation it would be alot simpler, but the issue here is, the program doesn't know the placement of the columns - check out Excel's Text Import Wizard if you have it. This is the situation the program would be in, after the user has selected a text file with the 'answer file' command.
Within the script I'd use the 'read file' to bring in the first 100 rows from the text file as a sample, display it in a field. When the user clicks on the Next button, take them to the next card that then allows them to (and this is the critical part) set the "column breaks" visually. That entails the user to click near the beginning/ending of each (unknown to the program) column. Once the user has mouseUp'd, the program then takes that mouseLoc position as the tabStop. At least this is how I perceive it, but I don't know how to script all this.

I hope that adds more light on the concept.

TIA,
Mark

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5147
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon May 15, 2006 10:03 pm

Hi Mark,

I understand I forgot a few details. You have to set the font of the field that contains the data to a monospaced font. Then take the longest line out of those first 100, if not all lines are equally long. In a repeat loop, check for each character in that line the fortmattedwidth of char 1 to that character of that particular line. Start with the last character, then count back to 1. Each time when the formattedWidth equals a tab stop (within a range of say 5 pixels), put a tab before or after that character. You will have to tweak a little, to make sure that you don't get two tabstops if the range is too large.

Good luck.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Databases”