|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
string reset? why? how?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 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 > 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 > > 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. -- Show quoteHide quoteRegards, -Ron "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 > > > > > tomb ha scritto:
> Ron, perhaps they meant:> 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. 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 > > > >
Show quote
Hide quote
"RNEELY" <RNE***@discussions.microsoft.com> schrieb: 's' and 'sOriginal' always contain the same value because 'sOriginal' is set > 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) 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/> RNEELY wrote:
Show quoteHide quote > I've inherited code similar to the following with a comment on resetting the Another possiblity for you.> 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 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. |
|||||||||||||||||||||||