Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2001, 04:43 PM
jcjlkj jcjlkj is offline
Member
 
Join Date: Nov 2000
Posts: 30
Default How can you fill a data base ASCII Text data?

I am downloading data files off of an old mainframe as a text file that would resemble the following format:

New record Identifier
Record Key/ID
field 1
field 2
.
.
.
field N
New record Identifier

The fields from 1 to N basically match the field order in my Paradox Table. However I was wondering, would it be easier to extract if it were in an XML format? If so How would you do that also?
Reply With Quote
  #2  
Old 02-23-2001, 12:49 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: How can you fill a data base ASCII Text data?

Can you post a short example of your file and the schema of
your Paradox table?
Reply With Quote
  #3  
Old 02-23-2001, 04:48 PM
jcjlkj jcjlkj is offline
Member
 
Join Date: Nov 2000
Posts: 30
Default RE: RE: How can you fill a data base ASCII Text data?

File to be retrieved comments in {}

12345 {Key/ID}
John Doe {name}
123 help me Dr. {address}
Sandtrap City {City}
FL {State}
01234#### {Zip may or may not have last 4 digits}
3053321234 {Home Phone if avail if not left blank}
3053321235 {Work Phone blank if not avail}
{Fax Phone - for example this is not avail}
someone@something.com {Email addr and last item of record}
12346 {next record id/key thus repeating the series until eof}

Paradox7 customer table is very straight forward
0 - Key id Cust-no
1 - String field Name
2 - String field Address
3 - String Field City
4 - String Field State
5 - Numeric field with Mask 5#/5#-4# Zip
6 - Numeric field with Mask 7#/10# Hphone
7 - Numeric field with Mask 7#/10# Wphone
8 - Numeric field with Mask 7#/10# Fphone
9 - String field for email

That is basically my Paradox table with the last word being my Identifyier. I understand that when receiving an XML format the data is between the Tags, I just don't know how to parse it out and get the data into my file structure.

Thanks in advance for your help.
Reply With Quote
  #4  
Old 02-26-2001, 05:41 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: RE: How can you fill a data base ASCII Text data?

Now, do you want this stored in a Paradox table or an XML
file?

I can do it in both...

Or are you saying you can get the results in XML and need
to parse the XML to the Paradox table?

I can do that one too...
Reply With Quote
  #5  
Old 02-26-2001, 08:40 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: RE: How can you fill a data base ASCII Text data?

OK, here's how to import straight into a Paradox table with
the structure you provided:

procedure TForm1.Button1Click(Sender: TObject);
function FormatPhone(Value: String): String;
var
ac, pref, num: String;
begin
ac := Copy(Value,1,3);
pref := Copy(Value,4,3);
num := Copy(Value,7,4);
Result := Format('(%3s)%3s-%4s', [ac, pref, num]);
end;

function FormatZip(Value: String): String;
var
Zip, Plus4: String;
begin
Zip := Copy(Value, 1, 5);
Plus4 := Copy(Value, 6, 4);
if Length(trim(Plus4)) > 0 then
Result := Format('%5s-%4s', [Zip, Plus4])
else
Result := Zip;
end;

var
slImport: TStringList;
i, x: Integer;
begin
LockWindowUpdate(DBGrid1.Handle);
slImport := TStringList.Create;
slImport.LoadFromFile('c:\ascii.txt');
Table1.Active := True;
for i := 0 to Pred(slImport.Count div 10) do
begin
x := i * 10;
Table1.Append;
Table1.FieldByName('KeyID').AsInteger := StrToInt(slImport.Strings[x]);
Table1.FieldByName('Name').AsString := slImport.Strings[x+1];
Table1.FieldByName('Address').AsString := slImport.Strings[x+2];
Table1.FieldByName('City').AsString := slImport.Strings[x+3];
Table1.FieldByName('State').AsString := slImport.Strings[x+4];
Table1.FieldByName('Zip').AsString := FormatZip(slImport.Strings[x+5]);
Table1.FieldByName('Home_Phone').AsString := FormatPhone(slImport.Strings[x+6]);
Table1.FieldByName('Work_Phone').AsString := FormatPhone(slImport.Strings[x+7]);
Table1.FieldByName('Fax_Phone').AsString := FormatPhone(slImport.Strings[x+8]);
Table1.FieldByName('EMail').AsString := slImport.Strings[x+9];
Table1.Post;
end;
slImport.Free;
LockWindowUpdate(0);
end;

