string reset? why? how?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RNEELY

    #1

    string reset? why? how?

    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 SetTheStringToS omething(ByRef OutStr As String)
    OutStr = "123"
    End Sub

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

  • Cor Ligthert [MVP]

    #2
    Re: string reset? why? how?

    RNeely,

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

    Cor

    "RNEELY" <RNEELY@discuss ions.microsoft. comschreef in bericht
    news:7F7E56F0-4E91-497D-939A-CAA333076329@mi crosoft.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 SetTheStringToS omething(ByRef OutStr As String)
    OutStr = "123"
    End Sub
    >
    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    Dim s As String
    SetTheStringToS omething(s)
    Dim sOriginal$ = s
    s = sOriginal 'reset the string ' <- why? how?
    Debug.WriteLine (s)
    Debug.WriteLine (sOriginal)
    End Sub
    --
    Regards,
    -Ron
    >

    Comment

    • tomb

      #3
      Re: string reset? why? how?

      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 SetTheStringToS omething(ByRef OutStr As String)
      OutStr = "123"
      End Sub
      >
      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      >System.EventAr gs) Handles MyBase.Load
      Dim s As String
      SetTheStringToS omething(s)
      Dim sOriginal$ = s
      s = sOriginal 'reset the string ' <- why? how?
      Debug.WriteLine (s)
      Debug.WriteLine (sOriginal)
      End Sub
      >
      >

      Comment

      • RNEELY

        #4
        Re: string reset? why? how?

        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



        "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 SetTheStringToS omething(ByRef OutStr As String)
        OutStr = "123"
        End Sub

        Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        Dim s As String
        SetTheStringToS omething(s)
        Dim sOriginal$ = s
        s = sOriginal 'reset the string ' <- why? how?
        Debug.WriteLine (s)
        Debug.WriteLine (sOriginal)
        End Sub
        >

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: string reset? why? how?

          "RNEELY" <RNEELY@discuss ions.microsoft. comschrieb:
          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 SetTheStringToS omething(ByRef OutStr As String)
          OutStr = "123"
          End Sub
          >
          Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          Dim s As String
          SetTheStringToS omething(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/>

          Comment

          • tommaso.gastaldi@uniroma1.it

            #6
            Re: string reset? why? how?


            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
            SetTheStringToS omething(s)

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

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


            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 SetTheStringToS omething(ByRef OutStr As String)
            OutStr = "123"
            End Sub

            Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
            System.EventArg s) Handles MyBase.Load
            Dim s As String
            SetTheStringToS omething(s)
            Dim sOriginal$ = s
            s = sOriginal 'reset the string ' <- why? how?
            Debug.WriteLine (s)
            Debug.WriteLine (sOriginal)
            End Sub

            Comment

            • Phill W.

              #7
              Re: string reset? why? how?

              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 SetTheStringToS omething(ByRef OutStr As String)
              OutStr = "123"
              End Sub
              >
              Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
              System.EventArg s) Handles MyBase.Load
              Dim s As String
              SetTheStringToS omething(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 SetTheStringToS omething(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.

              Comment

              Working...