Click to See Complete Forum and Search --> : Import ASCII file into a HTML form


Ron
02-07-2003, 07:31 AM
I've written a program to write a file containing the results of various calculations. I'd like to display the results in a HTML format.

I need to import a ASCII file , rows of data into specific field in the HTML file.

Can anyone lead me in the right direction?

:o

pyro
02-07-2003, 07:34 AM
What kind of ascii file? .txt? I think a server side language is what you need here, Perl or PHP. Does your server support PHP?

Charles
02-07-2003, 07:38 AM
Perl, being the Practical Extraction and Report Language, would do a very nice job in a minimum number of lines.

Ron
02-07-2003, 07:42 AM
I can name the file anything I want. I currently use .CAL (calc). Is there an advantage to use TXT?

pyro
02-07-2003, 07:45 AM
No, probably not, I was just wondering what kind of info you'd have in it. All you need to do is display the text file in you html file?

Ron
02-07-2003, 07:53 AM
Below is an example of a file I write.


5555599
1HS1
18
7.95
1264
1962
20
HS2-1,53,125.00,22.35,6.89, *
HS2-2,33,89.00,21.38,10.91,**
HS2-3,139,89.00,17.52,27.00,**
HS2-4,35,89.00,16.60,30.85,**
HS2-5,57,89.00,15.17,36.78,**
HS2-6,17,100.00,14.77,38.45,**
HS2-7,67,89.00,13.30,44.58,**
HS2-8,56,100.00,12.15,49.37,**

<eof>

I would like to read the file and place the data into specific fields in the form. In the ideal world, I'd like to save the data into a specific HTML file with the same name as the .CAL file.
But I might be asking for too much.

I need some way to send the data to the client in a easy readable format for them to review and approve.

pyro
02-07-2003, 07:56 AM
It should be quite easily done in PHP... Or, just to let you know that you can, you can load a .txt file into an iFrame, but that won't allow you to split into form fields, etc.

Ron
02-07-2003, 08:03 AM
Do you know where I can find an example of this? I know a little about HTML but have never written PHP before. Any resource ideas would be great.

Thanks for your time and input.

Charles
02-07-2003, 08:14 AM
This seems more and more like a job for Perl. And you can use the CGI.pm module to greatly simplify the HTML part of the problem. I'd toss something together for you but I don't know what those number represent or how you want the HTML file look.

But if you had written the calculator program in Perl from the start, then you'ld be one step closer. Perl was designed for this kind of thing and only later pressed into service for the web.

Ron
02-07-2003, 08:49 AM
I am performing the calculations within AutoCAD, using LISP. Then I write the results out to a file.

Below you will the description of the fields.


Project number: 5555599
Circuit: 1HS1
Wire guage: 18
Resistence: 7.95 per 1000 feet
Total conduit length: 1264,feet
Total mAmp in circuit: 1962,mAmp
Total number of devices: 20

Device ID Length mAmp Volts % Drop
HS2-1 53 125.00 22.35 6.89 *
HS2-2 33 89.00 21.38 10.91 **
HS2-3 139 89.00 17.52 27.00 **
HS2-4 35 89.00 16.60 30.85 **
HS2-5 57 89.00 15.17 36.78 **
HS2-6 17 100.00 14.77 38.45 **
HS2-7 67 89.00 13.30 44.58 **
HS2-8 56 100.00 12.15 49.37 **

* Greater than 5% voltage drop
** Greater than 10% voltage drop


If you can just get ME started, I would appreciate it.
(sorry for the typo)

Thanks for your help.

pyro
02-07-2003, 09:30 AM
If you're going to use Perl/CGI, you'll need to find help from someone besides me. It's not my strong suit. I always use PHP if it is an option. :D

Ron
02-07-2003, 09:45 AM
At this point I'll try PHP. If you have some input I'd like to hear/see it.

Thanks

Charles
02-07-2003, 10:25 AM
Something like this ought to do the trick.

use strict;
use CGI qw(:all acronym);

my $projectNumber = <>;
chomp $projectNumber;

my $circuit = <>;
chomp $circuit;

my $wireGauge = <>;
chomp $wireGauge;

my $resistance = <>;
chomp $resistance;

my $conduitLength = <>;
chomp $conduitLength;

my $mAmp = <>;
chomp $mAmp;

my $devices = <>;
chomp $devices;

my @data = <>;

my $acronym = acronym({-title=>'miliamp'}, 'mAmp');
my $project = Tr(th('Project Number'), td($projectNumber));
$project = $project.Tr(th('Circuit'), td($circuit));
$project = $project.Tr(th('Wire guage'), td($wireGauge));
$project = $project.Tr(th('Resistence per 1000 feet'), td($resistance));
$project = $project.Tr(th('Total conduit length'), td($conduitLength));
$project = $project.Tr(th("Total $acronym in circuit"), td($mAmp));
$project = $project.Tr(th('Total number of devices'), td($devices));
$project = table($project);

my $data = Tr(th(['Device ID', 'Length', 'mAmp', 'Volts', '% Drop', '&nbsp;']));
foreach (@data) {chomp; my @td = split /,/; $data = $data.Tr(td(\@td))};
$data = table($data);

my $title = "Data for $projectNumber";

print start_html($title), h1($title), $project, $data, end_html;

pyro
02-07-2003, 10:32 AM
Seeing how Charles is willing to help you with a Perl version, go ahead and use that...

Ron
02-07-2003, 11:50 AM
I think I see what's going on.

Thanks to both of you........

I really appreciate it.

Thanks