If you need to or from XML, that will take a little more
time. If so, do you want to use the MS parser or XDOM,
native Delphi parser?
Reply With Quote
  #6  
Old 02-27-2001, 04:36 AM
jcjlkj jcjlkj is offline
Member
 
Join Date: Nov 2000
Posts: 30
Default RE: RE: RE: RE: How can you fill a data base ASCII Text data?

I would be very interested in the XML In/Out you mentioned. Yes I would be interested in MS Parser and XDOM. Thank you.
Reply With Quote
  #7  
Old 02-27-2001, 07:45 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: RE: RE: RE: How can you fill a data base ASCII Text data?

This uses the MS parser. Import the TypeLibrary from the
Project..Import Type Library menu. This will save the file
to a valid XML file with no DTD. This one uses Elements for
each field. If you want attributes for each field, some
mods will have to be made...let me know.

I need more time to build this using XDOM.



procedure TForm1.Button1Click(Sender: TObject);

function FormatPhone(Value: String): String;
var
ac, pref, num: String;
begin
ac := Copy(Value,1,3);
pref := Copy(Value,4,3);
num := Copy(Value,7,4);
if (Length(trim(ac)) > 0 ) and
(Length(Trim(pref)) > 0) and
(Length(Trim(num)) > 0) then
Result := Format('(%3s)%3s-%4s', [ac, pref, num])
else
Result := '';
end;

function FormatZip(Value: String): String;
var
Zip, Plus4: String;
begin
Zip := Copy(Value, 1, 5);
Plus4 := Copy(Value, 6, 4);
if Length(trim(Plus4)) > 0 then
Result := Format('%5s-%4s', [Zip, Plus4])
else
Result := Zip;
end;
var
oXMLDoc: OleVariant;
oRoot, oNode, oAttr, oChild, oPI, oXMLCDATASection: OleVariant;
slImport: TStringList;
i, x: Integer;
DataOut: TMemoryStream;
s: String;
begin
try
DataOut := TMemoryStream.Create;
// Build the XML document
oXMLDoc := VarNull;
oXMLDoc := CreateOleObject('Microsoft.XMLDOM');
oRoot := oXMLDoc.CreateElement('ROWSET');
oXMLDoc.AppendChild(oRoot);
// Open the File and import into StringList...
slImport := TStringList.Create;
slImport.LoadFromFile('c:\ascii.txt');
for i := 0 to Pred(slImport.Count div 10) do
begin
x := i * 10;

// Build The Node
oNode := oXMLDoc.CreateElement('ROW');
oXMLDoc.DocumentElement.AppendChild(oNode);

// Insert CHild Elements
// KeyId
oChild := oXMLDoc.CreateNode('element', 'KeyId', '');
oChild.Text := slImport.Strings[x];
oNode.AppendChild(oChild);

// Name
oChild := oXMLDoc.CreateNode('element', 'Name', '');
oChild.Text := slImport.Strings[x+1];
oNode.AppendChild(oChild);

// Address
oChild := oXMLDoc.CreateNode('element', 'Address', '');
oChild.Text := slImport.Strings[x+2];
oNode.AppendChild(oChild);

// City
oChild := oXMLDoc.CreateNode('element', 'City', '');
oChild.Text := slImport.Strings[x+3];
oNode.AppendChild(oChild);

// State
oChild := oXMLDoc.CreateNode('element', 'State', '');
oChild.Text := slImport.Strings[x+4];
oNode.AppendChild(oChild);

// Zip
oChild := oXMLDoc.CreateNode('element', 'Zip', '');
oChild.Text := FormatZip(slImport.Strings[x+5]);
oNode.AppendChild(oChild);

