473,666 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String functions run on empty string

I have a form in which several elements are expected to be all digits.
Some of those elements can be left empty, but if specified they must
be all digits. I have this Sub to edit them:

Sub NumEdit(ByRef Req, ByVal value, ByRef size, ByRef name, ByRef tag)
Dim allDigs
Set allDigs = new RegExp
allDigs.Pattern = "^\d+$"

If IsNull(value) Then
value = ""
Else
value = trim(value)
End If

If len(value) = 0 Then
If Req = false Then
Return
Else
AddMessage name & " must be supplied.", tag
End if
ElseIf size 0 And len(value) <size Then
AddMessage name & " must be " & size & " characters.", tag
ElseIf allDigs.test(va lue) = false Then
AddMessage name & " must be numeric.", tag
End If
End Sub
It's invoked by a line like this:
NumEdit false, Request.Form("z ip"), 5, "Zip code", "zip"

In this case, the "zip" element is not required, but if present it
must be exactly five digits. (AddMessage stores an error message. It
works fine).

When zip is not given, the page blows up. I've experimented with
taking the values of various functions of Request.Form("z ip"), with
the following results:

zip=
IsEmpty(zip)=Fa lse
IsNull(zip)=Fal se
Len(zip)=0
Trim(zip)=
IsEmpty(Trim(zi p))=
IsNull(Trim(zip ))=
len(Trim(Zip))=

So Request.Form("z ip") is not Empty, it's not Null, and its Len is 0.
But once I apply Trim to it, everything goes to heck. IsEmpty, IsNull,
and Len return nothing at all, and I get no error message.

What's happeneing?

--
Tim Slattery
MS MVP(DTS)
Sl********@bls. gov
http://members.cox.net/slatteryt
Jul 11 '07 #1
1 2591
Tim Slattery <Sl********@bls .govwrote:
>I have a form in which several elements are expected to be all digits.
Some of those elements can be left empty, but if specified they must
be all digits. I have this Sub to edit them:

Sub NumEdit(ByRef Req, ByVal value, ByRef size, ByRef name, ByRef tag)
Dim allDigs
Set allDigs = new RegExp
allDigs.Pattern = "^\d+$"

If IsNull(value) Then
value = ""
Else
value = trim(value)
End If

If len(value) = 0 Then
If Req = false Then
Return
Ugh! Now I find out that "Return" is not valid VBScript, I have to use
Exit Sub.

That makes the Sub work. I still don't understand the results I
reported lower down, but it doesn't matter much now.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls. gov
http://members.cox.net/slatteryt
Jul 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
5881
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less important changes, so in this thread I would like to focus on that issue alone. I have edited the Proposed Syntax example below to take out the changes unecessary to this discussion. I left in the change of "instance variable" syntax (...
19
10910
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple empty strings in the resulting string array.
8
4339
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I have done this as follows: LPOLESTR dunk_data = (LPOLESTR)T2CW(data_name);
4
1426
by: AVL | last post by:
Hi, I read that to check for empty strings , comparing strings using String.Length == 0 is faster than String.Empty or "" . Is it true...? If so, how?
3
1412
by: scorpion53061 | last post by:
I have little hope of resolving this as I have had to contact outside help. But I thought I would post it here to see if anyone could add an idea or solution. 1. I have a form in a Class Control library along with 6 other namespaces. My root functions are in this form and all the other namespaces revolve around this form. I add the project as a dll to another windows project and call its functions there. Option Strict is
13
1526
by: Ivar | last post by:
Hi guys - So basically I am trying to implement a function that converts an int to a string, but it is not working for some reason - any thoughts? My function, intToStr, is shown below. I'm just trying to implement this to gain practice with c-style strings. #include<iostream> #include"testString.h" int main(int argc, char* argv) { char* c2 = new char;
35
5819
by: jacob navia | last post by:
Hi guys! I like C because is fun. So, I wrote this function for the lcc-win32 standard library: strrepl. I thought that with so many "C heads" around, maybe we could improve it in a collective brainstorming session. Let's discuss some C here, for a change :-)
6
7607
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
3
2057
by: digz | last post by:
This is a very simplified version of something I am trying to understand. The State object holds the strings and maps , and I pass a reference to State to the process Function which manipulates it based on the tag passed in. I cannot pass the strings/maps in question as references coz .. a) thats redundant, state has everything, it increases number of parameters unnecessarily b) I have to do the case/switch outside the function to...
9
4554
by: WebArchitect | last post by:
I have a text file. My text file contains lines with double quotes around it. I trying to code if a line has double quotes around it Then make it bold My code is below and it is not working. Please Help <? $filename = "whatsnew.txt"; # file to read if (file_exists($filename)) {
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.