Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to sneak around a NULL value
Hi Folks,

I have a short routine that will reverse the "Order-of-Characters" in
a text string. ( part of learning about encryption).

It works nicely...   until you send a Null value.

The problem is because I use a "For i = 1 to nCounter" kind of loop
to work the passed string into its new "Order-of-Character". nCounter
is the string length which is zero.
I have included an IF nCounter=0 then exit sub, but this is a function
and VB won't allow that cheat.

What can I do to resolve?




Thanks,

Paul
( This darn program refuses to do what I want
it to. It ONLY does what I tell it to...
and reluctantly. Remainds me of Bart Simpson )

Report this thread to moderator Post Follow-up to this message
Old Post
PaulB
04-26-05 08:56 PM


Re: How to sneak around a NULL value
<PaulB> wrote in message  news:mvss619kbg8vc3o0juj3iqsaffio32ht9j@
4ax.com...
> Hi Folks,
> I have included an IF nCounter=0 then exit sub, but this is a function
> and VB won't allow that cheat.
>
> What can I do to resolve?
>

IF nCounter=0 then exit function???



Report this thread to moderator Post Follow-up to this message
Old Post
MP
04-26-05 08:56 PM


RE: How to sneak around a NULL value
The syntax is

Exit Function


"PaulB" wrote:

> Hi Folks,
>
> I have a short routine that will reverse the "Order-of-Characters" in
> a text string. ( part of learning about encryption).
>
> It works nicely...   until you send a Null value.
>
> The problem is because I use a "For i = 1 to nCounter" kind of loop
> to work the passed string into its new "Order-of-Character". nCounter
> is the string length which is zero.
> I have included an IF nCounter=0 then exit sub, but this is a function
> and VB won't allow that cheat.
>
> What can I do to resolve?
>
>
>
>
> Thanks,
>
> Paul
> ( This darn program refuses to do what I want
>   it to. It ONLY does what I tell it to...
>   and reluctantly. Remainds me of Bart Simpson )
>

Report this thread to moderator Post Follow-up to this message
Old Post
Charlie
04-26-05 08:56 PM


Re: How to sneak around a NULL value
> I have included an IF nCounter=0 then exit sub, but this
> is a function and VB won't allow that cheat.

VB does have an Exit Function statement available to quit out of
functions in the same way Exit Sub quits out of Sub(routines).

Rick - MVP


Report this thread to moderator Post Follow-up to this message
Old Post
Rick Rothstein
04-26-05 08:56 PM


Re: How to sneak around a NULL value
PaulB wrote:
> Hi Folks,
>
> I have a short routine that will reverse the "Order-of-Characters" in
> a text string. ( part of learning about encryption).
>
> It works nicely...   until you send a Null value.

Do you really mean (VB parlance) an empty string?

> The problem is because I use a "For i = 1 to nCounter" kind of loop
> to work the passed string into its new "Order-of-Character". nCounter
> is the string length which is zero.
> I have included an IF nCounter=0 then exit sub, but this is a function
> and VB won't allow that cheat.

Ummm, how about Exit Function?

I'd likely structure the function like this, myself:

If Len(StrToRev) Then
' Perform the reversal, and assign return value.
End If

That'd end up returning an empty string when passed an empty string.

> What can I do to resolve?

Maybe if you showed the code you're having troubles with, actual proposals c
ould be
offered?

Later...   Karl
--
Working Without a .NET?
http://classicvb.org/petition



Report this thread to moderator Post Follow-up to this message
Old Post
Karl E. Peterson
04-26-05 08:56 PM


Re: How to sneak around a NULL value
First off: Null and Zero length string are two different things.  You are
talking about a zero length string in this case.

Second: Just test the len of the string prior to the looping routine.

Like:
If Len(MyString) = 0 Then Exit Sub

'Looping Code here

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/


