nondoo
nondoo

Reputation: 641

An error occurred creating the form

I just don't understand where I went wrong in my code. I have identified the line where error is but I don't know how to correct it or else what causes it. please help, any suggestions would be most welcome. Here is where the problem lies: Just along line 2 of code

Public Class Form2
Dim ThirdForm As New Form3
Dim Randomize()

Dim check As Integer = 0

Upvotes: 0

Views: 864

Answers (1)

Steve
Steve

Reputation: 216293

Dim is the keyword to use when you want to declare a variable, not when you want to call a function Randomize() is a function that initializes the random-number generator and you cannot call it outside any method of your class

Public Class Form2
    Dim ThirdForm As New Form3 ' Declare and initialize the variable ThirdForm
    Dim check As Integer = 0   ' Declare and initialize the variable check

    ' Inside a form constructor....
    Public Sub New()
        Randomize() ' Call the function that initializes the random-number generator
    End Sub

    Public Sub Form_Load(sender as Object, e As EventArgs) Handles MyBase.Load
        ' In alternative you call it inside the Form_Load event.
        ' Randomize() ' Call the function that initializes the random-number generator

    End Sub

Upvotes: 2

Related Questions