473,395 Members | 1,466 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,395 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 1392
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.