How to set module instance varaible to nothing for another Form?

  • Thread starter Thread starter Shane Saunders
  • Start date Start date
S

Shane Saunders

I have a menu option that loads a form and displays infomation. if you go to
main form and try to load something else from that same menu, it does a
check to see if the form in exist and then reloads it has to or does
messagebox. the problem i have is that i want to set the module instance
varible to nothing when i exit the form that is being check.


The code i am use is

If frmWeatherMap Is Nothing Then
objWeatherMaps.WeatherMap = strMapLoc
frmWeatherMap = New frmWeatherMap()
frmWeatherMap.Show()
Else
MessageBox.Show("There is a Instance of Weather Maps already Runing" &
ControlChars.CrLf _
& "To see another map, Please use the Weather Map Menu in Weather Map
Window.", "Weather Map Instance Warning", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
 
Hi Shane,

Why do you want to set the form to nothing, that is normaly never done in
vb.net, it is hided, closed or with a dialogform disposed?

Cor
 
if i dont set it to nothing, when try to load the same form again, it tell
me that it already exist and it really does not. when the main form loads it
makes a form obj and does not release until the program closes. i wanted to
take the variable (dim frmMyform as frmMyForm) and set it nothing. the only
way i was think i could do that is to do showdialog, but i dont want to do
that. So wanted to set the frmMyForm to nothing, but i dont know how to do
that? i could do in the sub, then i should just not have the check there in
the first place.

Shane
 
Hi Shane,

Did you close it, that is the normal way to archieve what you describe it in
my opinion.

And than you can create it new. However show what code, probably than it is
easier to help you.


Cor
 
Cor,

Here is the code i am using.. this to check for the form

Dim strMapLoc As String
Private frmWeatherMap As frmWeatherMap < ------this what i want to set to
nothing on exit of the form

Private Sub MapCheck()
Dim objWeatherMaps As CWeatherMaps
objWeatherMaps = New CWeatherMaps()

Try

' Check to see if there is version already in memory, if not loads new one
or prompts the user that one exist already
If frmWeatherMap Is Nothing Then
objWeatherMaps.WeatherMap = strMapLoc
frmWeatherMap = New frmWeatherMap()
frmWeatherMap.Show()
Else
MessageBox.Show("There is a Instance of Weather Maps already Runing"
& ControlChars.CrLf _
& "To see another map, Please use the Weather Map Menu in Weather
Map Window.", "Weather Map Instance Warning", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
Catch exc As Exception
MessageBox.Show(exc.Message, "Error Message", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Exit Sub
End Try
End Sub

i want know how to do this.

Private Sub frmWeatherMap_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
frmweathermap = nothing

End Sub


But this has to be the one on main form that i am setting to nothing
 
Hi Shane,

I never did it this way, however I think that this needs much your needs

You can try it,

I hope this helps?

Cor


\\\
Private frm As Form2
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If frm Is Nothing Then
frm = New Form2
frm.Show()
Else
If Not frm.Visible Then
frm.Show()
End If
End If
End Sub
///
\\\
Private Sub Form2_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Me.Hide()
End Sub
///
 
Cor,
I Thank you for you help. I though of a better way to do it. I ended up
using boolean logic to to show if the form existed or not, and it works
just like i wanted it to.

Shane
 
Back
Top