Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here's the code:
'-------------------------------------------------- Function ReadTextFile$(Filename$) ' Reads large amounts of data from a text file in one shot. Dim iNum% On Error GoTo ErrHandler iNum = FreeFile(): Open Filename For Input As #iNum ReadTextFile = Space$(LOF(iNum)) ReadTextFile = Input(LOF(iNum), iNum) ErrHandler: Close #iNum: If Err Then Err.Raise Err.Number, , Err.Description End Function 'ReadTextFile() '-------------------------------------------------- Sub FlawedSub() Dim vTmp, sLine$ Const sFile$ = "C:\data.txt" sLine = ReadTextFile(sFile) sLine = Trim(sLine) vTmp = Split(Application.Substitute(sLine, " ", "*", 1), "*") MsgBox Trim(vTmp(0)) End Sub '-------------------------------------------------- The file data.txt contains the following string: (There's a tab char just after the a123) a123 A. BC #123 The output is supposed to be "a123". Instead, I'm getting "a123 A." Ugh, why doesn't this work? BTW, I'm using Excel 2010, so I don't know if that's the problem. Is there another way to extract the first substring on the nth line in a file? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How the heck? | Excel Worksheet Functions | |||
trace dependent tool doesn't work but trace precendent doesn't | Excel Discussion (Misc queries) | |||
What the heck is wrong here? | Excel Programming | |||
macro doesn't properly record AutoSum (and SendKeys doesn't work) | Excel Programming | |||
Shell Doesn't Work With UNC - Can't Get ShellExecute to Work Either | Excel Programming |