Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2006, 05:44 PM
Registered User
 
Join Date: Oct 2006
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)
  Next

  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


Steve





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





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