473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is happening here....

zmbd
5,501 Expert Mod 4TB
OK, I've used this little function off and on for quite awhile... works slick until recently.

Normally this function returns only the alphanumerics...
Takes a string like "AS456^(SK)-4"
and returns "AS4564"

Recently it started doing this:
Takes a string like "AS456^(SK)-4"
and returns "^()-"

I fixed that by taking the passed string as a value (the original code had nothing there)

Then a few days ago, what caused me to think about the details of this code is that one report needed to preserve the dash and underscore in some of the strings... so I altered the pattern expression....

It dawned on me... why does that work?
The pattern is inside the the IF...THEN structure... I'm using late binding so the Object RegEx should always be "Nothing;" thus the pattern and the object should never be read... and yet, this works!?

I've stepped thru the code a 100 times and the lines inside the IF...THEN structure never executes.

If you take the pattern as it is in the code below:
"AS123@#$_345-Az"
will return
"AS123_345-Az"

If you alter the code to my normal pattern of
Expand|Select|Wrap|Line Numbers
  1. .Pattern = "[^a-zA-Z0-9]"
Then:
"AS123@#$_345-Az"
will return
"AS123345Az"

and yet the line is never executed.

(I'm using late binding here; so no library references to the regular expressions so that I don't have to deal with seting the reference on all of the lab-PCs)


Expand|Select|Wrap|Line Numbers
  1. Function RemChrs(ByVal s As String) As String
  2.     Static RegEx As Object
  3.  
  4.     If RegEx Is Nothing Then
  5.         Set RegEx = CreateObject("VBScript.RegExp")
  6.         With RegEx
  7.             .Global = True
  8.             .Pattern = "[^a-zA-Z0-9_\-]"
  9.         End With
  10.     End If
  11.     RemChrs = RegEx.Replace(s, "")
  12. End Function
I use this function alot to strip illegal charactors out of data entry on forms and never thought about it.

Dazed and confussed (@_@)
Aug 21 '14 #1
7 1389
jimatqsi
1,271 Expert 1GB
I'm not following you. You said " I'm using late binding so the Object RegEx should always be "Nothing;" thus the pattern and the object should never be read." What does that mean, "should never be read"?

The If test in line 4 is satisfied because Regex is Nothing; Lines 5-9 get executed, logically.I'm not sure why the debugger wouldn't step through those lines but there are rare times when the debugger actually interferes with the code.

I'm not sure why you're mystified about why it normally works. I'm not sure why it does not work when you step through the code with the debugger. And I don't know at all why it just recently started not working for you.

Sorry, I'm not much help.

Jim
Aug 22 '14 #2
Rabbit
12,516 Expert Mod 8TB
Since you declared it as a static object, the if block should run the very first time the function is called and never again as long as the code is still in memory.

Close and reopen the database. Set the breakpoint. Call the function. It should run the if block. Run it again, it should no longer run the if block.
Aug 22 '14 #3
NeoPa
32,556 Expert Mod 16PB
I'm a little confused as to what the question is but, like Rabbit, I'll assume it's "Why do I never see the code between the If ... and End If lines execute?".

In that case, my response is exactly that of Rabbit's. I strongly suspect you'll see it execute just the once - exactly as he suggests.
Aug 22 '14 #4
zmbd
5,501 Expert Mod 4TB
There you go Rabbit.
Thank you NeoPa -

Of Course it's the "static" setting, don't even need to run the code.

Just having one of those obtuse, forst for the trees days. (^_^)

I just stepped away from everything PC related for a day or two... knew it was something simple and why I was having to reset the project to get the pattern to change.

Working on the formating and reporting for too long and my eyes crossed.
Aug 25 '14 #5
NeoPa
32,556 Expert Mod 16PB
Good for you Z :-) We all have times like that I can assure you.
Aug 25 '14 #6
zmbd
5,501 Expert Mod 4TB
:blush: Embarrassed enough to kill the thread… then again… maybe it’s a good thing for others to see that experts/moderators are human too (^_^)

Besides, that little function is just too slick to keep to myself. I found it on the web looking to validate alphanumerics in a field. Now I use it to simply strip the fields of illegal charactors and don't worry about user input. (^_^)
Aug 25 '14 #7
NeoPa
32,556 Expert Mod 16PB
Interesting indeed :-) I don't use regular expressions from within VBA but I use them in TextPad and they are SO powerful.

Creating scripts from a list of data is so much fun. Even VBA code sometimes.
Aug 25 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: dan miller (moderator, s.p.d) | last post by:
trying to figure out scoping of 'globals' in modules. So I have test.py: glob = 1 def setglob(v): global glob glob = v def getglob(): return glob
3
by: nin234 | last post by:
I am trying to create a Binary Search Tree in the code below. I am posting this question more from a C++ point of view rather than Binary search tree techniques. This is is the output of running...
2
by: Barry Mossman | last post by:
Hi, What is required to unwire an event ? I wire it with: this.MyEvent += new MyEventHandler() Do I need to maintain a handle to the eventhandler created so that I can detach it ? The...
4
by: Garry Freemyer | last post by:
I'm trying to convert this macro to a c# function but I have a big problem. It's on the LEFT side of an assignment statement and I am extremely flustered over this one because I'm a little rusty...
2
by: Jim in Arizona | last post by:
Being new, i experiment a lot and usually get results I'm not hoping for. My current problem is reading from a SQL 2000 table and populating an ASP dropdownlist with a column from the table. The...
6
by: News | last post by:
When I write a simple height or width CSS for a tag using percentage it seems to give unreliable results. ..BannerPurple { background-color: #660066; height: 60%; width: 50%; }
4
by: shapper | last post by:
Hello, I am trying to send an email from a form in my web page. I have the following codes: ... Dim mailSettings As New System.Net.Configuration.MailSettingsSectionGroup Dim smtpClient As...
9
by: Jonathan Wood | last post by:
I found the following class on the Web: public class LoginRewriter : IHttpModule { void IHttpModule.Dispose() { } void IHttpModule.Init(HttpApplication app) { app.AuthorizeRequest += new...
2
by: sarandnl08 | last post by:
Hi all, I can't find any problem in this program, i getting empty string as output, why? what happening here any one help? int main() { char *p1=“name”; char *p2; ...
2
by: parag_paul | last post by:
#include <stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf("%s\n",h(f(1,2))); printf("%s\n",g(f(1,2))); return 0;
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.