473,385 Members | 1,848 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,385 software developers and data experts.

Is it posible to do this casting in VB?

Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?
Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

But I need to do it many times
Thanks

Mar 5 '07 #1
10 1466
" active" <ac**********@a-znet.comschrieb:
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?
Not really, if the method is declared in both types separately and they
share 'Form' as common base class.

However, if you define the method in a base type (base class) or implement
an interface containing the method, you can use this type as the method's
return type.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 5 '07 #2
active wrote:
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?
Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

But I need to do it many times
Thanks
You can't make a function return different data types.

What you can do is to make a base class that inherits Form and contains
the virtual method GetSomething, and let each form inherit from the base
class instead of Form and implement the GetSomething method.

Then you can cast your reference to the base class, and call the method.

--
Göran Andersson
_____
http://www.guffa.com
Mar 5 '07 #3
Hi,

Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
return true
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
return false
end if
End Function

Cor

" active" <ac**********@a-znet.comschreef in bericht
news:uC**************@TK2MSFTNGP03.phx.gbl...
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?
Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

But I need to do it many times
Thanks



Mar 5 '07 #4
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
return true
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
return false
end if
End Function
What would be the task this procedure solves?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mar 5 '07 #5
Don't mean to question your need for such a function but it seems unlikely
to be of much use. In your example the variable qq would have been declared
as a given form type right? The DirectCast information would simply be lost
if it is of type Form.

Perhaps posting a little more information would help, what's the goal?
" active" <ac**********@a-znet.comwrote...
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?

Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

But I need to do it many times

Thanks

Mar 5 '07 #6
Herfried,

I don't know but I can me immage, that I have 1 special and more general
formats for my MDI form. (Not so unusual), If I than have to do something
where a cast is needed I can do this.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.atschreef in bericht
news:O1**************@TK2MSFTNGP04.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
>Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
return true
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
return false
end if
End Function

What would be the task this procedure solves?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 5 '07 #7
Excuse me for saying it, but that is pure nonsense.

:: As the return value of the method is Boolean, you can not assign a
form to it.

:: You a mixing the use of parameters with the use of global/member
variables.

:: The parameter y is never used at all.

:: The type of z is always MyForm1 so the if statement is pointless.

:: Casting to the specific form class serves no purpose at all, as the
return type of a method is always the same.

:: Assigning a value to the method name serves no purpose if you are
also using Return.

Cor Ligthert [MVP] wrote:
Hi,

Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
return true
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
return false
end if
End Function

Cor

" active" <ac**********@a-znet.comschreef in bericht
news:uC**************@TK2MSFTNGP03.phx.gbl...
>Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?
Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

But I need to do it many times
Thanks
--
Göran Andersson
_____
http://www.guffa.com
Mar 5 '07 #8
On Mar 4, 6:34 pm, " active" <activeNOS...@a-znet.comwrote:
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?

Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if
I'm not sure what you're attempting to accomplish. Does GetSomething
return a different type for each form?

Mar 5 '07 #9
Chris Dunaway wrote:
On Mar 4, 6:34 pm, " active" <activeNOS...@a-znet.comwrote:
>Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(ActiveMdiChild, MyForm1)
else
CastIt = DirectCast(ActiveMdiChild, MyForm2)
end if
End Function

Can I make a function in VB that returns the result of a DirectCast.

I think what I don't know is what to use for ?? above.

Is it possible to do this in VB?

Thanks

PS
I'd use it like this

ZZ= CastIt.Getsomething

Where both MyForm1 and MyForm2 have the property Getsomething

I find it hard to believe the compiler would let me do that but maybe you
see a different approach.

I could do it without a function
if z then
qq = DirectCast(ActiveMdiChild, MyForm1).Getsomething
else
qq = DirectCast(ActiveMdiChild, MyForm2).Getsomthing
end if

I'm not sure what you're attempting to accomplish. Does GetSomething
return a different type for each form?
Yes, that is what he would like to do, but i have already explained that
this is impossible.

--
Göran Andersson
_____
http://www.guffa.com
Mar 5 '07 #10
Goran,

You are right,

Cor
Mar 5 '07 #11

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

Similar topics

3
by: | last post by:
hey all, i wonder if it is posible to make a A:HOVER without a class defintion.. so <a href="#" style="{color:red;};HOVER{color:blue}">test</a> because i am sending html email in the body ...
4
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
0
by: Banx | last post by:
Hi everyone, i'm trying to copy data from a table in Pervasive database to a table in MySQL Does anyone know how to do it? :confused: Is it posible to copy data from another database prog to...
231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
35
by: ytrama | last post by:
Hi, I have read in one of old posting that don't cast of pointer which is returned by the malloc. I would like to know the reason. Thanks in advance, YTR
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
11
by: chinthamani | last post by:
Hai I want to create a COM in C# .Net, is it posible to create a COM in C# Net, if how can we create a COM in C# .Net. Regards S.Vinodh Noel (Bangalore)
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
101
by: Tinkertim | last post by:
Hi, I have often wondered if casting the return value of malloc() (or friends) actually helps anything, recent threads here suggest that it does not .. so I hope to find out. For instance : ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.