True or False?  
Author Message
Whoisit





PostPosted: Visual Basic General, True or False? Top

In my project I have a Module with the following code

Module modPGS
Public Create As Boolean
End Module

In Form One
I have two events one that sets Create = True and one that sets Create = False
after setting Create, Form Two opens and an event checks for the state of Create
but Create is always False why is this



Visual Basic6  
 
 
Ken Tucker





PostPosted: Visual Basic General, True or False? Top

What is the event that sets create = false

 
 
Whoisit





PostPosted: Visual Basic General, True or False? Top

Here is the code that sets Create to False

Private Sub
tlstLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlstLoad.Click
Create = False
PassCreate.btnPassCreate.Text = "Enter User Name and Password"
PassCreate.Show()
End Sub

Here is the code that sets Create to True

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
Create = True
PassCreate.btnPassCreate.Text = "Create Account"
PassCreate.Show()
End Sub

 
 
Ken Tucker





PostPosted: Visual Basic General, True or False? Top

I really dont see why this is not working. Two things to try make the module Public. The other is to make sure there is not a create a variable named create in the procedure you are checking create in. A form level create will also be used before the modules create.

 
 
nobugz





PostPosted: Visual Basic General, True or False? Top

Such is the problem with global variables. To make it debuggable and pretty, add this code to the PassCreate form:

Private mCreate As Boolean
Public Property Create() As Boolean
Get
Return mCreate
End Get
Set(ByVal value As Boolean)
mCreate = value
If value Then
btnPassCreate.Text = "Create account"
Else
btnPassCreate.Text = "Enter user name and password"
End If
End Set
End Property

Now change the calling code to:

Private Sub tlstLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlstLoad.Click
PassCreate.Create = False
PassCreate.Show()
End Sub

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
PassCreate.Create = True
PassCreate.Show()
End Sub

If that doesn't fix the problem immediately, you can now set a breakpoint on the Create.Set code.



 
 
Whoisit





PostPosted: Visual Basic General, True or False? Top

Thanks to all for the help and advice in this thread, after reading them I went back to look at my code and it was in the code that I found the answer to the problem.
In Form One I had
Dim Create as Boolean

When this did not work I shut down and had a break, I then went back and decided to try using a Module with
Dim Create as Boolean

Still not working, I posted the problem on the forum. After reading the post I checked my code again and noticed that I had not removed
Dim Create as Boolean
from Form One, once I did this the code worked as it should.

NoBugz I have copied your code to keep for future reference.

Thanks again to all.