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?

RE: Question with despair - will buy movie tickets for the first one w by NoSpamMgbworld

NoSpamMgbworld
Mon Nov 22 10:03:02 CST 2004

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

Re: Question with despair - will buy movie tickets for the first one w by Imran

Imran
Mon Nov 22 10:10:38 CST 2004

"Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@comcast.netNoSpamM> wrote
in message news:9745B80A-03ED-4FC7-8294-82CF58F15874@microsoft.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.



Re: Question with despair - will buy movie tickets for the first one who helps by David

David
Thu Dec 30 10:28:14 CST 2004

You need to allocate memory for cred.
See code below for an example. Option 2 is an alternative.

Cheers,
Dave

=============================

Imports System.Collections

Module Module1

Sub Main()
Option1()
option2()
End Sub

Sub Option1()
Dim cred(5) 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"

' This is better
cc.DataSourceName = "198.87.87.6"
cc.Password = "XXX"
cc.UserName = "YYY"
cred(0) = cc

End Sub

Sub option2()
Dim cred As ArrayList = New ArrayList
Dim cc As New DataSourceCredentials

cc.DataSourceName = "198.87.87.6"
cc.Password = "XXX"
cc.UserName = "YYY"

cred.Add(cc)
End Sub
End Module




On Mon, 22 Nov 2004 10:46:41 -0500, "Oliver" <spam@deviso.com> 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?
>
>