|
-
Jan 25th, 2011, 07:47 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Object Problem - Simple to fix, am I missing something?
Hi guys , I have this code where an object is made and it needs to be filled with other objects depending on a string value.
The code is:
Code:
Dim o As Object = Activator.CreateInstance(LoadedType)
Dim oo As Object() = New Object() {}
For pI As Integer = 0 To strParamTypes.Split(",").Length - 1
Dim strParam As String = strParamTypes.Split(",")(pI)
Select Case strParam.ToLower
Case "s"
oo(pI) = Convert.ToString(strParams.Split(",")(pI))
Case "i"
oo(pI) = Convert.ToInt32(strParams.Split(",")(pI))
Case "f"
oo(pI) = Convert.ToDecimal(strParams.Split(",")(pI))
Case "b"
oo(pI) = Convert.ToBoolean(strParams.Split(",")(pI))
End Select
Next
retStr = Convert.ToString(LoadedMethod.Invoke(o, oo))
An example of strParamTypes: "I,I" (To tell the program that both need to be converted to integers for the oo object.)
An example of strParams: "1,5"
The type 'LoadedType' and the method 'LoadedMethod' are loaded perfectly with no problems whatsoever.
The idea of the above code is that it invokes the fucntion in another DLL giving the required parameters as specified in the strings, seperated with commas and it should then return the value given back by the function.
For some reason I either get an error saying "Object reference not set to and isntance of an object" or one saying the "Index is out of bounds".
I've narrowed the object error down to the oo object not being filled properly and I presume the "index out of bounds" error is something to do wwith the string splitting, but I can't work out what the solution to any of the problems is.
I've been working at this for a good few hours now and it's probably something simple I keep missing but if any of you can help then I'd appreciate it 
Thanks in advance, knxrb.
Last edited by knxrb; Jan 25th, 2011 at 08:10 PM.
Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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
|