Code Comments
Programming Forum and web based access to our favorite programming groups.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 )
Post Follow-up to this message<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???
Post Follow-up to this messageThe 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 ) >
Post Follow-up to this message> 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
Post Follow-up to this messagePaulB 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
Post Follow-up to this messageFirst 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 )
Post Follow-up to this message<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..
Post Follow-up to this messageThanks, 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 )
Post Follow-up to this message<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.
Post Follow-up to this messageAn 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 )
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.