holi4683 holi4683 - 1 year ago 59
Vb.net Question

How to pass integer value between forms without text boxes

I have a Main form that has a button. When pressed I want the integer value for i to = 0. I then want to pass this value of 0 to form2. Form2 counts i + 1 every minute for a sub on form2 but I want it to reset every time the button on the main form is pressed. I know how to pass string values from comboboxes, textbox ect. but I need to pass a variable that is not displayed like other questions on here have asked.

So basically everytime the button is pushed on the main form the i value on form2 will equal 0.

Answer Source

If you have put your variable at class level you just have to make it Public or Friend to be able to access it from other forms/classes/etc.


Public Class Form2
    Public i As Integer = 0
End Class

Your button in Form1:

Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    Form2.i = 0
End Sub

Read more about access levels on the MSDN Documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download