473,657 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting Objects Equal to an Object of Base Class

I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInf o
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.Com pareTo

My issue comes when I try to set an instance of FSFileSystemInf o to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo(" ./")
Dim FSInfo() As FSFileSystemInf o
DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in advance.
Feb 19 '06 #1
4 1585
The DirInfo.GetFile SystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable of
the FSFileSystemInf o
type. You need to convert the FileSystemInfo object to a FSFileSystemInf o
object.

Try:

FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o)
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:77******** *************** ***********@mic rosoft.com...
I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInf o
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.Com pareTo

My issue comes when I try to set an instance of FSFileSystemInf o to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo(" ./")
Dim FSInfo() As FSFileSystemInf o
DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in
advance.

Feb 19 '06 #2
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemIn fos into an array of
FSFileSystemInf o Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.File SystemInfo[]'
to type 'FSFileSystemIn fo[]'.

"Stephany Young" wrote:
The DirInfo.GetFile SystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable of
the FSFileSystemInf o
type. You need to convert the FileSystemInfo object to a FSFileSystemInf o
object.

Try:

FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o)
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:77******** *************** ***********@mic rosoft.com...
I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInf o
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.Com pareTo

My issue comes when I try to set an instance of FSFileSystemInf o to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo(" ./")
Dim FSInfo() As FSFileSystemInf o
DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in
advance.


Feb 19 '06 #3
Sorry ... Missed the array and ended up putting you crook.

I'm going to have to ask you at this stage, what sort of operations are you
going to be carrying out with your FSFileSystemInf o class.

The reason I ask is that implementing your class is going to be fraught with
difficulty for reasons that include:

- FileSystemInfo is the base class for the DirectoryInfo and
FileInfo classes.

- DirectoryInfo.G etFileSystemInf os returns an array that can be
a mixture of DirectoryInfo and FileInfo objects.

- You will not be able to deal with the returned DirectoryInfo and
FileInfo objects unless you create your own classes that derive
from FSFileSystemInf o.

If you are looking to get a list of files in a directory that match a given
pattern and sort them, then you do not need to go to all this trouble.

Instead you can use the shared Directory.GetFi les(string, string) overloaded
method to return a string array of the matching files and then use one of
the shared Array.Sort overloaded methods to sort the aray, with or woithout
an IComparer as required.
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemIn fos into an array of
FSFileSystemInf o Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.File SystemInfo[]'
to type 'FSFileSystemIn fo[]'.

"Stephany Young" wrote:
The DirInfo.GetFile SystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable
of
the FSFileSystemInf o
type. You need to convert the FileSystemInfo object to a FSFileSystemInf o
object.

Try:

FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o)
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:77******** *************** ***********@mic rosoft.com...
>I am extending FileSystemInfo class so that I can Implement Icomparable.
>My
> custom class looks like:
>
> Class FSFileSystemInf o
> Inherits FileSystemInfo : Implements Icomparable
> Function CompareTo(ByVal o As Object) As Integer _
> Implements IComparable.Com pareTo
>
> My issue comes when I try to set an instance of FSFileSystemInf o to an
> object that is FileSystemInfo type. Such as:
>
> Dim DirInfo As New DirectoryInfo(" ./")
> Dim FSInfo() As FSFileSystemInf o
> DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
> FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS
>
> I get a Cast Error when I do the previous statment and I am unsure how
> to
> cast one object into another within VB.NET. Thanks for any help in
> advance.
>
>


Feb 19 '06 #4
That's it. I just got off on a wrong foot. thanks!

"Stephany Young" wrote:
Sorry ... Missed the array and ended up putting you crook.

I'm going to have to ask you at this stage, what sort of operations are you
going to be carrying out with your FSFileSystemInf o class.

The reason I ask is that implementing your class is going to be fraught with
difficulty for reasons that include:

- FileSystemInfo is the base class for the DirectoryInfo and
FileInfo classes.

- DirectoryInfo.G etFileSystemInf os returns an array that can be
a mixture of DirectoryInfo and FileInfo objects.

- You will not be able to deal with the returned DirectoryInfo and
FileInfo objects unless you create your own classes that derive
from FSFileSystemInf o.

