By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,117 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Question with despair - will buy movie tickets for the first one who helps

P: n/a
Hi,
I have spent my entire weekend trying to solve this, now I have to admit I
need your help.

Here is my code:

Dim cred() As DataSourceCredentials
Dim cc As New DataSourceCredentials
cred(0) = cc
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

It crashes with the error message:Object Reference not set to
an instance of an Object

What am I missing?

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
For your single operation, you can do something like this:

Dim cc As New DataSourceCredentials
Dim cred() As DataSourceCredentials = {cc}
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

This is largely useless, but avoids the compile error. If you are going to
pop Credentials on and off the collection, you are better to set up cred as a
collection rather than a simple array.

You can also do something like:
Dim cred(1) As DataSourceCredentials
Dim cc As New DataSourceCredentials
cred(0) = cc
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

And Redim for additional values, remember to use Preserve to avoid clearing
out the initial values. You biggest isssue is there is no size to your array.
In the first example, the size is implicitly set to 1; in the second it is
explcitly set.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Oliver" wrote:
Hi,
I have spent my entire weekend trying to solve this, now I have to admit I
need your help.

Here is my code:

Dim cred() As DataSourceCredentials
Dim cc As New DataSourceCredentials
cred(0) = cc
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

It crashes with the error message:Object Reference not set to
an instance of an Object

What am I missing?

Jul 21 '05 #2

P: n/a
"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:97**********************************@microsof t.com...
For your single operation, you can do something like this:

Dim cc As New DataSourceCredentials
Dim cred() As DataSourceCredentials = {cc}
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

This is largely useless, but avoids the compile error. If you are going to
pop Credentials on and off the collection, you are better to set up cred as a collection rather than a simple array.

You can also do something like:
Dim cred(1) As DataSourceCredentials
Dim cc As New DataSourceCredentials
cred(0) = cc
cred(0).DataSourceName = "198.87.87.6"
cred(0).Password = "XXX"
cred(0).UserName = "YYY"

And Redim for additional values, remember to use Preserve to avoid clearing out the initial values. You biggest isssue is there is no size to your array. In the first example, the size is implicitly set to 1; in the second it is
explcitly set.


just a minor correction..in the second case, size is explicitly to 2 -
cred(0) will set the size to 1..apart from that all's good :)
Imran.
Jul 21 '05 #3

P: n/a
On Mon, 22 Nov 2004 10:46:41 -0500, Oliver wrote:
Dim cred() As DataSourceCredentials
Here you have created an array to hold DataSourceCredentials objects, but
it is empty, that is, it has no elements in it. You need to first ReDim
the array to hold the number of objects you need:

ReDim cred(9) 'Use whatever number is appropriate for your situation
Dim cc As New DataSourceCredentials


This line is unnecessary, instead, use something like this:

For x as integer = 0 to 9
cred(x) = New DataSourceCredentials
cred(x).DataSourceName = "198.87.87.6"
cred(x).Password = "XXX"
cred(x).UserName = "YYY"
Next

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.
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.