473,405 Members | 2,171 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,405 software developers and data experts.

Error using object type array.

Despite the fact this deals with webservices I believe it is a VB question.

I am working on a test application that passes data to a webservice.
The webservices takes a variable type that is defined below:

Public Class Variable
Inherits MarshalByRefObject

'<remarks/>
Public strVariableName As String

'<remarks/>
Public objVariableValue() As Object
End Class

My code is as follows
Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name

If I use the above code I get a "Specified Cast is not Valid" error.

If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here

I get "Object reference not set to an instance of an object." as my
error. What am I missing?
Nov 21 '05 #1
7 1487
On Tue, 28 Sep 2004 09:14:33 -0400, William Apple wrote:
Public Class Variable
Inherits MarshalByRefObject

'<remarks/>
Public strVariableName As String

'<remarks/>
Public objVariableValue() As Object
End Class

My code is as follows
Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name


You've declared objVariableValue as an array of objects, so you need to
initialize it as an array of objects and specify a size for the array:

Public objVariableValue(size) As Object

Or if you didn't mean for objVariableValue to be an array of objects,
remove the parentheses in the declaration:

'<remarks/>
Public objVariableValue As Object

Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2
Chris has answered the first part of your problem. For the second part:
If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here


What variable is 'name'? I don't see it being declared anywhere in the piece
of code you've posted. Is this declared somewhere else? Or did you mean
something like:
varList(0).objVariableValue(0) = "name"
If so, then you do need to create an instance of the object before assigning
it a value:
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = "name"
hope that helps..
Imran.
Nov 21 '05 #3
I didn't write the webservice, so I have no control over the declaration of
objVariableValue. Is it possible to get this to work or is it a bug on their
part?

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:yl*****************************@40tude.net...
On Tue, 28 Sep 2004 09:14:33 -0400, William Apple wrote:
Public Class Variable
Inherits MarshalByRefObject

'<remarks/>
Public strVariableName As String

'<remarks/>
Public objVariableValue() As Object
End Class

My code is as follows
Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name


You've declared objVariableValue as an array of objects, so you need to
initialize it as an array of objects and specify a size for the array:

Public objVariableValue(size) As Object

Or if you didn't mean for objVariableValue to be an array of objects,
remove the parentheses in the declaration:

'<remarks/>
Public objVariableValue As Object

Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #4
My code should have read.....the variable name was declared. How I wish it
was simple stupidity on my part.

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name

If I use the above code I get a "Specified Cast is not Valid" error.

If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ua*************@TK2MSFTNGP14.phx.gbl...
Chris has answered the first part of your problem. For the second part:
If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here
What variable is 'name'? I don't see it being declared anywhere in the

piece of code you've posted. Is this declared somewhere else? Or did you mean
something like:
varList(0).objVariableValue(0) = "name"
If so, then you do need to create an instance of the object before assigning it a value:
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = "name"
hope that helps..
Imran.

Nov 21 '05 #5
The problem is that you've not defined the length of the objVariableValue
array. So, you should do something like this:

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

' this will make your object array of length 3
ReDim varList(0).objVariableValue(2)

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospam-cisys.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
My code should have read.....the variable name was declared. How I wish it
was simple stupidity on my part.

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name

If I use the above code I get a "Specified Cast is not Valid" error.

If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ua*************@TK2MSFTNGP14.phx.gbl...
Chris has answered the first part of your problem. For the second part:
If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here


What variable is 'name'? I don't see it being declared anywhere in the

piece
of code you've posted. Is this declared somewhere else? Or did you mean
something like:
varList(0).objVariableValue(0) = "name"
If so, then you do need to create an instance of the object before

assigning
it a value:
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = "name"
hope that helps..
Imran.


Nov 21 '05 #6
Thanks, that works. I also found this to work also

varlist(0).objVariableValue = New Object(2) {}

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The problem is that you've not defined the length of the objVariableValue
array. So, you should do something like this:

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

' this will make your object array of length 3
ReDim varList(0).objVariableValue(2)

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospam-cisys.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
My code should have read.....the variable name was declared. How I wish it was simple stupidity on my part.

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name

If I use the above code I get a "Specified Cast is not Valid" error.

If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ua*************@TK2MSFTNGP14.phx.gbl...
Chris has answered the first part of your problem. For the second part:
> If I code it this way...
>
> Dim varList(2) as Variable
>
> varList(0) = New Variable
> varList(0).strVariableName = "Name"
> varList(0).objVariableValue(0) = name <-- Error Occurs here

What variable is 'name'? I don't see it being declared anywhere in the

piece
of code you've posted. Is this declared somewhere else? Or did you mean something like:
varList(0).objVariableValue(0) = "name"
If so, then you do need to create an instance of the object before

assigning
it a value:
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = "name"
hope that helps..
Imran.



Nov 21 '05 #7
Yup - thats fine too. However, if you just want to assign the variable
'name' to the object, you don't necessarily have to create a new instance
(which is what's happening with New Object(2) {}) since the instance already
exists (the 'name' instance) and you directly assign the reference to it.
Just a thought...

Imran.

"William Apple" <wa****@nospam-cisys.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
Thanks, that works. I also found this to work also

varlist(0).objVariableValue = New Object(2) {}

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The problem is that you've not defined the length of the objVariableValue
array. So, you should do something like this:

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

' this will make your object array of length 3
ReDim varList(0).objVariableValue(2)

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = New Object
varList(0).objVariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospam-cisys.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
My code should have read.....the variable name was declared. How I wish
it was simple stupidity on my part.

Dim varList(2) as Variable
Dim name As Object

name = "xyz"

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue = New Object <- Error Occurs Here
varList(0).objVariableValue(0) = name

If I use the above code I get a "Specified Cast is not Valid" error.

If I code it this way...

Dim varList(2) as Variable

varList(0) = New Variable
varList(0).strVariableName = "Name"
varList(0).objVariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microsoft.com> wrote in message
news:ua*************@TK2MSFTNGP14.phx.gbl...
> Chris has answered the first part of your problem. For the second part: >
> > If I code it this way...
> >
> > Dim varList(2) as Variable
> >
> > varList(0) = New Variable
> > varList(0).strVariableName = "Name"
> > varList(0).objVariableValue(0) = name <-- Error Occurs here
>
> What variable is 'name'? I don't see it being declared anywhere in
the piece
> of code you've posted. Is this declared somewhere else? Or did you

mean > something like:
> varList(0).objVariableValue(0) = "name"
> If so, then you do need to create an instance of the object before
assigning
> it a value:
> varList(0).objVariableValue(0) = New Object
> varList(0).objVariableValue(0) = "name"
>
>
> hope that helps..
> Imran.
>
>



Nov 21 '05 #8

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
7
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything...
1
by: Vaibhav Modak | last post by:
Hi All, I have a Web Service written in Java (Web Logic) and I am trying to call it in my ASP. NET client. I am facing a problem while getting the data from the Web Service Method. My Web...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
3
by: Jeremy Chapman | last post by:
I've writtin a very simple web service in axis which returns an array of classes. I consume it in a .net app. When receiving the response, my .net app generates an error "Cannot assign object...
5
by: Al G | last post by:
Hi, I'm converting a bit of POP3 VB6 code to VB2005, and have run into this error with the following code. Can someone help me find out what I'm missing/doing wrong? 'holds the attachments...
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
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 projectplanning, coding, testing,...
0
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...

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.