Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,
I'm newbie in vb.Net programming and trying write coding to run scripts in vb.net

I Have a Form, which contains ListBox1, TextBox1 And Button1

VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ScriptControl As New MSScriptControl.ScriptControl
        Dim cScript As String = ""

        ListBox1.Items.Add("Sunday")
        ListBox1.Items.Add("Monday")
        cScript = "Msgbox ListBox1.Name" & vbCrLf
        cScript = cScript & "Msgbox ListBox1.Items.Count "
        TextBox1.Text = cScript
        ScriptControl.Language = "VBScript"
        ScriptControl.AddObject("ListBox1", ListBox1, True)
        ScriptControl.ExecuteStatement(TextBox1.Text)
    End Sub


But there is error "Object required: 'ListBox1.Items'" when I click Button1
Please Help me . . .
Thanks.
Posted
Updated 24-Feb-14 0:54am
v2
Comments
Maciej Los 24-Feb-14 16:27pm    
COuld you be more specific and provide more details?
sg.sumaryo 24-Feb-14 21:39pm    
I just simply want to change the coding from vb6 to vb.net that uses MSScriptControl.ScriptControl, but i have a big problem (error "Object required: 'ListBox1.Items'") when I run myscript.
The example to add item to ListBox Object
In vb6 : ListBox1.AddNew "New Item"
In vb.Net : ListBix1.Items.Add("New Item")

please give me suggestions for my script above can running properly.
Thanks
Maciej Los 25-Feb-14 1:37am    
Here you'll find everything about ListBox control. There is an example on the bottom of page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900