M
Mark Hurd
Is there a simpler acceptable syntax for
(New Class).Method
than
With New Class
.Method
End With
In VB.NET you can use Call
Call (New Class).Method
but this syntax is not acceptable in VB6 (with or without the () at the
end).
FYI I am looking for VB6 and VB.NET answers, if they are different.
(Using Call in VB.NET is "acceptable", I'm just wondering if there is an
alternative syntax I haven't thought of.)
BTW Note that if you define an "identity" function:
Function Identity(ByVal C As Class) As Class
Identity = C
End Function
(And in VB.NET you can use Identity(Of T)(ByVal O As T) As T: Return O)
you can then say
Identity(New Class).Method
in both languages.
--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
Further info:
Commented out lines give syntax errors.
VB.NET (.WL is an Extension that calls Console.WriteLine, and this was
tested using the Snippet Compiler):
Sub RunSnippet()
with New String(New Char(){"a"c,"b"c,"0"c})
.WL()
end with
'(New String(New Char(){"a"c,"b"c,"1"c})).WL
'(New String(New Char(){"a"c,"b"c,"2"c})).WL()
Call (New String(New Char(){"a"c,"b"c,"3"c})).WL()
Identity(New String(New Char(){"a"c,"b"c,"4"c})).WL
Identity(New String(New Char(){"a"c,"b"c,"5"c})).WL()
DirectCast(New String(New Char(){"a"c,"b"c,"6"c}),String).WL
End Sub
private function Identity(of T)(o as T)as T
return o
end function
VB6:
Sub Main()
With New Form1
.TestFun
End With
'(New Form1).TestFun
'Call (New Form1).TestFun()
Dim i As Integer
'i=(new Form1).TestFun()
Dim f As Form1
Set f = New Form1
f.TestFun
i = f.TestFun
Identity(New Form1).TestFun
Call Identity(New Form1).TestFun
i = Identity(New Form1).TestFun()
End Sub
Private Function Identity(f As Form1) As Form1
Identity = f
End Function
Form1 contains:
Public Function TestFun() As Integer
:
End Function
(Yes I could have used a Class, it was just a test that evolved.)
(New Class).Method
than
With New Class
.Method
End With
In VB.NET you can use Call
Call (New Class).Method
but this syntax is not acceptable in VB6 (with or without the () at the
end).
FYI I am looking for VB6 and VB.NET answers, if they are different.
(Using Call in VB.NET is "acceptable", I'm just wondering if there is an
alternative syntax I haven't thought of.)
BTW Note that if you define an "identity" function:
Function Identity(ByVal C As Class) As Class
Identity = C
End Function
(And in VB.NET you can use Identity(Of T)(ByVal O As T) As T: Return O)
you can then say
Identity(New Class).Method
in both languages.
--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
Further info:
Commented out lines give syntax errors.
VB.NET (.WL is an Extension that calls Console.WriteLine, and this was
tested using the Snippet Compiler):
Sub RunSnippet()
with New String(New Char(){"a"c,"b"c,"0"c})
.WL()
end with
'(New String(New Char(){"a"c,"b"c,"1"c})).WL
'(New String(New Char(){"a"c,"b"c,"2"c})).WL()
Call (New String(New Char(){"a"c,"b"c,"3"c})).WL()
Identity(New String(New Char(){"a"c,"b"c,"4"c})).WL
Identity(New String(New Char(){"a"c,"b"c,"5"c})).WL()
DirectCast(New String(New Char(){"a"c,"b"c,"6"c}),String).WL
End Sub
private function Identity(of T)(o as T)as T
return o
end function
VB6:
Sub Main()
With New Form1
.TestFun
End With
'(New Form1).TestFun
'Call (New Form1).TestFun()
Dim i As Integer
'i=(new Form1).TestFun()
Dim f As Form1
Set f = New Form1
f.TestFun
i = f.TestFun
Identity(New Form1).TestFun
Call Identity(New Form1).TestFun
i = Identity(New Form1).TestFun()
End Sub
Private Function Identity(f As Form1) As Form1
Identity = f
End Function
Form1 contains:
Public Function TestFun() As Integer
:
End Function
(Yes I could have used a Class, it was just a test that evolved.)