// Home_Phone
oChild := oXMLDoc.CreateNode('element', 'Home_Phone', '');
oChild.Text := FormatPhone(slImport.Strings[x+6]);
oNode.AppendChild(oChild);

// Work_Phone
oChild := oXMLDoc.CreateNode('element', 'Work_Phone', '');
oChild.Text := FormatPhone(slImport.Strings[x+7]);
oNode.AppendChild(oChild);

// Fax_Phone
oChild := oXMLDoc.CreateNode('element', 'Fax_Phone', '');
oChild.Text := FormatPhone(slImport.Strings[x+8]);
oNode.AppendChild(oChild);

// EMail
oChild := oXMLDoc.CreateNode('element', 'EMail', '');
oChild.Text := slImport.Strings[x+9];
oNode.AppendChild(oChild);

end;
slImport.Free;
//
oPI := oXMLDoc.CreateProcessingInstruction('xml', 'version="1.0"');
oXMLDoc.InsertBefore(oPI, oXMLDoc.ChildNodes.Item[0]);
// Build String from oXMLDoc.XML
s := oXMLDoc.XML;
DataOut.Clear;
DataOut.Write(s[1], Length(s));
DataOut.Seek(0, soFromBeginning);
DataOut.SaveToFile('test.xml');
finally
DataOut.Free;
oXMLDoc := VarNull;
oRoot := VarNull;
oNode := VarNull;
oChild := VarNull;
oPI := VarNull;
oAttr := VarNull;
end; // Try
end;
Reply With Quote
  #8  
Old 02-27-2001, 08:00 AM
jcjlkj jcjlkj is offline
Member
 
Join Date: Nov 2000
Posts: 30
Default RE: RE: RE: RE: RE: RE: How can you fill a data base ASCII Text data?

You are Awesome!!! Do you hire your skills under contract basis? If so How much do you charge per hour or do you bill per project? Can I contact you directly? You can feel free to contact me
jason@dealerprogramming.com

Also, how well do you understand VCL components such as Async Professional 3? Have you or do you use it? I am having much difficulty with Kermit FTP. Do you understand Kermit FTP and TCP/IP or Winsock or TAPI?

I don't suppose that Columbus, OH is a local call for you? If not I would be more than willing to "foot" any phone bills if you would be willing to do some somewhat temporary work for my company. Please let me know!

Sincerely,

Jason Jelks, President/Owner
Custom Dealer Solutions, Inc.
Reply With Quote
  #9  
Old 02-27-2001, 08:09 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: RE: RE: RE: RE: RE: RE: How can you fill a data base ASCII Text data?

Actually, I do this for the grins. I wanted to see how fast
I could reach 100 accepted answers. No, seriously, I am
currently fully employed and not looking. I live in Central Texas so Columbus, OH is quite a ways for me.

What kind of questions do you have about Async Pro? Did you
know that they have a very active support newsgroup. The
fellows there are very helpful and quick to answer. Also,
one of their employees, Stephen Posey, is a very active
member of the Delphi mailing lists hosted by Ken Kyler. I
have been a member of those lists since 1995. You can sign
up here:
http://www.elists.org
Reply With Quote
  #10  
Old 02-27-2001, 08:19 AM
jcjlkj jcjlkj is offline
Member
 
Join Date: Nov 2000
Posts: 30
Default RE: RE: RE: RE: RE: RE: RE: RE: How can you fill a data base ASCII Text data?

Based on the Answers you put out I don't doubt that you are fully employed. What I am offering is a way for you to gain extra income on your "off" time, at your discression. No time limit constraints as you obviously know your stuff. Depending on what you currently make I can help you subsidize your income if you would like. I am not asking for you to even think of terminating your position, but rather offering almost the same type of help you give here but produce code in an executable form and get a little "Spiff" for it. It is obviously up to you. If you are interested in doing work at your discression on your time where it hurts no one then let me know. Either way I do appretiate your help.


Jason
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:17 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.