473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB6 and ASCII text files

Using VB6, is there any special way of reading an ascii text file, that does not have any delimiters? The rows of data are seperated into seperate columns, but there is not "space" delimiter. Has me confused. I am trying to read in about 10 columns of data, with x number of rows. Any help or suggestions? Thanks
Attached Files
File Type: txt LITH.txt (491 Bytes, 500 views)
Jan 28 '10 #1
7 3369
vb5prgrmr
305 Expert 100+
Your fields are delimeted by a tab character (vbTab)... so you would split using vbTab...



Good Luck
Jan 28 '10 #2
I tried using vbTab and I am getting an error. Not sure what else to do.
Jan 28 '10 #3
This is the code I'm using to split the line:
Expand|Select|Wrap|Line Numbers
  1. strLine = TrimAll2(objstream.Readline)
  2. myarray = Split(strLine, vbTab) 'use tab to create space
  3. 'read into variables
  4. lithdepth = Format(Trim(myarray(0)), "0")
  5. shale = Trim(myarray(1))
  6. silt = Trim(myarray(2))
  7. sand = Trim(myarray(3))
  8. chalk = Trim(myarray(4))
  9. lime = Trim(myarray(5))
  10. dolo = Trim(myarray(6))
  11. anhy = Trim(myarray(7))
  12. coal = Trim(myarray(8))
  13. chert = Trim(myarray(9))
  14. nosamp = Trim(myarray(10))
  15.  
This is the function code that processes each line:
Expand|Select|Wrap|Line Numbers
  1. Function TrimAll2(Str)
  2.     '***remove all non ASCI chrs and reduce internal whitespace to single
  3.     Dim i, strTemp, strOut, strCh
  4.  
  5.     strTemp = Str
  6.     For i = 1 To Len(strTemp)
  7.         strCh = Mid(strTemp, i, 1) '***look at each character in turn
  8.         '***if the chr is a space and the previous added chr was a space ignore it
  9.         '***otherwise add it on
  10.         If Not (strCh = " " And Right(strOut, 1) = " ") And ((Asc(strCh) >= 64 And Asc(strCh) <= 122) _
  11.             Or (Asc(strCh) >= 48 And Asc(strCh) <= 57) Or Asc(strCh) = 32 Or strCh = ".") Then
  12.                 strOut = strOut & strCh
  13.         End If
  14.     Next
  15.     TrimAll2 = strOut
  16. End Function
  17.  
For some reason, vbTab is still giving me an error when reading the line into an assigned variable.
Jan 28 '10 #4
vb5prgrmr
305 Expert 100+
Because the tab character equates to the ascii value of 9, you are removing the tabs from the string and thus are unable to split on the tab character...



Good Luck
Jan 28 '10 #5
So, do I need to recode the function? Or can I add to it? Or what would you suggest? Thanks for the response.
Jan 28 '10 #6
vb5prgrmr
305 Expert 100+
From what I remember of your file, I would think that you could skip the removal function and go strait to spliting on vbtab but just to be sure check the results.



Good Luck
Jan 29 '10 #7
Thanks. I just skipped the function process and it is working.
Jan 29 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Bix | last post by:
As this is my very first post, I'd like to give thanks to all who support this with their help. Hopefully, this question hasn't been answered (too many times) before... If anyone could explain...
12
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
15
by: miki | last post by:
hello, I was asked this question during a job interview, and didn't know the answer. could someone please help me with that? the question was: "Which files are more suitable for working in C,...
16
by: chunhui_true | last post by:
I know in ASCII '\r' is 0x0d,'\n' is 0x0a. But some say ASCII characters in UTF8 is unchanged. Now I want to know in UTF8 '\r' and '\n' are already 0x0d and 0x0a?? Could anybody can tell me? Very...
4
by: George | last post by:
I am lost on how to do this. I have not worked with C much at all but can understand the basic properties of this language. Could someone please show me or explain to me how to write a function...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
13
by: greg | last post by:
Hello, I'm searching to know if a local file is ascii or binary. I couldn't find it in the manual, is there a way to know that ? thanks, -- greg
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
18
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.