473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

StringToObject

Hi guys,

hope someone can help me out here.

Got two dll's

dll1 and dll2

this one works

dim myObj as dll1
dim myObj2 as dll2
dim iInt as integer

iInt = dll1.somefunction

Ok now what I want

dim sString as string="dll1"

dim myObj as sString <------ No good

How do I get this to work?


Nov 21 '05 #1
8 949
Hi Albert
Sure this can't be done
You are using the Dim key word and the As keyword , the complier expects
to find a type after the word as . what you are presenting is a variable .
of course , no compiler in the world would take this variable , figure its
value and then try to see if it match a type that we have ???? imagine you
are saying
dim K as String="interger"
Dim myint as K ' of course the complier will never understand that you want
to declare in it .
Whoever, if your logic require declaring a variable of a type that is not
defined until run time , I am sure there are many ways to achieve that , a
simple solution for example declare as many variables of all the possible
types and then use that one that you will want.
Hope that was clear

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2
Mohamed,

I know this can't be done this way, that's why I posted my question ;-)
You tell me declaring a variable of a type that is not defined until runtime
can be done in many ways. Well I can't seem to find any.
Declaring all the variables that may or may not be used, is not an option.

Can someone else maybe shed some light on this issue?

Thanks,

Albert

"Mohamoss" <mo************@egdsc.microsoft.com> schreef in bericht
news:qu**************@cpmsftngxa10.phx.gbl...
Hi Albert
Sure this can't be done
You are using the Dim key word and the As keyword , the complier expects
to find a type after the word as . what you are presenting is a variable .
of course , no compiler in the world would take this variable , figure its
value and then try to see if it match a type that we have ???? imagine you
are saying
dim K as String="interger"
Dim myint as K ' of course the complier will never understand that you want to declare in it .
Whoever, if your logic require declaring a variable of a type that is not
defined until run time , I am sure there are many ways to achieve that , a
simple solution for example declare as many variables of all the possible
types and then use that one that you will want.
Hope that was clear

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #3
Albert,

After reading this 10 times I did not understand what you want and could
only give an answer as Mohamoss did.

dim sString as string="dll1"
dim myObj as sString <------ No good

You told how it works and this does not work, that is true, as Mohamoss
said.

And?

Cor
Nov 21 '05 #4
Cor,

ok might be a bad example.
Imagine a project
I've got two dll's referenced, dll1 and dll2

within some function of my project i want to use a function out of dll1/dll2
Normally you then would put in the function:

Function fncSomeProjFunc as int

dim myobj as dll1 (Make the functions of dll1 available inside this
function)
dim myobj2 as dll2

dim sResult as string
dim sResult2 as string

sResult = myobj.SomeFunctionwithsResultAsReturnValue
sResult2 = myobj2.SomeFunctionwithsResultAsReturnValue

return 1
end function

this is what Mohammed suggested, agree?

Now what i want is this

Function fncSomeProjFunc(byval sDllToCall as String) as int
..
...
....
.....

end function

sDllToCall is either "dll1" or "dll2" being the NAME of the object that I
have to declare.
How can I use sDllToCall to declare an object?

If you for example look at it the other way around,

dim myobj as dll1

msgbox (myobj.toString) would give "dll1"
so maybe there is some function like myobj=sdlltocall.StringToObject or
something like this?

I don't know how to explain it more clearly.



"Cor Ligthert" <no**********@planet.nl> schreef in bericht
news:%2******************@tk2msftngp13.phx.gbl...
Albert,

After reading this 10 times I did not understand what you want and could
only give an answer as Mohamoss did.

dim sString as string="dll1"
dim myObj as sString <------ No good

You told how it works and this does not work, that is true, as Mohamoss
said.

And?

Cor

Nov 21 '05 #5
* "Albert" <al****@informant.nl> scripsit:
[...]


Please avoid multiposts.

\\\
Private Function CreateClassByName( _
ByVal PartialAssemblyName As String, _
ByVal QualifiedClassName As String _
) As Object
Return _
Activator.CreateInstance( _
[Assembly].LoadWithPartialName( _
PartialAssemblyName _
).GetType(QualifiedClassName) _
)
End Function
///

Usage:

\\\
Dim c As Control = _
DirectCast( _
CreateClassByName( _
"System.Windows.Forms", _
"System.Windows.Forms.Button" _
), _
Control _
)
With c
.Location = New Point(10, 10)
.Size = New Size(80, 26)
.Text = "Hello World"
End With
Me.Controls.Add(c)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Hi Albert,

I was busy with it however I see you got an answer from Herfried,

