|
-
Feb 1st, 2005, 10:59 AM
#1
Thread Starter
New Member
Trying to make a second form work
I have an VB .NET application in which I need to collect some range data prior to searching a database for a report. I have tried the examples given in this forum, to no avail. What I cannot seem to get straight is how to get the data and key-press data from the second form back to the first.
When the user presses a menu button I want to show a small form(form2) whereiin the user enters the search keys, then presses an "Ok" button. When the Ok button is pressed I want the key data available to the application(form1) and the form2 to disappear. The user will also be able to press a "cancel" button on form2 wherein the application(form1) will be able to so note.
I've looked here and elsewhere and tried dozens of approaches, all have failed on one way or another. In the code below I've stripped my attempts and left the basic code in hopes someone can help in what should be a simple problem. I will surely appreciate any help offered.
Here is what i've done...
Created Form2 with two text boxes and two buttons. I'd put the graphics here but I don't know how.
In form2
VB Code:
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
#End Region
Public BookNumberLow As Integer
Public BookNumberHigh As Integer
Public GetKeyStatus As Boolean
Public Sub main()
End Sub
Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click
BookNumberLow = Int(BookNumberLowBox.Text)
BookNumberHigh = Int(BookNumberHighBox.Text)
If BookNumberLow > BookNumberHigh Then
MessageBox.Show("Starting Book Number must not be greater than Ending Book Number", "Error", MessageBoxButtons.OK)
Else
GetKeyStatus = True
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
GetKeyStatus = False
End Sub
Public Property Status() As Boolean
Get
Return GetKeyStatus
End Get
Set(ByVal Value As Boolean)
GetKeyStatus = Value
End Set
End Property
Public Property Hi() As Integer
Get
Return BookNumberHighBox.Text
End Get
Set(ByVal Value As Integer)
BookNumberHighBox.Text = Value
End Set
End Property
Public Property Low() As Integer
Get
Return BookNumberLowBox.Text
End Get
Set(ByVal Value As Integer)
BookNumberLowBox.Text = Value
End Set
End Property
End Class
in form1
VB Code:
Private Sub MenuItem21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem21.Click
Dim GetKeys As New Form2
GetKeys.ShowDialog(Me)
'
'Code to get the key pressed in form2 and the low and high keys
'
Call PrintByTitle()
End Sub
-
Feb 1st, 2005, 12:10 PM
#2
Frenzied Member
Re: Trying to make a second form work
I create a new module called Globals.vb and put all my global (public) variables here:
Module Globals
'All Globals Go Here
'==================================
Public gs_IniString As String = "My Global String"
End Module
Now I can access these variables from any Form or class or module.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Feb 1st, 2005, 12:28 PM
#3
PowerPoster
Re: Trying to make a second form work
 Originally Posted by Webtest
I create a new module called Globals.vb and put all my global (public) variables here:
Module Globals
'All Globals Go Here
'==================================
Public gs_IniString As String = "My Global String"
End Module
Now I can access these variables from any Form or class or module.
If you declare them Public in any form which is also declared Public, you should be able to access them.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 1st, 2005, 01:30 PM
#4
Thread Starter
New Member
Re: Trying to make a second form work
I activate or show the seconf form(form2). The Go key click works. Now, how do I get back to the first form?
-
Feb 1st, 2005, 04:46 PM
#5
Frenzied Member
Re: Trying to make a second form work
Close the 2nd form or "Set Focus" on the first form?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|