Welcome Guest [Log In] [Register]
We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Help communicating betwwen Windows Forms
Topic Started: Nov 5 2009, 11:05 AM (133 Views)
ZapTap
Want to talk? My inbox is always open :D
[ *  *  *  * ]
I have two forms in a project, one to set up the game, and one to play the game. The problem is, when the second form opens it is supposed to read which radio button is selected in the first form, but I can't get it to work. I set it up so when the user clicks on the radio button it changes the text of a hidden label within Form1, but my second form always reads that this label's text is set to whichever statement is the first option in the if statement of the function, so when I switch which number is in the main If.. Then with one of the number checked for within an Elseif.. Then, it will always say true on the If.. Then, no matter what the value. Here's my function in form2:
Code:
 
Function FindNumColors()
Dim frmSetup As New Form1
If (frmSetup.lblNumColors.Text = 3) Then
Return 3
strColor1 = frmSetup.txtColor1.Text
strColor2 = frmSetup.txtColor2.Text
strColor3 = frmSetup.txtColor3.Text
ElseIf (frmSetup.lblNumColors.Text = 4) Then
Return 4
strColor1 = frmSetup.txtColor1.Text
strColor2 = frmSetup.txtColor2.Text
strColor3 = frmSetup.txtColor3.Text
strColor4 = frmSetup.txtColor4.Text
ElseIf (frmSetup.lblNumColors.Text = 5) Then
Return 5
strColor1 = frmSetup.txtColor1.Text
strColor2 = frmSetup.txtColor2.Text
strColor3 = frmSetup.txtColor3.Text
strColor4 = frmSetup.txtColor4.Text
strColor5 = frmSetup.txtColor5.Text
End If
End Function

EDIT: this is in VB .NET 2003
Edited by ZapTap, Nov 5 2009, 11:05 AM.
Offline Profile Quote Post Goto Top
 
Chris
Member Avatar
Member
[ *  *  *  *  * ]
Try adding the project name before the form name.

Ex: Project name is MMORPG

If (MMORPG.frmSetup.lblNumColors.Text = 5)

Also.. I think you're supposed to use two equal signs. I can't remember. xD
Offline Profile Quote Post Goto Top
 
ZapTap
Want to talk? My inbox is always open :D
[ *  *  *  * ]
Chris
Nov 5 2009, 05:54 PM
Try adding the project name before the form name.

Ex: Project name is MMORPG

If (MMORPG.frmSetup.lblNumColors.Text = 5)

Also.. I think you're supposed to use two equal signs. I can't remember. xD
nope, that comes up with a build error... and the double == is in C++, which I would be using if I could do anything but if statements and/or I didn't have VB .NET class at school xD
Offline Profile Quote Post Goto Top
 
Chris
Member Avatar
Member
[ *  *  *  *  * ]
Just incase: I don't just mean what you named the file. You have to click the My Project part in the area where you find all the forms listed; there should be a property for "Name" like the one that each form has.

If that isn't the problem I'm not sure what is :S


EDIT:

Maybe it's because you are re-dimming the window that you want to communicate with.
Code:
 
Dim frmSetup As New Form1
Edited by Chris, Nov 5 2009, 09:28 PM.
Offline Profile Quote Post Goto Top
 
ZapTap
Want to talk? My inbox is always open :D
[ *  *  *  * ]
I can't seem to find the "My Projects" area you're talking about, did you mean the name you type in when you create the project? That came up with a syntax error...
and I tried removing that dim statement and making it global, but it still did the same thing. When I set breakpoints and tested it the other day, it would always fire on the first condition in the if statement, regardless of the true value :-/
Offline Profile Quote Post Goto Top
 
Chris
Member Avatar
Member
[ *  *  *  *  * ]
In the Solution Explorer frame there is a part called "My Project"
Double click that; a new tab should open.

Look for "Root Namespace"
Edited by Chris, Nov 6 2009, 04:22 PM.
Offline Profile Quote Post Goto Top
 
ZapTap
Want to talk? My inbox is always open :D
[ *  *  *  * ]
Oh, yeah, that is the same as what I had tried, and it gave me a syntax error.
I decided to do it a bit differently, by having a separate form for each layout, and using an if stateent within the setup form to decided which layout, eliminating the above problem.

However, due to security issues on the school computers, I have to find a way to force it to close the setup form, as I had to used Me.Hide() so that the variable could be read by the game form. I think I can just make it pop back up and tie it in with a win count or something along those lines. Hopefully this will work once I get all my score counted sorted out.
Offline Profile Quote Post Goto Top
 
ZapTap
Want to talk? My inbox is always open :D
[ *  *  *  * ]
I'm having another problem now..
I have it set up so the user can pick the colors they want to use in the setup form, and when the game form opens, it sets the variables as the colors they chose, but it seems to not read what the current value is in the label storing the chosen colors name on the setup form, it reads the default value, and so the user can't choose their colors. Any idea why?
Edited by ZapTap, Nov 20 2009, 10:13 PM.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Programming and Scripting Chat · Next Topic »
Add Reply