Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

executing vbscript functions from a C# winform app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kasper - 10 Feb 2008 23:05 GMT
Hi Group.

I have an old VB6 application which loads a number of gui controls
from an inifile and for each control the inifile states the name of
the vbscript that should be executed once the control is clicked or
otherwise triggered.
My question is whether it is possible to execute the vb scripts from
C#? There are multiple scripts in the same file.

If that is not possible I sure would like a hint about how I create a
winforms app where the eventhandler is defined at runtime, not
compiletime.

TIA

Kasper
Marc Gravell - 10 Feb 2008 23:32 GMT
Well, the simplest way is to store something useful in the tag, and
simply have a shared handler, i.e.

private void foo_Clicked(object sender, EventArgs args) {
 Control cont = sender as Control;
 if(cont!= null) {
   // do something with cont.Tag
 }
}

Then when looping:

foreach(whatever) {
 SomeControl foo = new SomeControl();
 // init
 foo.Tag = {something useful}; // could also use Name I suppose
 foo.Clicked += foo_Clicked;
}

Depending on needs, you can do things a lot more sophisticated.

Marc
Marc Gravell - 10 Feb 2008 23:33 GMT
(you'll also need to add each "foo" onto the form somewhere ;-p)

Marc
Cor Ligthert[MVP] - 11 Feb 2008 00:54 GMT
Kasper,

Would it not better to make this really good. As this is your design, then
in my opinion is using C# withouth sense. I would find then VB6 (If I knew
that program languqage good)  probably a better option.

However, it would be in VB6 then probably as unsafe as it would be in C#.

Cor
Nicholas Paldino [.NET/C# MVP] - 11 Feb 2008 01:05 GMT
Kasper,

   I think that the best option here is to refactor the VB6 app so that the
UI is contained in hostable ActiveX controls and then host those controls in
your C# app, and let the VB6 code that is being interoped with handle the
script (as you were before).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi Group.
>
[quoted text clipped - 12 lines]
>
> Kasper

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.