469,270 Members | 1,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

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


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 ?
Nov 21 '05 #1
6 37529
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.
"baret bonden" <ar****@networks-cc.com> wrote in message
news:2v*************@uni-berlin.de...

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 ?

Nov 21 '05 #2

Użytkownik "baret bonden" <ar****@networks-cc.com> napisał w wiadomo¶ci
news:2v*************@uni-berlin.de...

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
Nov 21 '05 #3
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

"baret bonden" <ar****@networks-cc.com>

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 ?

Nov 21 '05 #4
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

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u0*************@TK2MSFTNGP11.phx.gbl...
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

"baret bonden" <ar****@networks-cc.com>

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 ?


Nov 21 '05 #5
Scott,

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

Cor

"Scott M." <s-***@nospam.nospam>
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

"Cor Ligthert" <no************@planet.nl> wrote in message
news:u0*************@TK2MSFTNGP11.phx.gbl...
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

"baret bonden" <ar****@networks-cc.com>

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 ?



Nov 21 '05 #6
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.
"baret bonden" <ar****@networks-cc.com> wrote in message
news:2v*************@uni-berlin.de...

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 ?

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Francois Grieu | last post: by
11 posts views Thread by tshad | last post: by
2 posts views Thread by Jim in Arizona | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.