|
-
Jan 20th, 2004, 03:59 PM
#1
Thread Starter
Addicted Member
String Extraction *RESOLVED*
Probably an easy question. Is there a way to store the first 8 characters of a text file into the first item in an array, the next 10 in the next item, the next 12 in the next item, 10 in the next, etc??
Last edited by run_GMoney; Jan 22nd, 2004 at 10:06 AM.
Place Your VBForums Ad Here
-
Jan 20th, 2004, 04:43 PM
#2
Try this .........
Make sure you place the data.txt in "C:\" drive
VB Code:
Option Explicit
Private Sub Form_Load()
Dim FilePath As String
Dim strData As String
Dim tmp As String
FilePath = "C:\data.txt"
If Dir(FilePath) <> "" Then
Open FilePath For Input As #1
Do While Not EOF(1)
Input #1, tmp
strData = strData & tmp
Loop
Close #1
Dim arrData(2) As String
'copy the first 8 char
arrData(0) = Mid(strData, 1, 8)
'copy the next 10 char
arrData(1) = Mid(strData, 9, 12)
'copy the next 12 char
arrData(2) = Mid(strData, 21, 10)
MsgBox "First 8 char :" & arrData(0) & vbCrLf & "Next 12 char:" & arrData(1) & vbCrLf & "Next 10 char:" & arrData(2)
Else
MsgBox "File/Path not found"
End If
End Sub
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jan 20th, 2004, 08:29 PM
#3
About the Dir function, it'll return a path (passing your test) if the path given it is a folder. You need to use the GetAttr function to get around this, though that will only matter very rarely. Just being thorough.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Jan 21st, 2004, 06:36 AM
#4
Originally posted by jemidiah
About the Dir function, it'll return a path (passing your test) if the path given it is a folder. You need to use the GetAttr function to get around this, though that will only matter very rarely. Just being thorough.
Yep thanks, I am aware of that, i try not using Dir function. If i already have a reference to the Scripting runtime i tend to use FSO's FileExist method. The question was about string extraction so didnt wanna spend time doing validaion, i guess run_GMoney has already got it covered.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jan 22nd, 2004, 10:05 AM
#5
Thread Starter
Addicted Member
Danial - Thanks for the Mid solution. I've put it to good use.
jemidiah - I'll be sure to address the Dir issue when I get to it. For now I'm just wrangling with the concepts of how this data is output from the original program so I can figure out how I want to input it into mine.
Place Your VBForums Ad Here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|