BBM,
| However, I've never understood why VB.Net allows you to do this (use a
| function without requiring you assign it to something). In 1986 Turbo
Pascal
| could catch this. There's no reason for something to be a function unless
| the return value is useful.
I agree; It would be nice if it was an option, however for those developers
who create functions that return an "error status" (rather then relying on
Exceptions) & never check them. Or those developers who don't really know
the difference between Sub & Function, who always use Function. It could
"break" their code. Or those "advanced developers" who create functions that
return "additional info" that is needed sometimes & not needed other times.
It could be problematic for their code. Of course they could simply assign
the return value to a local value & ignore. Wait, that's what the compiler
is doing now ;-)
' Return True it succeeded, False it Fails
Public Function DoSomething() As Boolean
Try
Return True
Catch
Return False
End Try
End Function
' I don't care if I did something, ignore return code
DoSomething()
verses
Dim bitBucket As Boolean = DoSomething()
' Never refer to bitBucket again
VS.NET 2005 adds some new compiler messages that can be configured as either
errors or warnings, I'm not sure if not using the return value is one of
them (I don't have my VS.NET 2005 VPC running right now to check)... One of
the messages I know is there is unused local variable, unfortunately in the
above sample bitBucket would be marked as unused...
Unfortunately I suspect its too late in the VS.NET 2005 development cycle to
add the message.
| I was lucky enough to catch my error in test. I'll bet there's about a
| billion occurences of errors similar to mine in production code.
I would suggest Unit Testing (TDD - Test Driven Development) to help ensure
bugs like this do not make it to your production code.
www.nunit.org is unit
testing tool I currently use. VS.NET 2005's Team System also includes a unit
testing tool.
Hope this helps
Jay
"BBM" <bb*@bbmcompany.com> wrote in message
news:7C**********************************@microsof t.com...
| You're right. I was in a hurry and missed the fact that string.replace is
a
| function.
|
| However, I've never understood why VB.Net allows you to do this (use a
| function without requiring you assign it to something). In 1986 Turbo
Pascal
| could catch this. There's no reason for something to be a function unless
| the return value is useful.
|
| I was lucky enough to catch my error in test. I'll bet there's about a
| billion occurences of errors similar to mine in production code.
|
| Thanks again for your help and prompt response.
|
| BBM
|
| "Marina" wrote:
|
| > Replace does not modify the original string. It returns a new one with
the
| > replacements.
| >
| > Meaning, you have to assign the return of Replace to a variable. This is
| > well documented.
| >
| > "BBM" <bb*@bbmcompany.com> wrote in message
| > news:35**********************************@microsof t.com...
| > > This is so bizarre I hesitate to post it, but I need to get this
working.
| > >
| > > My code looks like this...
| > >
| > > Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
| > > " WHERE Scenario =
| > > @Scenario"
| > > Dim cmdstr as String
| > >
| > > cmdstr = cmdTestResourcesSel
| > > If history Then
| > > cmdstr.Replace("TResources", "TResourcesHistory")
| > > End If
| > > Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)
| > >
| > > History is true. Coming out of the "if" statement, cmdstr is
unchanged.
| > > CommandText of the SQLCommand contains "TResources" not
| > > "TResourcesHistory"
| > > This same code template works in the same program in about a dozen
other
| > > places. No exceptions thrown. I can do the replace on cmdstr in the
| > > command window while debugging the app and it works fine.
| > >
| > > What's up with this???
| > >
| > > Thanks for your help.
| > >
| > > BBM
| >
| >
| >