1 (edited by jrga 2024-07-22 00:43:17)

Topic: CSV import doesn't work if first column is string

Hey guys! Here is a project I downloaded from the forum and I am adapting it to my needs. I have a tool called Visual Kit 5 v8, developed with Visual Foxpro which, although it is
old, has the advantage of building the entire application from just the "drawing" of the screens. The problem is that it uses MS's MSgraph.exe to generate graphs but, because it is old, this no longer works on Windows 11. Therefore, the objective is to use the attached project to generate graphs from data exported by Visual Kit to a CSV file. The MVD application (5.6) would load this data from the CSV file into a table and generate the graphs. The problem is that the import routine, which I also got here on the forum, works fine if the first column of the CSV is numeric. When the type is string, the process is interrupted by an error message.
I still plan to include printing and other customizations. In addition to using it with Visual KIt 5, I am thinking about the possibility of using it in applications whose development languages also depend on MSGraph.exe, to generate graphs. I appreciate any help that can be given.

CSV:

2007;15049861,72;0;0;6385;28,00
2008;2606270,58;0;0;2283;10,01
2009;3901885,82;0;0;3742;16,41
2010;3355533,20;0;0;3002;13,17
2011;6691013,64;0;0;4736;20,77
2012;517515,33;0;0;415;1,82
2013;2745497,70;0;0;2239;9,82
Post's attachments

Attachment icon Chart_import.rar 444.3 kb, 37 downloads since 2024-07-20 

Roberto Alencar

2 (edited by jrga 2024-07-22 00:22:45)

Re: CSV import doesn't work if first column is string

Problem solved! I replaced the line of code - CODE 1 with the line of code (CODE 2)


CODE 1:

                    SQLExecute('INSERT INTO '+TableName+' ('+Fields+') VALUES ('+sValues+')');

CODE 2;

                       instr_sql := '';
                       instr_sql := 'INSERT INTO ';
                       instr_sql := instr_sql + TableName;
                       instr_sql := instr_sql + ' ('+ Fields     + ') VALUES ';
                       instr_sql := instr_sql + ' (' + sValues + ')';
                       SQLExecute(instr_sql);
Roberto Alencar

Re: CSV import doesn't work if first column is string

Hi Roberto


We kindly ask that in order to understand your problem, please indicate in the future exactly what errors occur.
When testing your program on my computer, you may get errors:
"Could not convert variant of type (UnicodeString) ..."
"Is not valid integer value..."
"Error message: no such column"

4 (edited by jrga 2024-07-22 17:40:42)

Re: CSV import doesn't work if first column is string

sparrow wrote:

Hi Roberto


We kindly ask that in order to understand your problem, please indicate in the future exactly what errors occur.
When testing your program on my computer, you may get errors:
"Could not convert variant of type (UnicodeString) ..."
"Is not valid integer value..."
"Error message: no such column"

Hi Sparrow, you are right. Thanks for the guidance. When the project is complete, I will upload it again.

Roberto Alencar

Re: CSV import doesn't work if first column is string

Here is the project completed and working...still missing the printing

It imports delimited text (CSV) and generates charts from the imported data. I searched the internet via ChatGPT about the functions available to change the appearance of TeeChart charts (MVD 5.6) and included a button on each chart to do this customization.

Post's attachments

Attachment icon Chart_import.rar 335.15 kb, 43 downloads since 2024-07-31 

Roberto Alencar

6 (edited by jrga 2024-08-02 00:11:42)

Re: CSV import doesn't work if first column is string

The import procedure I used presented some errors. I replaced it with another one created by Dmitri himself, specifically for importing CSV files (link below). Below is the corrected project.

The CSV file must have delimiters and periods in values with decimals, without column titles, as per the following example:



"ANHEMBI",16054542.98,0,0,5943,27.55
"BARUERI",1113402.53,0,0,486,2.25
"CASA VERDE",3379641.23,0,0,2918,13.53
"IBITIRA",3482791.97,0,0,2931,13.59
"INTERLAGOS",3634897.27,0,0,2766,12.82
"MARAJUARA",6232411.02,0,0,4304,19.95
"PORTA A PORTA",660044.78,0,0,354,1.64
"SÃO MATEUS",2736725.14,0,0,1869,8.66



https://myvisualdatabase.com/forum/sear … =435433873

Post's attachments

Attachment icon Chart_import_fixed.rar 333.78 kb, 35 downloads since 2024-08-02 

Roberto Alencar

Re: CSV import doesn't work if first column is string

Hi Roberto

I can't say that previous versions contained errors. Initially, all your problems were the "Ã" character in the CSV file.
When using TStringList, processing this character caused a failure and incorrect further work with the database.
What you considered a solution was a temporary solution until this or another similar character appeared again.
In the latest version, you used a different import solution. One of several possible ones. Import solutions based
on working with EXCEL are also possible. Of course, if you use this program.
In any case, I congratulate you on finding a solution. The "higher mind" is no better than your head.

Re: CSV import doesn't work if first column is string

sparrow wrote:

Hi Roberto

I can't say that previous versions contained errors. Initially, all your problems were the "Ã" character in the CSV file.
When using TStringList, processing this character caused a failure and incorrect further work with the database.
What you considered a solution was a temporary solution until this or another similar character appeared again.
In the latest version, you used a different import solution. One of several possible ones. Import solutions based
on working with EXCEL are also possible. Of course, if you use this program.
In any case, I congratulate you on finding a solution. The "higher mind" is no better than your head.

thanks for the feedback

Roberto Alencar