|
-
Jul 9th, 2012, 09:47 PM
#1
Thread Starter
PowerPoster
Classic VB6 conversion
VB6 and VB.NET are very similar in many ways.
I am having a difficulty trying to see whats going on, partly because of the method being literally over 5,000 lines of code but also partly because things are being done here there and everywhere.
I am trying to convert it ultimately to C# but VB.NET is fine.
Code:
Dim validScenario as tScenario
if condition then
with validScenario
.MsgType = "blah"
end with
else if condition2
with validScenario
.SomeProp = 1
end with
else
...
end if
so what is going on there? Everytime there is a with, is it using a new instance of the type or is it just using the existing instance and modifying the relevant properties?
I know what with is used for, makes you write less code and faster in performance when using it on the long type. But im puzzled by the above VB6 code.
should I be created a new instance everytime or not?
-
Jul 9th, 2012, 11:57 PM
#2
Re: Classic VB6 conversion
Possibly this may have made more sense (to write less code):
Code:
With validScenario
if condition then
.MsgType = "blah"
else if condition2
.SomeProp = 1
else
...
end if
End with
Of course that thought is just based on the info provided, and as you alluded to, it's more complex than that
-
Jul 10th, 2012, 12:06 AM
#3
Re: Classic VB6 conversion
... and each time (both code versions) the same instance is being used, and that shouldn't be altered.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jul 10th, 2012, 12:26 AM
#4
Re: Classic VB6 conversion
If that is the entire block of code, then I have to assume tScenario is a valuetype, because you don't ever actually call a New constructor to create an instance of it.
Regarding the With keyword, no new instance is created, it is from a compiler perspective the same thing as:
Code:
Dim validScenario as tScenario
if condition then
validScenario.MsgType = "blah"
else if condition2
validScenario.SomeProp = 1
else
...
end if
-
Jul 10th, 2012, 04:37 AM
#5
Thread Starter
PowerPoster
Re: Classic VB6 conversion
thanks all. much appreciated - i thought as much that it would be using the same instance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|