Code check please...

  • Thread starter Thread starter Derek Martin
  • Start date Start date
D

Derek Martin

Thanks in advance:

Dim thisperson(7) As Array
Dim validcheck As Boolean = False

thisperson = getperson(usernametextbox.Text, pinnumbertextbox.Text)
....

private function getperson(byval username as string, byval pinnumber as
string)
....
dim returnarray(7)
....

return returnarray

Error: Invalid cast exception is being thrown on thisperson = ... after it
executes the function...what am I missing here????

Thanks!
Derek
 
Derek Martin said:
Thanks in advance:

Dim thisperson(7) As Array
Dim validcheck As Boolean = False

thisperson = getperson(usernametextbox.Text, pinnumbertextbox.Text)
...

private function getperson(byval username as string, byval pinnumber as
string)
...
dim returnarray(7)

Should this not be Dim returnarray(7) As Array?
 
Well, I was following what you said and actually removed the as array from
thisperson to yield:

Dim thisperson(7)
and then
Dim returnarray(7)

same error....
????


Derek
 
I'm not sure if this is the problem, but you should declare "returnarray" as
an "Array" object and specify the return type of the "getperson" function to
be "as Array()".

Are you actually trying to return an array of arrays?
 
That was what I tried in my first attempt and it gave me the cast error. I
am returning an array of strings: returnarray(0) = bob,
returnarray(1)=hello, etc.

???
:-)

Derek
 
Hi Derek,

Make it you more covertable even with the approach which is not ideal for
this.

Dim thisperson(7) As String
Dim validcheck As Boolean = False

thisperson = getperson(usernametextbox.Text, pinnumbertextbox.Text)
....

private function getperson(byval username as string, byval pinnumber as
string) as String()
....
dim returnarray(7) as String()

return returnarray

I think this should do it.

Cor
 
On Thu, 1 Apr 2004 20:59:13 +0200, Cor wrote:

Hi Cor
dim returnarray(7) as String()

Doesn't this line create an array of string arrays? Shouldn't it be:

Dim returnarray(7) As String

??
 
It should be the same type of declaration as the original array. That's the
only way to return it from the function without the "Invalid cast"
exception. I'm guessing this was a type-o...

dim returnarray(7) as String
 
That did it - typos suck! Thank you all!

Derek

Scott said:
It should be the same type of declaration as the original array. That's the
only way to return it from the function without the "Invalid cast"
exception. I'm guessing this was a type-o...

dim returnarray(7) as String
 
Hi Chris,
Doesn't this line create an array of string arrays? Shouldn't it be:

Dim returnarray(7) As String
Of course typos, thank you to point the attention to it.

Cor
 
Back
Top