Cor

ok might be a bad example.
Imagine a project
I've got two dll's referenced, dll1 and dll2

within some function of my project i want to use a function out of dll1/dll2 Normally you then would put in the function:

Function fncSomeProjFunc as int

dim myobj as dll1 (Make the functions of dll1 available inside this
function)
dim myobj2 as dll2

dim sResult as string
dim sResult2 as string

sResult = myobj.SomeFunctionwithsResultAsReturnValue
sResult2 = myobj2.SomeFunctionwithsResultAsReturnValue

return 1
end function

this is what Mohammed suggested, agree?

Now what i want is this

Function fncSomeProjFunc(byval sDllToCall as String) as int
.
..
...
....

end function

sDllToCall is either "dll1" or "dll2" being the NAME of the object that I
have to declare.
How can I use sDllToCall to declare an object?

If you for example look at it the other way around,

dim myobj as dll1

msgbox (myobj.toString) would give "dll1"
so maybe there is some function like myobj=sdlltocall.StringToObject or
something like this?

I don't know how to explain it more clearly.



"Cor Ligthert" <no**********@planet.nl> schreef in bericht
news:%2******************@tk2msftngp13.phx.gbl...
Albert,

After reading this 10 times I did not understand what you want and could
only give an answer as Mohamoss did.

dim sString as string="dll1"
dim myObj as sString <------ No good

You told how it works and this does not work, that is true, as Mohamoss
said.

And?

Cor


Nov 21 '05 #7
Thanks Cor

"Cor Ligthert" <no**********@planet.nl> schreef in bericht
news:OG**************@TK2MSFTNGP11.phx.gbl...
Hi Albert,

I was busy with it however I see you got an answer from Herfried,

Cor

ok might be a bad example.
Imagine a project
I've got two dll's referenced, dll1 and dll2

within some function of my project i want to use a function out of

dll1/dll2
Normally you then would put in the function:

Function fncSomeProjFunc as int

dim myobj as dll1 (Make the functions of dll1 available inside this
function)
dim myobj2 as dll2

dim sResult as string
dim sResult2 as string

sResult = myobj.SomeFunctionwithsResultAsReturnValue
sResult2 = myobj2.SomeFunctionwithsResultAsReturnValue

return 1
end function

this is what Mohammed suggested, agree?

Now what i want is this

Function fncSomeProjFunc(byval sDllToCall as String) as int
.
..
...
....

end function

sDllToCall is either "dll1" or "dll2" being the NAME of the object that I have to declare.
How can I use sDllToCall to declare an object?

If you for example look at it the other way around,

dim myobj as dll1

msgbox (myobj.toString) would give "dll1"
so maybe there is some function like myobj=sdlltocall.StringToObject or
something like this?

I don't know how to explain it more clearly.



"Cor Ligthert" <no**********@planet.nl> schreef in bericht
news:%2******************@tk2msftngp13.phx.gbl...
Albert,

After reading this 10 times I did not understand what you want and could only give an answer as Mohamoss did.

dim sString as string="dll1"
dim myObj as sString <------ No good

You told how it works and this does not work, that is true, as Mohamoss said.

And?

Cor



Nov 21 '05 #8
"Albert" <al****@informant.nl> wrote in message news:<ch**********@reader10.wxs.nl>...
Mohamed,

I know this can't be done this way, that's why I posted my question ;-)
You tell me declaring a variable of a type that is not defined until runtime
can be done in many ways. Well I can't seem to find any.
Declaring all the variables that may or may not be used, is not an option.

Can someone else maybe shed some light on this issue?

Thanks,

Albert

"Mohamoss" <mo************@egdsc.microsoft.com> schreef in bericht
news:qu**************@cpmsftngxa10.phx.gbl...
Hi Albert
Sure this can't be done
You are using the Dim key word and the As keyword , the complier expects
to find a type after the word as . what you are presenting is a variable .
of course , no compiler in the world would take this variable , figure its
value and then try to see if it match a type that we have ???? imagine you
are saying
dim K as String="interger"
Dim myint as K ' of course the complier will never understand that you

want
to declare in it .
Whoever, if your logic require declaring a variable of a type that is not
defined until run time , I am sure there are many ways to achieve that , a
simple solution for example declare as many variables of all the possible
types and then use that one that you will want.
Hope that was clear

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

I have a vague feeling that your answer will involve delegates, even
if they don't solve your problem as stated.
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Solel Software | last post by:
Hello, I am attempting to serialize an object for storage in a DB field and them deserialize it later on. I have managed to Serialize it using private string SerializeObject(object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.