Abbas1999
Abbas1999

Reputation: 395

Vb.Net Control Variable Names

I am trying to create bunch of WebBrowsers with Variable Names; I started with the following code, but seems it has something wrong that I cannot figure our; The error is in the FIRST PORTION OF THE CODE;

Any help/comment appreciated:

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim NumberOfBrowsers As Integer = 12
    For Pro As Integer = 1 To NumberOfBrowsers
        Dim frmNew As New Form
        '------------------------- FIRST PORTION:
        Dim MekdamBrowser As New WebBrowser
        MekdamBrowser = "WebBrowser" & Pro
        frmNew.Controls.Add(MekdamBrowser)
        '-------------------------
        MekdamBrowser.Location = New System.Drawing.Point(10, 10)
        MekdamBrowser.Size = New System.Drawing.Size(300, 300)
        MekdamBrowser.Show()
        '-------------------------
    Next
End Sub
End Class

Thanks

Upvotes: 1

Views: 230

Answers (1)

har07
har07

Reputation: 89285

It seems that you want the first portion to be as follow instead :

'------------------------- FIRST PORTION:
Dim MekdamBrowser As New WebBrowser
MekdamBrowser.Name = "WebBrowser" & Pro
frmNew.Controls.Add(MekdamBrowser)
'-------------------------

The difference between this and the original code you tried is, above code assigns name for WebBrowser control, where corresponding line of code in question tried to "replace" WebBrowser control it self with a name (it tried to assign string data to variable of type WebBrowser which is not a valid operation).

Upvotes: 1

Related Questions