Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 24th, 2003, 03:04 PM
Z24_2000 Z24_2000 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 Z24_2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Delimited text to Access

Hi there,

I am currently working on enhancing a VB 6.0 application that used to get a fixed length text file and export that information to an Access table. However, the new file format is in a delimited text form. Now, I've never dealt with delimited text before in VB as I am a relatively new programmer. However, I have used ADO and Excel before, so I am familiar with ADO, I just don't know how to pick up delimited text fields, so any help would be muchly appreciated.

Thanks,
Andrew

P.S. Here is a sample record

"19710928"/"F"/"P7K 5Z2"

The first field being the DOB, the second being Gender and the third being postal code.

Thanks again

Reply With Quote
  #2  
Old February 24th, 2003, 03:16 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 8
Use Split() to turn your data into an array and iterate over the elements - performing any text to type conversions as necessary.

You should check if there are any / characters allowed in your data or else strip the quotes from the start and end and then split using "/" (ie 3 characters, double quote then forward slash then double quote) as the delimeter... etc.

Reply With Quote
  #3  
Old February 25th, 2003, 08:26 AM
Z24_2000 Z24_2000 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 Z24_2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Example?

Hi there epl,

Thanks for the reply, however, I'm still a little confused as how to use the Split() function, can you possibly give me an example using the data I supplied above?

Thanks again,
Andrew

P.S. Slashes are not allowed in the data.

Last edited by Z24_2000 : February 25th, 2003 at 08:33 AM.

Reply With Quote
  #4  
Old February 25th, 2003, 08:35 AM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 8
I'd do it like this because each data field is wrapped in quotes:
Code:
Dim dataStr as String, tokenStr as String, dataArray as Variant
  Let dataStr = "19710928""/""F""/""P7K 5Z2"
  Let tokenStr = "/"
  Let dataArray = Split(Mid$(dataStr, 2, Len(dataStr) - 2), """" & tokenStr & """", -1, vbBinaryCompare)

Without the quotes (ie just a / between items), or if I wanted to keep the quotes to remove later, I'd do this:
Code:
Dim dataStr as String, tokenStr as String, dataArray as Variant
  Let dataStr = "19710928""/""F""/""P7K 5Z2"
  Let tokenStr = "/"
  Let dataArray = Split(dataStr, tokenStr, -1, vbBinaryCompare)


You can then iterate over your results in dataArray and assign them given elements accordingly.

Hope that helps.

(the reapeated double quotes - ""/"" - each time above are the way vb requires you to write quotes within strings, by the way)

Last edited by epl : February 25th, 2003 at 11:48 AM.

Reply With Quote
  #5  
Old February 25th, 2003, 09:02 AM
Z24_2000 Z24_2000 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 3 Z24_2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Thank you :)

Thank you very much epl, I'll give it a try

Thanks,
Andrew

Reply With Quote
  #6  
Old February 27th, 2003, 02:27 PM
ngibsonau ngibsonau is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 138 ngibsonau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
You could try using the ADO text driver.
It works on "," seperated, tab seperated and user definable character seperated.

Code:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=\somepath\;" & _
"Extensions=asc,csv,tab,txt;" & _
"Persist Security Info=False"


only thing you have to be wary of is the MAXSCANROWS, how the driver determines the type of the columns. I had a person with their last name True in my data and it converted the column to boolean!
__________________
--

ngibsonau

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Delimited text to Access


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway