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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting from VB6 to VB.net

Status
Not open for further replies.

Viruland

Programmer
Dec 6, 2000
61
BE
I'm new to the VB.net programming and I'm trying to convert the following piece of code:

Private Sub Command1_Click()

Dim blnFind As Boolean
Dim objForm As Form
Dim myForm As Form2

blnFind = False

For Each objForm In Forms
If objForm.Name = "Form2" Then
blnFind = True
Set myForm = objForm
End If
Next objForm

If blnFind = False Then
Set myForm = New Form2
myForm.Show
myForm.Caption = strTitle
Else
myForm.WindowState = vbNormal
myForm.SetFocus
End If

End Sub

I've tried several ways but I don't find a solution to it.
The VB.net upgrade wizard gives a failure to this type of update.

Live fast, die young and leave a beautiful corpse behind.
 
I'm afraid that this code can't be converted directly as there is no Forms collection in VB.NET.

If you want to do this sort of thing you will have to create your own Forms collection in your initial startup object. Then each time you create an instance of a Form you will need to add it to the collection and of course remove it when it is closed.

It's not at all clear to me what this code is trying to achieve and it may well be that are simpler methods available to you. For example if you assign a global variable for each form that you create then simply checking if that variable is not set to nothing will indicate that the Form has been instantiated.

For example: (not real code but shows the principle in VB.NET code)

Code:
Public gForm1 as Form1, gForm2 as Form2, gForm3 as Form3
.
.
.

Private Sub Command1_Click(Sender as object,...)
    If gForm2 is Nothing then
        gForm2 = New Form2()
        gForm2.Show()
        gForm2.Text = strTitle
    Else
        gForm2.WindowState = FormWindowState.Normal
        gForm2.Focus()
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top