CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2014
    Posts
    3

    How to receive VBScript dictionary object and verify the data in C# Windows applicati

    Hello Friends,

    I am new to C# and would like to know is there any way to execute the VBScript function which return Dictionary object and want to receive the data into C# application.

    Here is the my code and getting the error "Connot implicitly convert type 'object' to System.Collections.Generic.Dictionary<string, string>. An explicit conversion exists(are you missing a cast?)"

    private void QCloginOK_Click(object sender, EventArgs e)
    {
    MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
    sc.Language = "VBScript";
    sc.AddCode(@"Function test
    Set d = CreateObject (""Scripting.Dictionary"")
    d (""Firstvalue"") = ""hello""
    test = d
    End Function");
    object[] myParams = {};

    Dictionary<string, string> sD = sc.Run("test", ref myParams);

    }

    Here I am using Microsoft Script control to execute VBScript functions.

    Please can anyone guide me on this.

    Thanks,
    SG

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to receive VBScript dictionary object and verify the data in C# Windows appli

    This used to work with VB6:
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Private Const SW_SHOWNORMAL As Long = 1
    Private Const SW_HIDE As Long = 0
    
    Private Sub command1_Click()
    
    ShellExecute Me.hwnd, "Open", "C:\temp\capicom.vbs", vbNullString, "C:\vb\vb\", SW_SHOWNORMAL
    
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2014
    Posts
    3

    Re: How to receive VBScript dictionary object and verify the data in C# Windows appli

    Thanks for your reply David

    I can able to execute the VBScript functions using Microsoft Script Control in C# and if the return value is String then I can able to receive into C# code after execution, the problem is if it is dictionary object then I am getting the error at compilation itself. In my requirements we are giving an option to users to write there own code in VBScript and that will execute as an plug-ins and will display in my application as one of the tab. In plug-ins thy will write a code in vbscript and finally the code will collect the details and returns as a dictionary. So I would like to receive and handle it in C#.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to receive VBScript dictionary object and verify the data in C# Windows appli

    that's a very bad idea. read up on SQL INJECTION for the same problem re-defined
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Feb 2014
    Posts
    3

    Re: How to receive VBScript dictionary object and verify the data in C# Windows appli

    Hi David,

    Yes. You are correct. But here let me explain the situation of this project, actually I should not call as a project, it should call as a automation framework. Right now we have developed it completely in VBScripting. Now my team, managers and director made a decision to re-write the code in C# (only the framework). The framework will not be change for all the projects and each project may have a plug-in (this one particularly related to the projtoect) and those things we want to keep in VBScript (indivedual automation developers will develop this script and all of them are pertty much develop the script in vbscripting) and we don't want to change the existing plug-ins and these code will not be accessed by any regular users. So for now we are collecting all the details to re-write the things in c#.

    Please can you help me if you know how to receive and access the data in c#.

    And one more thing the VBScript code will in files and I will read and exetute using the Microsoft Script control.

    Thanks,
    SG

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to receive VBScript dictionary object and verify the data in C# Windows appli

    I'd switch everyone to POWERSHELL. That can be regulated a little easier than VBScript. Users can commit the changes, get them approved/accepted and then permitted to distribute to everyone.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured