Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 5th, 2006, 05:44 PM
Registered User
Join Date: Oct 2006
Location: Houston, Tx, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default REGEX Problem - Excel Hangs

See code below. This code worked on many previous versions - suddenly has started failing on the following line

"s_data = regex.Replace(s_data, "$1" & vbCrLf".

Works for 7 iterations and then fails on 8th. However, when 8th iteration is run by itself it works.

Size or memeory problem? Is there a way to set cachesize. I've seen some references to the property, but received error when I tried to set it.

Public Sub TPTToCell(destination As Range, TPTResponse As String)
  'Take TPT format a pastes it into a sheet at "destination"

  Dim regex As Object
  Dim s As String
  Dim s_header As String
  Dim s_data As String
  Dim s_value As String
  Dim NumColumns As String
  Dim a_header() As String
  Dim m As Variant
  Dim matches As Variant
  Dim tests As Variant

  Set regex = CreateObject("vbscript.regexp")

  'strip out bad characters that will cause regex to crash or go into infinite loops
  'some of the output had characters in it that I could not determine. So this pattern
  ' is a pass-thru filter instead of trying to figure out which characters were causing trouble
  ' I only pass those that do not cause trouble.
  regex.Pattern = "[^A-Za-z0-9_ |()./\\\-%]"
  regex.Global = True

  TPTResponse = regex.Replace(TPTResponse, "")

  regex.Pattern = "\|"

  TPTResponse = regex.Replace(TPTResponse, vbTab)

  regex.Global = False
  regex.IgnoreCase = True

  ' get just the header
  regex.Pattern = "^((.*?\t){5})(.*)"
  regex.MultiLine = False

  Set matches = regex.Execute(TPTResponse)
  For Each m In matches
    tests = m.Value
    s_header = m.SubMatches(0)
    s_data = m.SubMatches(2)

  FillRangeFromCSV destination, s_header

  NumColumns = destination.Offset(, 3).Value
  regex.Pattern = "((.*?\t){" & NumColumns & "})"
  regex.Global = True

  s_data = regex.Replace(s_data, "$1" & vbCrLf
  FillRangeFromCSV destination.Offset(2), s_data
  Set regex = Nothing

End Sub

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Regex problem cajedi Classic ASP Professional 0 December 7th, 2006 04:36 AM
ASP Regex problem cajedi Classic ASP Basics 0 December 7th, 2006 04:35 AM
Server hangs on Me z323791 Classic ASP Basics 1 March 28th, 2005 07:19 PM
Regex Problem claudew BOOK: ASP.NET Website Programming Problem-Design-Solution 2 June 5th, 2004 07:55 PM
My Program Hangs! zaimi Visual C++ 1 May 21st, 2004 06:34 AM

All times are GMT -4. The time now is 04:10 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.