473,799 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it posible to do this casting in VB?

Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
end if

But I need to do it many times
Thanks

Mar 5 '07 #1
10 1497
" active" <ac********** @a-znet.comschrieb :
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
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(Acti veMdiChild, MyForm1)
return true
else
CastIt = DirectCast(Acti veMdiChild, MyForm2)
return false
end if
End Function

Cor

" active" <ac********** @a-znet.comschreef in bericht
news:uC******** ******@TK2MSFTN GP03.phx.gbl...
Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
end if

But I need to do it many times
Thanks



Mar 5 '07 #4
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb:
Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
return true
else
CastIt = DirectCast(Acti veMdiChild, 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(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
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.atschre ef in bericht
news:O1******** ******@TK2MSFTN GP04.phx.gbl...
"Cor Ligthert [MVP]" <no************ @planet.nlschri eb:
>Function CastIt (byval z as MyForm1, y as MyForm2) As boolean
if type of z is MyForm1 then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
return true
else
CastIt = DirectCast(Acti veMdiChild, 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(Acti veMdiChild, MyForm1)
return true
else
CastIt = DirectCast(Acti veMdiChild, MyForm2)
return false
end if
End Function

Cor

" active" <ac********** @a-znet.comschreef in bericht
news:uC******** ******@TK2MSFTN GP03.phx.gbl...
>Function CastIt (byval z as boolean) As ??
if z then
CastIt = DirectCast(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
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(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
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(Acti veMdiChild, MyForm1)
else
CastIt = DirectCast(Acti veMdiChild, 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.Getsomet hing

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(Acti veMdiChild, MyForm1).Getsom ething
else
qq = DirectCast(Acti veMdiChild, MyForm2).Getsom thing
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

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

Similar topics

3
74918
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 and the web interface filters out the classes..
4
3482
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 good way to do this is by example. So I will give an example and please tell me what you think: I have a base class A with a virtual destructor, and a class B that is it inherits publicly from A and defines som extra stuff.
0
2784
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 MySQL? :confused: Thanks for the help....
231
23251
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 (perhaps mistakenly) that the purpose of a void pointer was to cast into a legitimate date type. Is this wrong? Why, and what is considered to be correct form?
35
2709
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
30793
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 along. It says it's an invalid cast. However, if I use the Convert.ToInt32() method (for example) things will work. At least, that's how it appears to me. Could someone explain when to use old-style parenthesized casts vs. the Convert() methods?
11
1244
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
13715
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
4361
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 : char *tmp = NULL;
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.