tags:

views:

272

answers:

2

I am developing a game and I want an options window to be used so that the user enters data into this and it carries to the main window instead of being lost...

I tried it with my recent program , guess the color , but it did not work the way I thought. I thought that I could assign it to a string in a textbox to a variable and it would carry into the main window...

I want this to happen:

  1. The user begins the program by clicking shortcut
  2. User clicks options in the toolbar
  3. A new window comes onto the screen
  4. In this window the user will select a map size then click ok the verify , radiobuttons used in this example...
  5. Back to the main screen after clicking ok
  6. User clicks new on toolbar to begin game
  7. Game is then playing...

Edit:

Form1 <<< Form 2 game screen 3x3 button end turn

Form 1 New game is begun form 2 appears 3x3 button is pressed* variable is used to change map (there is only one map for now)* form2 closes and form1 shows End turn is clicked

+2  A: 

Generally, what you have to do is when you create a new form/window, you hold onto the reference of that form window until it closes.

Then, when it closes, you can copy the information back from the form/window that just closed into your main window (or whatever else you wish).

The key here is to expose properties on the child window which represent the inputs. So if the child window that was opened has a color that was selected, create a property which exposes that color so that the parent window can access it on the child.

casperOne
so what you are saying is that I should tell the program to copy and paste the information?
Jimbo8098
No. He is saying that the main window needs to ask the child window (through it's public properties) for the information.
JohnFx
A: 

EDIT: Why did I think this was a VB6 question? Did this get re-tagged? If the OP can clarify which version of VB, I'll update my example.

OOP even applies to VB6. Create an class to hold the shared data. At the application startup, create the object as a global object (variable). I hate global variables as much as the next guy, but in the case where this data needs to be seen by the whole application (a logged-in user object or a logging object, for example), it's appropriate. You can assign the values to the class object in the first form, and then read them from the class object in the second or any other form.

Example class:

Option Explicit

Private m_firstName As String
Private m_lastName As String

Public Property Get FirstName() As String
    FirstName = m_firstName
End Property
Public Property Let FirstName(ByVal value As String)
    m_firstName = value
End Property

Public Property Get LastName() As String
    LastName = m_lastName
End Property
Public Property Let LastName(ByVal value As String)
    m_lastName = value
End Property

Public Function FullName() As String
    FullName = m_firstName & " " & m_lastName
End Function

I don't have VB6 on this machine, or I could have given you a better example. I think in .NET these days ;)

This may explain things quite a bit more - http://www.vbforums.com/showthread.php?t=374132

HardCode
This sounds like it is becoming the correct answer but I am new to Visual Basic and havent had to use class all that much...
Jimbo8098
so defining the data as a public property means that all of the windows can read the information?
Jimbo8098
Yes. As long as the object is created globally, any code anywhere in the app can access the Public properties.
HardCode