Question Typecasting

franz1280

New member
Joined
Oct 3, 2011
Messages
2
Programming Experience
1-3
I am trying to migrate a source code from BASIC to VB.NET 2010

Dim obj(4096)
Dim strng As String

obj$ = string$ + ".obj" -> Error: Value of type 'String' cannot be converted to '1-dimensional array of Object'

I can get away with this in VB6 but i can't in VB.NET.
I can't convert obj using CStr either. ToString won't work because it work on the left side of an assignment.

Any suggestions how to typecast obj to string or convert obj to string.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,335
Location
Sydney, Australia
Programming Experience
10+
That code doesn't really make sense in VB.NET. You're creating an Object array with 4097 elements and trying to cast or convert that to a String. That doesn't make sense. Instead of showing us code that doesn't work and asking how to make it work, try explaining what you're actually trying to achieve and then we can advise how to go about writing code to achieve it. When I say "what you 're trying to achieve" I don;t mean casting an Object array as type String. That's how you're trying to achieve it, not what you're trying to achieve.
 

franz1280

New member
Joined
Oct 3, 2011
Messages
2
Programming Experience
1-3
I'm trying to assign a string to an object array. I have to use the object array later that's why I only have to typecast it -> Ex Object(I) = 4444.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,335
Location
Sydney, Australia
Programming Experience
10+
You can't assign a String to an Object array. That's like saying that you need to assign a dog to a cat. Do you mean that you need to assign a String to an element of an Object array, or you need to split a String into characters and assign each of them to an element in an Object array, or something else?
 
Top Bottom