473,569 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specified cast is not valid.

Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object) As
Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class
Nov 21 '05 #1
6 2301
Can you post the entire text of the exception? The message would indicate
what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object) As
Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class

Nov 21 '05 #2
Hi.

Here is the exception.

?ex
{System.Invalid CastException}
[System.InvalidC astException]: {System.Invalid CastException}
HelpLink: Nothing
InnerException: Nothing
Message: "Specified cast is not valid."
Source: "test"
StackTrace: " at test.clsCompani es.Add(clsCompa ny Obj) in
c:\inetpub\wwwr oot\test\Class1 .vb:line 10"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OB******** ******@tk2msftn gp13.phx.gbl...
Can you post the entire text of the exception? The message would indicate
what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object)
As Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class


Nov 21 '05 #3
Now, can you show us line 10 of c:\inetpub\wwwr oot\test\Class1 .vb so we can
see just which line of code the compiler is having trouble casting?
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:d%******** ***********@new s4.e.nsc.no...
Hi.

Here is the exception.

?ex
{System.Invalid CastException}
[System.InvalidC astException]: {System.Invalid CastException}
HelpLink: Nothing
InnerException: Nothing
Message: "Specified cast is not valid."
Source: "test"
StackTrace: " at test.clsCompani es.Add(clsCompa ny Obj) in
c:\inetpub\wwwr oot\test\Class1 .vb:line 10"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OB******** ******@tk2msftn gp13.phx.gbl...
Can you post the entire text of the exception? The message would
indicate what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object)
As Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class



Nov 21 '05 #4
I'm guessing the problem is in here:

Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

So, a couple of questions for you.. are you working with Option Strict
turned on? If not, you should be. It would alert you to problems like this
with a blue wavy underline before you ever attempt to run your code.

Second, does the Add method of the clsArray class return anything? If so,
what does it return (an array perhaps)? If it does return an array, then
your problem is that you are attempting to assign an Integer to an array and
so the cast would be invalid.

If this is the case, change this:

Dim Index As Integer

to this:

Dim Index As Array

Does this help?
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:d%******** ***********@new s4.e.nsc.no...
Hi.

Here is the exception.

?ex
{System.Invalid CastException}
[System.InvalidC astException]: {System.Invalid CastException}
HelpLink: Nothing
InnerException: Nothing
Message: "Specified cast is not valid."
Source: "test"
StackTrace: " at test.clsCompani es.Add(clsCompa ny Obj) in
c:\inetpub\wwwr oot\test\Class1 .vb:line 10"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OB******** ******@tk2msftn gp13.phx.gbl...
Can you post the entire text of the exception? The message would
indicate what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object)
As Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class



Nov 21 '05 #5
Hi.

Here are the answers to your previous post:
"Now, can you show us line 10 of c:\inetpub\wwwr oot\test\Class1 .vb so we
can
see just which line of code the compiler is having trouble casting?"

Line 10: Index = clsArray.Add(Co mpanyArray, Obj)
And now for the post i replayed on:

Thanks for the tip on the Option Strict.
When i turned this on the compiler tells me this:
Option Strict On disallows implicit conversions from '1-dimensional
array of System.Object' to '1-dimensional array of test.clsCompany '.

Since i now know what the problem is, i need help solving this one also.

What i try to do is to make a general array class. This class only contains
shared functions so no need for any instance of this class inside all my
other classes.
Why i need this is that i have a lot of container classes for other classes
like class Companies are for class Company.
The clsArray should have functions like Add, Find, Remove, Exist, RemoveAll,
ToString etc...
So when i make the other container classes like class Companies all i have
to do is to call all the shared functions in clsArray for the machting
function in class Companies.

How can i write the shared procedure Add so it will support an array of any
class (Company, Person, Car etc).
I now used the following statement:
Shared Function Add(ByRef ObjArray() as Object, ObjToAdd as Object) as
Integer
The return integer should be the index from the array where the new element
(object) was added.

I really hope i do not have to make all of my shared function with a
spesific class type.
Any idea how to solve this ? Perhaps with some Cast statements ?

Please use my example and modify it the way you need to make this work.

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:uc******** ******@TK2MSFTN GP15.phx.gbl...
I'm guessing the problem is in here:

Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

So, a couple of questions for you.. are you working with Option Strict
turned on? If not, you should be. It would alert you to problems like
this with a blue wavy underline before you ever attempt to run your code.

Second, does the Add method of the clsArray class return anything? If so,
what does it return (an array perhaps)? If it does return an array, then
your problem is that you are attempting to assign an Integer to an array
and so the cast would be invalid.

If this is the case, change this:

Dim Index As Integer

to this:

Dim Index As Array

Does this help?
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:d%******** ***********@new s4.e.nsc.no...
Hi.

Here is the exception.