<PaulB> wrote in message  news:mvss619kbg8vc3o0juj3iqsaffio32ht9j@
4ax.com...
> Hi Folks,
>
> I have a short routine that will reverse the "Order-of-Characters" in
> a text string. ( part of learning about encryption).
>
> It works nicely...   until you send a Null value.
>
> The problem is because I use a "For i = 1 to nCounter" kind of loop
> to work the passed string into its new "Order-of-Character". nCounter
> is the string length which is zero.
> I have included an IF nCounter=0 then exit sub, but this is a function
> and VB won't allow that cheat.
>
> What can I do to resolve?
>
>
>
>
> Thanks,
>
> Paul
> ( This darn program refuses to do what I want
>   it to. It ONLY does what I tell it to...
>   and reluctantly. Remainds me of Bart Simpson )



Report this thread to moderator Post Follow-up to this message
Old Post
Veign
04-26-05 08:56 PM


Re: How to sneak around a NULL value
<PaulB> wrote in message  news:mvss619kbg8vc3o0juj3iqsaffio32ht9j@
4ax.com...
> Hi Folks,
>
> I have a short routine that will reverse the "Order-of-Characters" in
> a text string. ( part of learning about encryption).
>
> It works nicely...   until you send a Null value.
>
> The problem is because I use a "For i = 1 to nCounter" kind of loop

'=============
Private Sub Form_Load()
Dim i As Integer
Dim nCounter As Integer

nCounter = 0

For i = 1 To nCounter
MsgBox "this won't run if nCounter = 0"
MsgBox ""
MsgBox "But, if it did, you can use Exit For"
MsgBox ""
MsgBox "Depending on the code after the Next below"
MsgBox "You can use Exit For instead of Exit Sub"
MsgBox "Maybe I misread the question too."
MsgBox ""
MsgBox "Exit Subs can be a pain imo because they"
MsgBox "allow more than one way out of a procedure"
MsgBox "and they're easily missed so they make"
MsgBox "debugging harder."
Next

End Sub
'=============

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..



Report this thread to moderator Post Follow-up to this message
Old Post
Ken Halter
04-26-05 08:56 PM


Re: How to sneak around a NULL value
Thanks,

I have already kicked myself for that question.

By the way, what "IS" the difference between a zero length string and
a NULL value string?


Thanks,

Paul
( This darn program refuses to do what I want
it to. It ONLY does what I tell it to...
and reluctantly. Remainds me of Bart Simpson )

Report this thread to moderator Post Follow-up to this message
Old Post
PaulB
04-26-05 08:56 PM


Re: How to sneak around a NULL value
<PaulB> wrote in message  news:f2vs61dfdp2eqk74s50o18p1oru377tb7a@
4ax.com...

> By the way, what "IS" the difference between a zero length string and
> a NULL value string?

Nothing, because the question is flawed. There is no such thing as a "NULL
value string." Strings CANNOT contain the value Null. Only Variants (and
data types which are implemented as Variants behind the scenes, like Date)
can contain Null.

What you're talking about (the "null string") comes from C terminology and
refers to a string that contains nothing but the terminating ASCII 0 (called
the Null character). We try to avoid that term in VB simply because Null is
such a commonly-used value and it gets confusing, as you have just
experienced.



Report this thread to moderator Post Follow-up to this message
Old Post
Jeff Johnson [MVP: VB]
04-26-05 08:56 PM


Re: How to sneak around a NULL value
An empty string is normally a pointer to an empty BSTR (i.e. the piece of
memory representing strings in Unicode). This has a normal length field
(containing 0) and an immediate NULL (=0) terminator (i.e. no text data in
it)

The constant represented by vbNullString is often referred to as a "null
string". It is different in that it is actually an empty pointer rather than
a pointer to an empty string. If you call StrPtr() on vbNullString then
you'll see it returns 0 rather than a pointer to the empty BSTR mentioned
above.

Tony Proctor

<PaulB> wrote in message  news:f2vs61dfdp2eqk74s50o18p1oru377tb7a@
4ax.com...
> Thanks,
>
> I have already kicked myself for that question.
>
> By the way, what "IS" the difference between a zero length string and
> a NULL value string?
>
>
> Thanks,
>
> Paul
> ( This darn program refuses to do what I want
>   it to. It ONLY does what I tell it to...
>   and reluctantly. Remainds me of Bart Simpson )



Report this thread to moderator Post Follow-up to this message
Old Post
Tony Proctor
04-27-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Pages (4): [1] 2 3 4 »
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.