CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Guest

    Making an input box appear only once.

    I would like an Input Box to appear when I move from my Form1 to my Form2, but when the relevant information has been entered I do not want the same input box to appear each time I move from Form1 to Form2. How can this be prevented?


  2. #2

    Re: Making an input box appear only once.

    One way to do this is to declare a global variable called, GotData as boolean. When your program loads, set this variable to false. When the inputbox is called and data is successfully entered, set GotData to true. Now in the place of you input statement have an additional conditional statement like this...

    if GotData = false then
    data = inputbox("you know")
    GotData = true
    end if


    FaRd0wN


  3. #3
    Guest

    Re: Making an input box appear only once.

    Thanks for your help - I have added your suggested code and understand how it will work. Unfortunately , as I have just begun to code in VB it has kicked up another problem - I do not fully understand how to declare Public variables! My book tells me that you cannot declare Public variables within a proceedure? All my other variables so far have been Dim declarations, but the code will not work with one of these.

    Would it be possible to help me understand how to set up the Public variable so that your code will work? The book I am using to help me has an example, but it is relevant to a procedure working on a mathematical problem and therefore passes integers between the two proceedures - this all makes sence, but it is not quite what I am trying to do and is just confusing me.

    Thanks again, G.B.O


  4. #4
    Join Date
    Feb 2000
    Location
    Indiana USA
    Posts
    193

    Re: Making an input box appear only once.

    To declare the variable public within the form, place the Dim VariableName in the General declarations part of the form (Start of the form). To make a global variable(available to all forms) you would declare it in a module by using Public VariableName


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Making an input box appear only once.

    In order to share variables between forms you will need to put them in a MODULE. The purpose of a module is for variable and Code sharing between forms and user defined controls etc. It can contain Variables, Subroutines and Functions.

    To add a MODULE to your program, Go to the Project menu, click it and then Click Add Module. Select New. This should produce a second window with General Declarations.
    To define a Public variable add one or more of the following samples to the Module General Declarations section


    Public strMyvar as string ' or maybe
    Public blMySwitch as Boolean ' or maybe
    Public inMyInteger as Integer ' etc

    Public means just that. Any form or other program component has access to them. So both your forms can look at and change variables. It is also a method in which you can commmunicate between Forms

    It should be noted, you wiil need to name this module just like you did your Form and your project. It will bea seperate file on disk with a .bas file extension
    In regards to subroutines and Functions, you can define them in this module just like you can in a Form.

    Hope this Helps,

    John G

  6. #6

    Re: Making an input box appear only once.

    Looks like they took care of it for me.

    FaRd0wN


  7. #7
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Making an input box appear only once.

    You can share variables that belong to forms either by using a public member as already stated, or by the preferred method of using properties on each form.

    eg:

    - A form ('frmCustomer.frm') has a property as such :


    public property get Something() as string
    Something = "A Value from the customer form"
    End property




    - another form ('frmMain.frm') does something like :


    Dim fFrm as frmCustomer
    '
    set fFrm = new frmCustomer
    '
    ' Process the form a little bit
    '
    MsgBox fFrm.SomeThing
    '




    By passing around the form object reference (fFrm) you can then access it's own individual properties - this is preferable to using Modules as you get the individual value / property from that forms instance rather than a global value (that could be changed at any point).

    Forms are really classes as far as VB is concerned (with a user interface obviously



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  8. #8
    Guest

    Re: Making an input box appear only once.

    Thanks for all your help - its working great now.


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

Featured