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??
Printable View
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??
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
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.Quote:
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.
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.