0

Just trying to figure out how to pass one simple integer(StartingTeam) from Form2 to Form 1.

Form 2 Code

Public Class frmTeamChoose
Public StartingTeam As Integer
Public Sub btnTeam1_Click(sender As Object, e As EventArgs) Handles btnTeam1.Click
    StartingTeam = 1
End Sub

Public Sub btnTeam2_Click(sender As Object, e As EventArgs) Handles btnTeam2.Click
    StartingTeam = 2
End Sub

End Class

Form 1 is called Form1

1
  • Forms are classes. How would you pass this integer to a different class? Commented Nov 14, 2012 at 9:46

1 Answer 1

1

Although you need to provide more info I 'll try to help you:
I suppose that you have open Form2 from Form1:

'In form1:
Dim k as integer=Form2.StartingTeam 

An improved solution is to create a property:
Form 2 code:

 Private miStartingTeam 
 Public Property StartingTeam As Integer
    Get
        Return miStartingTeam 
    End Get
    Set(ByVal value As Integer)
        miStartingTeam = value
    End Set
 End Property

Then your code as it is.
In Form1:

'Open Form2
Dim f2 as new Form2
'f2.StartingTeam=1 'if you want to set a value before f2 opening
f2.Show


'Get StartingTeam from f2
dim k as integer=f2.StartingTeam 

Let me know if you need anything else

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.