Visual Basic 2013 - Form cannot access/modify data from a Module

Asked

Viewed 54 times

2

My problem is this. I have this module that contains a variable of the integer type and this variable is accessed by a form that changes its value, as shown in the code below.

Module Module1
       Public frm1 As New Form1
       Public frm2 As New Form2

       Public Uso As Integer
End Module

Public Class Form1
...
    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
        Uso = 1
        frm2 = New Form2
        frm2.MdiParent = Me
        frm2.Text = "PROJETO DE TROCADOR DE CALOR"
        frm2.Show()
    End Sub
End Class

When compiling it normally opens Form1 (Mdicontainer). When I try to open a new file, MenuItem4_Click, generates an exception. It says that the reference of an object has not been defined for an instance of this object.

This error happens with ALL variables of this Module1 that frm2 tries to access/modify.

I have done other programs using the same logic that never gave this bizarre error. I really need help!!!!

1 answer

1


On the line

frm2 = New Form2

You didn’t declare, you just set the variable frm2 to a new Form2, settle this with Dim. Your code is also very incomplete, put the declaration of variables (all) that were used in this code so we can get a better sense about the error.

  • What happens is that when I need to assign a value to the Use variable it falls into an exception and says that the object reference was not set to an instance of this object. It has nothing to do with the frm2 that has already been declared!!!

  • Reference of an undefined object to an object instance is synonymous with null object, no value, look at its code, use variable New and note that there is no variable referenced.

  • 1

    I did it, Cypher! It worked! I had a wrong reference in the frm2 code and I wouldn’t let it get started! As it is a program made in VB 2003 that was converted to 2013 appeared these bizarre errors of invalid references!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.