?ex
{System.Invalid CastException}
[System.InvalidC astException]: {System.Invalid CastException}
HelpLink: Nothing
InnerException: Nothing
Message: "Specified cast is not valid."
Source: "test"
StackTrace: " at test.clsCompani es.Add(clsCompa ny Obj) in
c:\inetpub\wwwr oot\test\Class1 .vb:line 10"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OB******** ******@tk2msftn gp13.phx.gbl...
Can you post the entire text of the exception? The message would
indicate what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
Hi.

I run into this problem and i could need some help to solve it.
The project is an ASP.NET Web project.

Including code sample of the problem.

Any idea what is causing the error message ?

John-Arne Lillebø
The ASPX page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'test is the project name.
Dim var_Companies As New test.clsCompani es
Dim var_Company As New test.clsCompany
Dim Index As Integer

var_Company.Nam e = "Test"

Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)
Index = var_Companies.A dd(var_Company)

var_Company = Nothing
var_Companies = Nothing
End Sub
The Class1.vb file

Public Class clsCompanies
Private CompanyArray() As clsCompany

Public Sub New()
ReDim CompanyArray(0)
End Sub
Public Function Add(ByVal Obj As clsCompany) As Integer
Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally
Add = Index
End Try
End Function
End Class

Public Class clsCompany
Private var_Name As String

Public Property Name() As String
Get
Name = var_Name
End Get
Set(ByVal Value As String)
var_Name = Value
End Set
End Property
End Class

Public Class clsArray
Shared Function Add(ByRef objArray() As Object, ByVal Obj As Object)
As Integer
Dim Index As Integer

Index = -1

Try
If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0)) =
False Then
ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
End If

objArray(objArr ay.GetUpperBoun d(0)) = Obj

Index = CInt(objArray.G etUpperBound(0) )
Catch ex As Exception
System.Diagnost ics.Debugger.Br eak()
Throw ex
Finally

End Try

Return Index
End Function
End Class



Nov 21 '05 #6
Ok John, here's the deal.

First to address the exception you are getting...Your Add method isn't
returning an Integer (although you may want it to), it is returning an Array
and Index is declared as an Integer so:

Index = clsArray.Add(Co mpanyArray, Obj)

tells the compiler to take the array that the add method returns and convert
it to an object and this is where your program is crashing. Even if that
part worked, Index is declared as an integer and you would still get an
exception there as well.

What you want to do is get away from an "array" class and create a
Strongly-Typed collection class. Arrays are for data-types that should
contain more than one value using the same pointer. Collections are for
objects that should contain groups of other objects.

Here's a sample:

Public Class Companies
Inherits System.Collecti ons.CollectionB ase

Default Public Property Item(ByVal Index As Integer) As Integer
Get
Return CType(Me.List.I tem(Index))
End Get
Set(ByVal Value As Index)
Me.List.Item(In dex) = Value
End Set
End Property

Public Function Add(ByVal myComp As Company) As Integer
Me.List.Add(myC omp)

'Returns the size of the collection and since the item just added
will be added to the
'end of the collection, this should be the index of the item just
added
Return Me.List.Count -1
End Sub

Public Sub Remove(ByVal myComp As Company)
Me.List.Remove( myComp )
End Sub

Public Sub RemoveAll()
Me.List.Clear()
End Sub

Public Function Exists(ByVal index As Integer) As Boolean
If IsNothing(Me.Li st.Item(index)) Then
Return False
Else
Return True
End If
End Function

End Class

Hope this helps.

-Scott
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:4j******** ************@ne ws2.e.nsc.no...
Hi.

Here are the answers to your previous post:
"Now, can you show us line 10 of c:\inetpub\wwwr oot\test\Class1 .vb so
we can
see just which line of code the compiler is having trouble casting?"

Line 10: Index = clsArray.Add(Co mpanyArray, Obj)
And now for the post i replayed on:

Thanks for the tip on the Option Strict.
When i turned this on the compiler tells me this:
Option Strict On disallows implicit conversions from '1-dimensional
array of System.Object' to '1-dimensional array of test.clsCompany '.

Since i now know what the problem is, i need help solving this one also.

What i try to do is to make a general array class. This class only
contains shared functions so no need for any instance of this class inside
all my other classes.
Why i need this is that i have a lot of container classes for other
classes like class Companies are for class Company.
The clsArray should have functions like Add, Find, Remove, Exist,
RemoveAll, ToString etc...
So when i make the other container classes like class Companies all i have
to do is to call all the shared functions in clsArray for the machting
function in class Companies.

How can i write the shared procedure Add so it will support an array of
any class (Company, Person, Car etc).
I now used the following statement:
Shared Function Add(ByRef ObjArray() as Object, ObjToAdd as Object) as
Integer
The return integer should be the index from the array where the new
element (object) was added.

I really hope i do not have to make all of my shared function with a
spesific class type.
Any idea how to solve this ? Perhaps with some Cast statements ?

