LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Why the heck doesn't this work?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How the heck? Dave Excel Worksheet Functions 6 April 8th 08 03:34 AM
trace dependent tool doesn't work but trace precendent doesn't marnie Excel Discussion (Misc queries) 2 May 24th 07 12:26 PM
What the heck is wrong here? [email protected] Excel Programming 1 January 5th 07 06:20 PM
macro doesn't properly record AutoSum (and SendKeys doesn't work) crimsonkng Excel Programming 2 November 21st 06 02:11 PM
Shell Doesn't Work With UNC - Can't Get ShellExecute to Work Either [email protected] Excel Programming 1 September 1st 06 05:35 AM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"