Value of type 'String' cannot be converted to '1-dimensional array of String'.

B

baret bonden

I get :Value of type 'String' cannot be converted to '1-dimensional array
of String' refering to curitem

Dim curItem As String

curItem = ListBox1.SelectedItem

TextBox1.Text = curItem

vcar = curItem



I had set up vcar above as in :



Friend vcar() As String

I freely admit to not knowing what I'm doing here; all my 20 yearsof
programming is seemingly worthless ....just trying to pass a variable from
one form to another and found myself with that error, which makes no sense
to me at all ...they are both strings, No ?
 
S

Scott M.

When you declared vcar, you wrote it as: Friend vcar() As String when you
should have written: Friend vcar As String.

The difference is that parenthesis, which indicate that you want vcar to be
a String array (more than one value and therefore needing an index when
assigning values). So, when you wrote: vcar = curItem, you were, in
effect, saying "take this one text value from this textbox and make it be
the value of an array object".

Just take away the () on the vcar definition and you'll be all set.
 
M

Maciej Januchowski

U¿ytkownik "baret bonden said:
I get :Value of type 'String' cannot be converted to '1-dimensional array
of String' refering to curitem

Dim curItem As String

curItem = ListBox1.SelectedItem

TextBox1.Text = curItem

vcar = curItem



I had set up vcar above as in :



Friend vcar() As String

I freely admit to not knowing what I'm doing here; all my 20 yearsof
programming is seemingly worthless ....just trying to pass a variable from
one form to another and found myself with that error, which makes no sense
to me at all ...they are both strings, No ?

vcar is an array of strings, so you have two options depending on what you
are trying to achieve:

1. Pass your string to the first element of vcar array:

Friend vcar(10) As String
vcar(0) = curItem

2. If you want an array where every element contains one char you should use
char array:

Dim vcar() As Char
vcar = curItem.ToCharArray

Hope that helps,
Maciek
 
C

Cor Ligthert

Baret,

In addition to the others.

For some (probably compatible) reasons has Microsoft standard set Option
Strict and Option explicit to Off. As far as I know have all Regulars from
this newsgroup this set to On.

Either in the options as I do or every time in top of the files.

When you set those to On you will be warned for errors at runtime.

It can be harder because with you have to set yourself more.

You can compare it like this.

Behaviour en performance of VBNet
With option Strict On = C#
With option Strict Off = VB6

I hope this helps?

Cor
 
S

Scott M.

Cor,

The default setting for Option Explicit in VB.NET is ON. Option Strict is,
by default, turned OFF.

You are right though, that it is best to have them both ON.

-Scott
 
C

Cor Ligthert

Scott,

Thanks for correcting me. As I wrote I have set them on in the options so I
could not check that.

Cor
 
B

baret bonden

So far the only easy and pleasing thing about learning (trying to learn) VB
Net has been the kind support from this group. Many thanks.
 

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

Top