Results 1 to 5 of 5

Thread: Trying to make a second form work

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    13

    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:
    1. Public Class Form2
    2.     Inherits System.Windows.Forms.Form
    3. #Region " Windows Form Designer generated code "
    4. #End Region
    5.     Public BookNumberLow As Integer
    6.     Public BookNumberHigh As Integer
    7.     Public GetKeyStatus As Boolean
    8.     Public Sub main()
    9.     End Sub
    10.     Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click
    11.         BookNumberLow = Int(BookNumberLowBox.Text)
    12.         BookNumberHigh = Int(BookNumberHighBox.Text)
    13.         If BookNumberLow > BookNumberHigh Then
    14.             MessageBox.Show("Starting Book Number must not be greater than Ending Book Number", "Error", MessageBoxButtons.OK)
    15.         Else
    16.             GetKeyStatus = True
    17.         End If
    18.     End Sub
    19.  
    20.     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    21.         GetKeyStatus = False
    22.     End Sub
    23.     Public Property Status() As Boolean
    24.         Get
    25.             Return GetKeyStatus
    26.         End Get
    27.         Set(ByVal Value As Boolean)
    28.             GetKeyStatus = Value
    29.         End Set
    30.     End Property
    31.     Public Property Hi() As Integer
    32.         Get
    33.             Return BookNumberHighBox.Text
    34.         End Get
    35.         Set(ByVal Value As Integer)
    36.             BookNumberHighBox.Text = Value
    37.         End Set
    38.     End Property
    39.     Public Property Low() As Integer
    40.         Get
    41.             Return BookNumberLowBox.Text
    42.         End Get
    43.         Set(ByVal Value As Integer)
    44.             BookNumberLowBox.Text = Value
    45.         End Set
    46.     End Property
    47. End Class

    in form1

    VB Code:
    1. Private Sub MenuItem21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem21.Click
    2.         Dim GetKeys As New Form2
    3.         GetKeys.ShowDialog(Me)
    4. '
    5. 'Code to get the key pressed in form2 and the low and high keys
    6. '
    7.         Call PrintByTitle()
    8.     End Sub

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Trying to make a second form work

    Quote 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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    13

    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?

  5. #5
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    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
  •  



Click Here to Expand Forum to Full Width