Please use my example and modify it the way you need to make this work.

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:uc******** ******@TK2MSFTN GP15.phx.gbl...
I'm guessing the problem is in here:

Dim Index As Integer
Try
Index = clsArray.Add(Co mpanyArray, Obj)

So, a couple of questions for you.. are you working with Option Strict
turned on? If not, you should be. It would alert you to problems like
this with a blue wavy underline before you ever attempt to run your code.

Second, does the Add method of the clsArray class return anything? If
so, what does it return (an array perhaps)? If it does return an array,
then your problem is that you are attempting to assign an Integer to an
array and so the cast would be invalid.

If this is the case, change this:

Dim Index As Integer

to this:

Dim Index As Array

Does this help?
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:d%******** ***********@new s4.e.nsc.no...
Hi.

Here is the exception.

?ex
{System.Invalid CastException}
[System.InvalidC astException]: {System.Invalid CastException}
HelpLink: Nothing
InnerException: Nothing
Message: "Specified cast is not valid."
Source: "test"
StackTrace: " at test.clsCompani es.Add(clsCompa ny Obj) in
c:\inetpub\wwwr oot\test\Class1 .vb:line 10"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

John-Arne Lillebø

"Scott M." <s-***@nospam.nosp am> wrote in message
news:OB******** ******@tk2msftn gp13.phx.gbl...
Can you post the entire text of the exception? The message would
indicate what line is running into this problem.
"John-Arne Lillebø" <ja*@will.not.g et.any.spam.bar n-nett.com> wrote in
message news:MK******** ***********@new s4.e.nsc.no...
> Hi.
>
> I run into this problem and i could need some help to solve it.
> The project is an ASP.NET Web project.
>
> Including code sample of the problem.
>
> Any idea what is causing the error message ?
>
> John-Arne Lillebø
>
>
> The ASPX page:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles MyBase.Load
> 'test is the project name.
> Dim var_Companies As New test.clsCompani es
> Dim var_Company As New test.clsCompany
> Dim Index As Integer
>
> var_Company.Nam e = "Test"
>
> Index = var_Companies.A dd(var_Company)
> Index = var_Companies.A dd(var_Company)
> Index = var_Companies.A dd(var_Company)
> Index = var_Companies.A dd(var_Company)
>
> var_Company = Nothing
> var_Companies = Nothing
> End Sub
>
>
> The Class1.vb file
>
> Public Class clsCompanies
> Private CompanyArray() As clsCompany
>
> Public Sub New()
> ReDim CompanyArray(0)
> End Sub
> Public Function Add(ByVal Obj As clsCompany) As Integer
> Dim Index As Integer
> Try
> Index = clsArray.Add(Co mpanyArray, Obj)
>
> Catch ex As Exception
> System.Diagnost ics.Debugger.Br eak()
> Throw ex
> Finally
> Add = Index
> End Try
> End Function
> End Class
>
> Public Class clsCompany
> Private var_Name As String
>
> Public Property Name() As String
> Get
> Name = var_Name
> End Get
> Set(ByVal Value As String)
> var_Name = Value
> End Set
> End Property
> End Class
>
> Public Class clsArray
> Shared Function Add(ByRef objArray() As Object, ByVal Obj As
> Object) As Integer
> Dim Index As Integer
>
> Index = -1
>
> Try
> If objArray.GetUpp erBound(0) > 0 Or IsNothing(objAr ray(0))
> = False Then
> ReDim Preserve objArray(objArr ay.GetUpperBoun d(0) + 1)
> End If
>
> objArray(objArr ay.GetUpperBoun d(0)) = Obj
>
> Index = CInt(objArray.G etUpperBound(0) )
> Catch ex As Exception
> System.Diagnost ics.Debugger.Br eak()
> Throw ex
> Finally
>
> End Try
>
> Return Index
> End Function
> End Class
>



Nov 21 '05 #7

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

Similar topics

0
3618
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception: "Specified cast is not valid." The only thing i put there was a "test this." inside the form. What might be the problem here? Thanks in advance. ...
4
7022
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
10500
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my columns is a template column where I'd like to evaluate the data brought back from the db and populate the column with a "Y" or "N" depending on the...
2
3085
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: try {
3
2172
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application. --------------------------------------------------------------------------------
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is not valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException: Specified cast is not valid. --->...
0
1604
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks. ----------------------------------------------------------- Server VS.NET 2003 SQLServer 2000 IIS 66.0
8
4256
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is not valid"). How do I fix it ? using System.Diagnostics; .. .. class NewProcess: Process {
3
12421
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean...
2
8745
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; Microsoft.Web.UI.WebControls.TreeNode iNode = null;
0
8118
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...
1
7666
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...
0
7964
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...
0
6278
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...
1
5504
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...
0
5217
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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
1
1208
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.