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

O

Oliver

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?
 
G

Guest

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!
***************************
 
I

Imran Koradia

Cowboy (Gregory A. Beamer) - MVP said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top