Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute contents of string variable as code ?

Status
Not open for further replies.

blink416

Technical User
Mar 22, 2005
20
GB
The title basically describes the problem, a specific example here :

Code:
Dim ResPath As String
Dim Stim1Physical As String

Sub AssignCustomImageToPictureBox()

ResPath = "IntegratedFeaturesConnectedTemplate.My.Resources.Resources._"
Stim1Physical = "BeautifulCode" 'refers to a picture in VS Project Resources with the name BeautifulCode
PictureBoxRight.Image = ResPath & Stim1Physical

End Sub

This gives me the following error, however : "Value of type 'String' cannot be converted to 'System.Drawing.Image'." i.e. I need to indicate to Visual Basic to read the contents of ResPath & Stim1Physical as code rather than treat them as String variables ... Any help most appreciated !

p.s. tried to search for a solution and hits returned things like EbExecuteLine, Activator.CreateInstance, Application.Run "MyFunction", "myParameter" but im either not sure how to use them or they are not really suitable here ...
p.p.s. I'm using VB.NET 2005
 
Try the code bellow,

Code:
Imports Microsoft.VisualBasic

...

Dim Img as Drawing.Image = _
CallByName(ClassWithImage,"BeautifulCode",CallType.Get)

CallByName(IntegratedFeaturesConnectedTemplate, "My.Resources.Resources.Stim1Physical",CallType.Set,Img)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top