|
-
Feb 9th, 2012, 10:29 PM
#1
Thread Starter
New Member
How to convert object array to string array in VB.Net?
Hi there,
I have a problem here for converting object of array to string of array in my VB.Net code. The object of array is quite long and contains 6 sets of data here.
Dim varReturnResult As Object
Dim varMapData As Object
Dim StrMap() As String
varMapData = varReturnResult(2)
StrMap = Split(varMapData, vbLf)
I encountered this error "Conversion from type 'Object()' to type 'String' is not valid." when trying to retrieve the StrMap value.
Appreciate if somebody can help me here.
-
Feb 9th, 2012, 10:44 PM
#2
Re: How to convert object array to string array in VB.Net?
Your code doesn't really make sense. You aren't trying to convert an Object array to a String array. You are calling Split, which takes a single String object and splits it into a String array. You are passing it your 'varMapData' variable. That variable apparently refers to an Object array, not a String. How exactly are you expecting an Object array to be split on line breaks at all? Your question like saying that you have a pumpkin and you want to drive to town so how do you convert it to a car. The answer is that you don't. It's just not the right type of thing.
Let's start at the beginning. You have a 'varReturnResult' variable and it is declared as type Object. You are apparently treating it as an array so why is it not declared as an array? Similarly for 'varMapData', i.e. why is it declared simply as Object when it is apparently an array? You should be declaring all your variables as the appropriate type for the objects that they will refer to. Where does this data come from in the first place and what does it look like?
-
Feb 10th, 2012, 12:39 AM
#3
Thread Starter
New Member
Re: How to convert object array to string array in VB.Net?
Thanks for your advise...I've changed the declaration from object to array now. The data came from a server and I have to retrieve them out, trim out the unnecessary vbLF and finally arrange it back to a flat file line by line. Do you have a better way to do this?
-
Feb 10th, 2012, 03:44 AM
#4
Re: How to convert object array to string array in VB.Net?
That's all still a bit vague I'm afraid. You say that you have to remove line feeds and then write back to a file line by line, but that's just putting line feeds back in again. Also, we still don't really know what those first two variables contain or how it gets there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|