If you are looking to get a list of files in a directory that match a given
pattern and sort them, then you do not need to go to all this trouble.

Instead you can use the shared Directory.GetFi les(string, string) overloaded
method to return a string array of the matching files and then use one of
the shared Array.Sort overloaded methods to sort the aray, with or woithout
an IComparer as required.
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemIn fos into an array of
FSFileSystemInf o Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.File SystemInfo[]'
to type 'FSFileSystemIn fo[]'.

"Stephany Young" wrote:
The DirInfo.GetFile SystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable
of
the FSFileSystemInf o
type. You need to convert the FileSystemInfo object to a FSFileSystemInf o
object.

Try:

FSInfo = CType(DirInfo.G etFileSystemInf os("*-*.pdf"), FSFileSystemInf o)
"FacultasNetDev eloper" <da**********@h otmail.com> wrote in message
news:77******** *************** ***********@mic rosoft.com...
>I am extending FileSystemInfo class so that I can Implement Icomparable.
>My
> custom class looks like:
>
> Class FSFileSystemInf o
> Inherits FileSystemInfo : Implements Icomparable
> Function CompareTo(ByVal o As Object) As Integer _
> Implements IComparable.Com pareTo
>
> My issue comes when I try to set an instance of FSFileSystemInf o to an
> object that is FileSystemInfo type. Such as:
>
> Dim DirInfo As New DirectoryInfo(" ./")
> Dim FSInfo() As FSFileSystemInf o
> DirInfo = New DirectoryInfo(S erver.MapPath(" .\"))
> FSInfo = DirInfo.GetFile SystemInfos("*-*.pdf") //THIS FAILS
>
> I get a Cast Error when I do the previous statment and I am unsure how
> to
> cast one object into another within VB.NET. Thanks for any help in
> advance.
>
>


Feb 19 '06 #5

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

Similar topics

11
3002
by: K.K. | last post by:
Suppose I have a class called Vehicle with many fields. Now I make a new class derived from Vehicle called Car. I'd like to make a method to copy the data from a Vehicle instance to a Car instance. Is writing a long series of assignments in a Clone() statement my only option? I know that I can write a Clone method using MemberwiseClone(), but my understanding is that the object created by MemberwiseClone is of the same type.
0
1579
by: Cat | last post by:
I have class Base, and class Derived. I am serializing Derived objects from XML, and these Derived objects are allowed to 'inherit' the values from other named Base objects already defined in the XML. <Base name="cat"/> <Derived name="tabby" inherits="cat"/> Some Derived objects are not fully described in the XML, and their members
7
12881
by: Prabhudhas Peter | last post by:
I have two object instances of a same class... and i assigned values in both object instances (or the values can be taken from databse and assigned to the members of the objects)... Now i want to compare these two objects so that it will return true if both object's members have the same value... it is good if u can give me a single function or simple code snippet.. Thank U -- Peter...
161
7806
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
15
7594
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
4
3757
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, (sorry to begin with Java in a Python list ;-) in Java, when I want to pass input to a function, I pass "InputStream", which is a base class of any input stream. In Python, I found that "file" objects exist. While specifying argument types in Python is not possible as in Java, it is possible to check whether an object is an instance of some class and that's what I need - I need to check if an argument is a "file"-like object,...
15
3518
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and you want to make a deque which can contain any objects of any of those types. Normally what you would have to do is to make a deque or vector of pointers of the base class type and then allocate each object dynamically with 'new' and store the...
3
1986
by: kjell | last post by:
Hi, I wonder if someone may have a solution to a small problem I'm experiencing with a C++ program? I'm have two classes in my application that provides methods for setting parameters in the classes. These methods returns a pointer to the class itself so that you can use the return value to call another attribute setting method on the same line. This is what my program look like: #include <iostream>
7
1960
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. The original post at gnu.gcc.help can be found at this link http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/ece55cbbd9c36270/2148a6c1ac6119e1?lnk=st&q=#2148a6c1ac6119e1 Here's the question: class base {
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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
8823
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
8726
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...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
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
6163
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
4151
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
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.