473,698 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting to Custom Classes

Okay, this should be a simple thing, but I can't seemto find the right
documentation on it. I created a custom class that inherits from a well
known class. For example:
Class MyString Inherits String
Public Sub New()
MyBase.New()
'custom code here
End Sub
'Custom properties here
'Custom subs and functions here
End Class

Now, what I would like to be able to do is cast from the well known public
class to my new custom subclass. Do something like this:
Dim wellKnown As String
Dim myCustom As MyString

wellKnown = "Some string"
myCustom = wellKnown
'or if the above won't work
myCustom = CType(wellKnown , MyString)

Then if I'm really daring, be able to go back the other way:
wellKnown = myCustom
'or if need be
wellKnown = CType(myCustom, String)

Seems like it should be a simple action for inheritance, but I guess I'm
missing the obvious if so. I know that it means some values may not be
populated, but I'd like to gracefully handle it.

Any help would be greatly appreciated!

TIA,
SMFX
Nov 21 '05 #1
0 1036

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

Similar topics

13
1926
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
4
1248
by: ITnerd | last post by:
In the interest of code re-use, I would like to place some code in a utility class to be used by other classes. The problem is that this code requires the following snippet: for(i=0; i < tbl.Rows.Count; i++) { myDataRow = tbl.Rows; company.someNestedClass sc = new company.someNestedClass(); for(j=0; j < tbl.Columns.Count; j++) {
3
1679
by: Kurt | last post by:
i just can't figure out why something im doing is not working correctly.... public interface IInterface { int someProperty { get; set; }
0
1307
by: Kurt Lange | last post by:
no... the array is created dynamically. and no... that defeats the purpose of what im trying todo.. encapsulate all initializing of variables in base class... derive from it... by deriving from base class, and casting, derived classes would already have their variables initialiezed(cause they have already been initialized in the base class) ....
61
4565
by: Ken Allen | last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years. One of the drawbacks with VB6 and earlier was the difficulty in casting a 'record' to a different 'shape' so one could perform different manipulations on it. For example, I have a complex data structure, which I can represent in a VB6 TYPE declaration, but I cannot easily convert that to a fixed length array of unsigned bytes so that I could perform a checksum...
0
237
by: SMFX | last post by:
Okay, this should be a simple thing, but I can't seemto find the right documentation on it. I created a custom class that inherits from a well known class. For example: Class MyString Inherits String Public Sub New() MyBase.New() 'custom code here End Sub 'Custom properties here 'Custom subs and functions here
8
2125
by: Michael | last post by:
Hi, I think my problem deals with class casting and inheritance. I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes), and writing the result to disk afterwards. Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations.
8
9174
by: David Williams | last post by:
Hi all, I have a templated Vector3D class which holds (x,y,z) components as the specified type. I quite often wish to cast a Vector3D holding ints into a Vector3D holding floats and vice versa. Like so: Vector3D<int> intVec(10,20,30); Vector3D<float> floatVec = intVec; Of course this doesn't work. I would be happy if instead the following
2
1711
by: keithb | last post by:
I'm trying to understand C# type casting. The following code will not compile unless I Cast item to a String. private static String myData; foreach (DataRow row in MyTable.Rows) { foreach (Object item in row.ItemArray) {
3
2763
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some dead ends. I'm posting this to get some feedback on wether I'm going in the right direction, and at the same time hopefully save others from going through the process.
0
9170
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...
1
8901
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
7739
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
6528
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
5862
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
4371
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...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.