Home All Groups Group Topic Archive Search About

string reset? why? how?

Author
18 Aug 2006 4:24 PM
RNEELY
I've inherited code similar to the following with a comment on resetting the
string.  Why would anyone want to do this?  How could this reset the string? 
What does it mean to reset a string?

    Public Sub SetTheStringToSomething(ByRef OutStr As String)
        OutStr = "123"
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        Dim s As String
        SetTheStringToSomething(s)
        Dim sOriginal$ = s
        s = sOriginal 'reset the string ' <- why?  how?
        Debug.WriteLine(s)
        Debug.WriteLine(sOriginal)
    End Sub
--
Regards,
-Ron

Author
18 Aug 2006 4:59 PM
Cor Ligthert [MVP]
RNeely,

To make his program unreadable for his coworkers and to make himself very
interesting.

Cor

Show quoteHide quote
"RNEELY" <RNE***@discussions.microsoft.com> schreef in bericht
news:7F7E56F0-4E91-497D-939A-CAA333076329@microsoft.com...
> I've inherited code similar to the following with a comment on resetting
> the
> string.  Why would anyone want to do this?  How could this reset the
> string?
> What does it mean to reset a string?
>
>    Public Sub SetTheStringToSomething(ByRef OutStr As String)
>        OutStr = "123"
>    End Sub
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim s As String
>        SetTheStringToSomething(s)
>        Dim sOriginal$ = s
>        s = sOriginal 'reset the string ' <- why?  how?
>        Debug.WriteLine(s)
>        Debug.WriteLine(sOriginal)
>    End Sub
> --
> Regards,
> -Ron
>
Author
18 Aug 2006 5:11 PM
tomb
Ron,
There could be any number of reasons someone would want to reset a
string, which only means putting it back to its original value.
If the string is used as a global variable that must default to a
certain value, but utilized to temporarily hold a new value that is
referenced somewhere else, then you would want to reset it after it is
referenced.
But, as Cor so eloquently pointed out, the example code is total
nonsense.  Is this a true representation of the code in question?

Tom

RNEELY wrote:

Show quoteHide quote
>I've inherited code similar to the following with a comment on resetting the
>string.  Why would anyone want to do this?  How could this reset the string? 
>What does it mean to reset a string?
>
>    Public Sub SetTheStringToSomething(ByRef OutStr As String)
>        OutStr = "123"
>    End Sub
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
>        Dim s As String
>        SetTheStringToSomething(s)
>        Dim sOriginal$ = s
>        s = sOriginal 'reset the string ' <- why?  how?
>        Debug.WriteLine(s)
>        Debug.WriteLine(sOriginal)
>    End Sub

>
Author
18 Aug 2006 5:35 PM
RNEELY
Yes, the representation is accurate.  Thanks for the sanity check.  The
assignment of s = sOriginal seems superfluous because it is superfluous. 
Don't know if this code was perhaps cut and pasted from inside a for loop? 
Doesn't matter.  It is still superfluous.
--
Regards,
-Ron



Show quoteHide quote
"tomb" wrote:

> Ron,
> There could be any number of reasons someone would want to reset a
> string, which only means putting it back to its original value.
> If the string is used as a global variable that must default to a
> certain value, but utilized to temporarily hold a new value that is
> referenced somewhere else, then you would want to reset it after it is
> referenced.
> But, as Cor so eloquently pointed out, the example code is total
> nonsense.  Is this a true representation of the code in question?
>
> Tom
>
> RNEELY wrote:
>
> >I've inherited code similar to the following with a comment on resetting the
> >string.  Why would anyone want to do this?  How could this reset the string? 
> >What does it mean to reset a string?
> >
> >    Public Sub SetTheStringToSomething(ByRef OutStr As String)
> >        OutStr = "123"
> >    End Sub
> >
> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) Handles MyBase.Load
> >        Dim s As String
> >        SetTheStringToSomething(s)
> >        Dim sOriginal$ = s
> >        s = sOriginal 'reset the string ' <- why?  how?
> >        Debug.WriteLine(s)
> >        Debug.WriteLine(sOriginal)
> >    End Sub
> > 
> >
>
Author
18 Aug 2006 5:55 PM
tommaso.gastaldi
tomb ha scritto:

> Ron,
> There could be any number of reasons someone would want to reset a
> string, which only means putting it back to its original value.
> If the string is used as a global variable that must default to a
> certain value, but utilized to temporarily hold a new value that is
> referenced somewhere else, then you would want to reset it after it is
> referenced.

perhaps they meant:

        Dim s As String = Nothing
        Dim sOriginal = s
        SetTheStringToSomething(s)

        s = sOriginal 'reset the string ' <- why?  how?

        Debug.WriteLine(s)
        Debug.WriteLine(sOriginal)



Show quoteHide quote
> But, as Cor so eloquently pointed out, the example code is total
> nonsense.  Is this a true representation of the code in question?
>
> Tom
>
> RNEELY wrote:
>
> >I've inherited code similar to the following with a comment on resetting the
> >string.  Why would anyone want to do this?  How could this reset the string?
> >What does it mean to reset a string?
> >
> >    Public Sub SetTheStringToSomething(ByRef OutStr As String)
> >        OutStr = "123"
> >    End Sub
> >
> >    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) Handles MyBase.Load
> >        Dim s As String
> >        SetTheStringToSomething(s)
> >        Dim sOriginal$ = s
> >        s = sOriginal 'reset the string ' <- why?  how?
> >        Debug.WriteLine(s)
> >        Debug.WriteLine(sOriginal)
> >    End Sub
> > 
> >
Author
18 Aug 2006 5:46 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"RNEELY" <RNE***@discussions.microsoft.com> schrieb:
> I've inherited code similar to the following with a comment on resetting
> the
> string.  Why would anyone want to do this?  How could this reset the
> string?
> What does it mean to reset a string?
>
>    Public Sub SetTheStringToSomething(ByRef OutStr As String)
>        OutStr = "123"
>    End Sub
>
>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim s As String
>        SetTheStringToSomething(s)
>        Dim sOriginal$ = s
>        s = sOriginal 'reset the string ' <- why?  how?
>        Debug.WriteLine(s)
>        Debug.WriteLine(sOriginal)


's' and 'sOriginal' always contain the same value because 'sOriginal' is set
to the value of 's' and the value gets reassigned to 's'.  I suggest to
remove 'sOriginal'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
22 Aug 2006 10:14 AM
Phill W.
RNEELY wrote:
Show quoteHide quote
> I've inherited code similar to the following with a comment on resetting the
> string.  Why would anyone want to do this?  How could this reset the string? 
> What does it mean to reset a string?
>
>     Public Sub SetTheStringToSomething(ByRef OutStr As String)
>         OutStr = "123"
>     End Sub
>
>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>         Dim s As String
>         SetTheStringToSomething(s)
>         Dim sOriginal$ = s
>         s = sOriginal 'reset the string ' <- why?  how?
>         Debug.WriteLine(s)
>         Debug.WriteLine(sOriginal)
>     End Sub

Another possiblity for you.
This may be a hang-over from a [much] earlier VB Type-ing problem.

If the Sub's /original/ declaration were

    Public Sub SetTheStringToSomething(ByRef OutStr)

Then (in VB) it would return a Variant /containing/ a String (and in
VB.Net an /Object/ containing a String).

Since sOriginal$ is explicitly Typed as a $tring, this may be an attempt
to /remove/ the Variant wrapper and get the value back in to a proper
String variable.

Regards,
    Phill  W.