July 06, 2020, 04:09:44 pm
News: If someone gives you assistance give them a Good Star
Pages: [1]   Go Down
Author Topic: Lost Topic Title  (Read 1097 times)
Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4536


Pure Evil Administrator


WWW
« on: April 18, 2006, 12:31:42 pm »

Ok I have a main form called frmMain and on this form there is a ListView Control called lvSystem. I have a second form called frmDefine, and when you click on a button on frmMain frmDefine opens modally and allows you to enter data. Once you click OK frmDefine is suppose to fire a sub located in a separate module that will add the values created in frmDefine to lvSystem on frmMain.

The problem? When ever I attempt to reference frmMain in the sub I'm getting an exception saying that the object wasn't set. When I set the object then nothing happens. The function fires but nothing is changed. I don't understand what am I doing wrong. Here is the code where right now I'm just trying to reference frmMain.


This one does nothing at really doesn't change the form caption at all.
Code:
Module Module1
    Public Sub main()
        Dim frm As frmMain = New frmMain()
        frm.Text = "PASS GEN TEST"
        frm.ShowDialog()
    End Sub
    Public Sub addItems2List(ByVal sUser As String, ByVal iCnt As Integer, ByVal iLen As Integer, ByVal sBegin As String, ByVal sEnd As String, ByVal sDef As String)
        Dim frm As frmMain = New frmMain()
        frm.Text = "YEP THIS WORKS"
    End Sub
End Module

This one gives me this exception
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]An unhandled exception of type 'System.NullReferenceException' occurred in PassGen.exe

Additional information: Object reference not set to an instance of an object.
[/quote]
Code:
Module Module1
    Dim frm As frmMain
    Public Sub main()
        frm = New frmMain()
        frm.Text = "PASS GEN TEST"
        frm.ShowDialog()
    End Sub
    Public Sub addItems2List(ByVal sUser As String, ByVal iCnt As Integer, ByVal iLen As Integer, ByVal sBegin As String, ByVal sEnd As String, ByVal sDef As String)
        frm.Text = "YEP THIS WORKS"
    End Sub
End Module

This one also doesn't do anything. Notice the frm = new frmMain() line in the addItems2List sub.
Code:
Module Module1
    Dim frm As frmMain
    Public Sub main()
        frm = New frmMain()
        frm.Text = "PASS GEN TEST"
        frm.ShowDialog()
    End Sub
    Public Sub addItems2List(ByVal sUser As String, ByVal iCnt As Integer, ByVal iLen As Integer, ByVal sBegin As String, ByVal sEnd As String, ByVal sDef As String)
        frm = New frmMain()
        frm.Text = "YEP THIS WORKS"
    End Sub
End Module

So anyone like to tell me what I'm doing wrong because I can't find it.
« Last Edit: April 18, 2006, 12:32:34 pm by JRSofty » Logged

-- signature --

Chris
Founders
*

Stars: +0/-0
Offline Offline

Posts: 3312


MIA


« Reply #1 on: April 18, 2006, 12:57:01 pm »

 welcome to OO.......

Looks like you're not refering to the instance of frmMain that was created. You need to use the instance cos there's no such thing as default instances anymore (mores the pity).

Passing the frmMain instance reference to the constructor of frmDefine is probably the easiest way.

Off the top of my head...

In frmDefine

Code:
Public Sub New(ByVal theMain As frmMain)
...
parent = theMain
...
End Sub
....
Private theParent as frmMain
....
Public Property parent() as frmMain
    Get
        Return theParent
    End Get
    Set(ByVal Value as frmMain)
        theParent = Value
     End Set
End Property

In frmMain

Code:
Dim frm as New frmDefine(Me)
frm.Show

Something like that. You'd then use parent. to refer to the frmMain instance. Another way is creating a collection of form instances and using that to get the specific instance
« Last Edit: April 18, 2006, 01:00:16 pm by Chris » Logged

When the Bogeyman goes to sleep every night, nothing happens.

Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4536


Pure Evil Administrator


WWW
« Reply #2 on: April 18, 2006, 01:08:19 pm »

Thanks Chris, that explains everything and it seems to work.

Man I guess I'll really have to get some books because I had no idea that this had changed
Logged

-- signature --

Chris
Founders
*

Stars: +0/-0
Offline Offline

Posts: 3312


MIA


« Reply #3 on: April 18, 2006, 01:11:47 pm »

A change for the worse in my humble opinion, but hey
« Last Edit: April 18, 2006, 01:11:55 pm by Chris » Logged

When the Bogeyman goes to sleep every night, nothing happens.

wrack
Master of TMEOotAP
*

Stars: +3/-0
Offline Offline

Posts: 11116


Don't look back. Look in the mirror to look back.


WWW
« Reply #4 on: April 18, 2006, 09:49:07 pm »

Start using C#
Logged

Chris
Founders
*

Stars: +0/-0
Offline Offline

Posts: 3312


MIA


« Reply #5 on: April 18, 2006, 09:50:09 pm »

Same problem  It all compiles into the CLR anyway
« Last Edit: April 18, 2006, 09:51:03 pm by Max Power » Logged

When the Bogeyman goes to sleep every night, nothing happens.

wrack
Master of TMEOotAP
*

Stars: +3/-0
Offline Offline

Posts: 11116


Don't look back. Look in the mirror to look back.


WWW
« Reply #6 on: April 18, 2006, 10:42:00 pm »

True but it makes you use good habits of programming.
Logged

Chris
Founders
*

Stars: +0/-0
Offline Offline

Posts: 3312


MIA


« Reply #7 on: April 18, 2006, 11:17:02 pm »

Well if you wanna learn good habits use Java...or better yet Smalltalk
Logged

When the Bogeyman goes to sleep every night, nothing happens.

Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4536


Pure Evil Administrator


WWW
« Reply #8 on: April 19, 2006, 01:12:20 am »

Quote from: wrack
Start using C#


Besides my company doesn't know if they are going to use C# or Visual C.NET for their upcoming projects.

I'm just doing a little helper tool so VB.NET is fine
Logged

-- signature --

wrack
Master of TMEOotAP
*

Stars: +3/-0
Offline Offline

Posts: 11116


Don't look back. Look in the mirror to look back.


WWW
« Reply #9 on: April 19, 2006, 05:27:46 am »

Quote from: Max Power
Well if you wanna learn good habits use Java...or better yet Smalltalk
Java  Smalltalk :never heard of it:

Quote from: JRSofty
Besides my company doesn't know if they are going to use C# or Visual C.NET for their upcoming projects.
No future plans ehh
Logged

Chris
Founders
*

Stars: +0/-0
Offline Offline

Posts: 3312


MIA


« Reply #10 on: April 19, 2006, 08:20:04 am »

Quote from: wrack
No future plans ehh
Best way to be, no rigid structure
Logged

When the Bogeyman goes to sleep every night, nothing happens.

Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4536


Pure Evil Administrator


WWW
« Reply #11 on: April 19, 2006, 12:02:56 pm »

Well hopefully they'll have it figured out by the time I get back to Germany. This way they can give me the IDE install disk and send me to school so I can learn how to use it.
Logged

-- signature --

wrack
Master of TMEOotAP
*

Stars: +3/-0
Offline Offline

Posts: 11116


Don't look back. Look in the mirror to look back.


WWW
« Reply #12 on: April 19, 2006, 09:42:59 pm »

Sweeeet
Logged

Pages: [1]   Go Up
Print
 
Jump to: