Why does a VB.Net function that returns string only actually return a single character?

Note: this answer was originally written by the OP, Kibbee, as a self-answer. However, it was written in the body of the question, not as an actual separate answer. Since the OP has refused repeated requests by other users, including a moderator, to repost in accordance with site rules, I’m reposting it myself.

After trying a hundred different things, refactoring my code, stepping through the code in the debugger many times, and even having a co-worker look into the problem, I finally, in a flash of genius, discovered the answer.

At some point when I was refactoring the code, I changed the function to get rid of the Value parameter, leaving it as follows:

Public Function GetSomeStringValue() As String
    ... Code Goes here
    Return Some_Multicharacter_String
End Function

However, I neglected to remove the parameter that I was passing in when calling the function:

SomeStringValue = GetSomeStringValue(Value)

The compiler didn’t complain because it interpreted what I was doing as calling the function without brackets, which is a legacy feature from the VB6 days. Then, the Value parameter transformed into the array index of the string (aka character array) that was returned from the function.

So I removed the parameter, and everything worked fine:

SomeStringValue = GetSomeStringValue()

I’m posting this so that other people will recognize the problem when/if they ever encounter it, and are able to solve it much more quickly than I did. It took quite a while for me to solve, and I hope I can save others some time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)