473,888 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MarshalByRefObj ect

'<remarks/>
Public strVariableName As String

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

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

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(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).strV ariableName = "Name"
varList(0).objV ariableValue(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 1503
On Tue, 28 Sep 2004 09:14:33 -0400, William Apple wrote:
Public Class Variable
Inherits MarshalByRefObj ect

'<remarks/>
Public strVariableName As String

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

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

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(0) = name


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

Public objVariableValu e(size) As Object

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

'<remarks/>
Public objVariableValu e As Object

Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[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).strV ariableName = "Name"
varList(0).objV ariableValue(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).objV ariableValue(0) = "name"
If so, then you do need to create an instance of the object before assigning
it a value:
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(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
objVariableValu e. Is it possible to get this to work or is it a bug on their
part?

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

'<remarks/>
Public strVariableName As String

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

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

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(0) = name


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

Public objVariableValu e(size) As Object

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

'<remarks/>
Public objVariableValu e As Object

Hope this helps

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[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).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(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).strV ariableName = "Name"
varList(0).objV ariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microso ft.com> wrote in message
news:ua******** *****@TK2MSFTNG P14.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).strV ariableName = "Name"
varList(0).objV ariableValue(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).objV ariableValue(0) = "name"
If so, then you do need to create an instance of the object before assigning it a value:
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(0) = "name"
hope that helps..
Imran.

Nov 21 '05 #5
The problem is that you've not defined the length of the objVariableValu e
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).objV ariableValue(2)

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospa m-cisys.com> wrote in message
news:uY******** ******@TK2MSFTN GP15.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).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(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).strV ariableName = "Name"
varList(0).objV ariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microso ft.com> wrote in message
news:ua******** *****@TK2MSFTNG P14.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).strV ariableName = "Name"
varList(0).objV ariableValue(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).objV ariableValue(0) = "name"
If so, then you do need to create an instance of the object before

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


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

varlist(0).objV ariableValue = New Object(2) {}

"Imran Koradia" <no****@microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The problem is that you've not defined the length of the objVariableValu e
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).objV ariableValue(2)

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospa m-cisys.com> wrote in message
news:uY******** ******@TK2MSFTN GP15.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).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(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).strV ariableName = "Name"
varList(0).objV ariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microso ft.com> wrote in message
news:ua******** *****@TK2MSFTNG P14.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).strV ariableName = "Name"
> varList(0).objV ariableValue(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).objV ariableValue(0) = "name"
If so, then you do need to create an instance of the object before

assigning
it a value:
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(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****@nospa m-cisys.com> wrote in message
news:uT******** ******@TK2MSFTN GP09.phx.gbl...
Thanks, that works. I also found this to work also

varlist(0).objV ariableValue = New Object(2) {}

"Imran Koradia" <no****@microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The problem is that you've not defined the length of the objVariableValu e
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).objV ariableValue(2)

varList(0) = New Variable
varList(0).strV ariableName = "Name"
varList(0).objV ariableValue(0) = New Object
varList(0).objV ariableValue(0) = name
hope that helps..
Imran.

"William Apple" <wa****@nospa m-cisys.com> wrote in message
news:uY******** ******@TK2MSFTN GP15.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).strV ariableName = "Name"
varList(0).objV ariableValue = New Object <- Error Occurs Here
varList(0).objV ariableValue(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).strV ariableName = "Name"
varList(0).objV ariableValue(0) = name <-- Error Occurs here
"Imran Koradia" <no****@microso ft.com> wrote in message
news:ua******** *****@TK2MSFTNG P14.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).strV ariableName = "Name"
> > varList(0).objV ariableValue(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).objV ariableValue(0) = "name"
> If so, then you do need to create an instance of the object before
assigning
> it a value:
> varList(0).objV ariableValue(0) = New Object
> varList(0).objV ariableValue(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
4771
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 appreciated. Thanks in advance
4
2343
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. Therefore the application errors out when deserializing the xml data. It places the some part of the child element
7
3100
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 works fine. So I deploy the webservice on a remote machine (Linux box) and I get an error when calling the service. BUT: I can retrieve the WSDL and make a webreference in my VS.NET project, so obviously I (or more correct: My VS.NET project) am...
1
4173
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 Service returns me an object which is a wrapper around an array of objects. (Earlier I was trying to read the array directly but could not succeed - so I wrapped that array with another object.) Now the primary issue is regarding the chunky characters...
7
4750
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 project. The same class lib is included in the ASP.NET Web Application that calls the web-method I can successfully call the web-method with
0
23532
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) 5: Procedure call or argument is not valid. 6: Overflow. 7: Out of memory.
669
26407
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
3
6101
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 of type System.Object to an object of type PersonWS.WorkGroupData.". I've included the wsdl of the consumed axis web service, the request/responses of the web service by the .net app and the exception and stack trace. Hoping someone can tell me...
5
3265
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 Class attachmentBlockParameter
63
3929
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 How to make it compile? I also tried buf but that gives "segmentation fault". Thanks in advanced.
0
9961
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9800
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,...
1
10886
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
9597
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, and deploymentwithout 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
7990
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
5819
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
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
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
3
3252
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.