473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 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

Aug 18 '06 #1
6 2051
RNeely,

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

Cor

"RNEELY" <RN****@discussions.microsoft.comschreef in bericht
news:7F**********************************@microsof t.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

Aug 18 '06 #2
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

Aug 18 '06 #3
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 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
Aug 18 '06 #4
"RNEELY" <RN****@discussions.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 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/>

Aug 18 '06 #5

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)
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
Aug 18 '06 #6
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
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.
Aug 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: spike | last post by:
My prygram goes through a string to find names between '\'-characters The problem is, parts of the name in sTemp remains if the new name is shorter than the old name. code...
2
by: Roger Withnell | last post by:
I need to reset a form to its original value using onclick rather than the Reset button. So, I have: <input type="button" name="reset" id="reset" value="Reset" onclick="form1.reset();"> where...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
2
by: ILCSP | last post by:
Hi, I have a sql table containing the answers for some tests. The information in this table is presented vertically and I need to create strings with them. I know how to read the data in VB.Net...
24
by: Derek Hart | last post by:
Is there an efficient line of code to count the number of instances of one string within another. If I have the sentence: "I want to go to the park, and then go home." It would give me a...
2
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
16
by: Giovanni D'Ascola | last post by:
Hi. I noticed that <input type="reset"actually don't enable checkbutton which are checked by default after they have been disabled by javascript. It's a bug?
4
by: raylopez99 | last post by:
I see that String and StringBuilder in C# / C++ do not have an easy way to set a string to null or zero length, once it is instantiated. Apparently some variant of the .NET languages do (reading...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.