?
Solved

Treat Consecutive Delimiters as One

Posted on 2002-03-05
3
Medium Priority
?
669 Views
Last Modified: 2012-05-04
I'm using the following code to import a space
delimited file. Works fine if there is only
one space. How can I import files with a varied
number of spaces?
Line Input #s1, strField
   ary1 = Split(strField, " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)
0
Comment
Question by:nschulz777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
crazyman earned 200 total points
ID: 6841803
Option Explicit
Function CompactSpaces(strText As String) As String
    Dim strTemp As String
    strTemp = strText
    While InStr(strTemp, "  ") > 0
        strTemp = Replace(strTemp, "  ", " ")
    Wend
    CompactSpaces = strTemp
End Function


Line Input #s1, strField
  ary1 = Split(CompactSpaces(strField), " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)



0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6842135
Add a reference to Microsoft VBScript Regular Expressions

Line Input #s1, strField

Set m_RegExp = New VBScript_RegExp_55.RegExp
With m_RegExp
    .Pattern = " +"    'Look for more than one blank
    .Global = True
    strField = .Replace(strField, " ")
End With
Set m_RegExp = Nothing

ary1 = Split(strField, " ")
outFields = UBound(ary1)
str1 = ary1(0)
str2 = ary1(1)
str3 = ary1(2)

Anthony
0
 
LVL 2

Author Comment

by:nschulz777
ID: 6849258
Took me awhile to have time to try your code,
works perfectly,
Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question