VB.Net Passing values to another form

前端 未结 2 576
予麋鹿
予麋鹿 2020-12-02 02:31

I would like to know how to pass a value from form1 to another form\'s public sub. The problem is that it says \"it is not accesible in this context because it is \'Private\

相关标签:
2条回答
  • 2020-12-02 03:13

    You could pass it as a parameter:

    Public Sub Check(valueToCheck as String)
       'get the value to here
    End Sub
    

    Or create a property on form2 to receive it:

    private _HostOrSomething As String = ""
    Friend Property HostOrSomething As String
       Get
            Return _HostOrSomething 
        End Get
        Set(ByVal value As String)
            _HostOrSomething = value
        End Set
    

    In which case, Sub Check could use _HostOrSomething since it is local var. To use these:

    HOST = Test(1)
    frm2.Check(HOST)
    

    or

    HOST = Test(1)
    frm2.HostOrSomething = HOST
    frm2.Check
    
    0 讨论(0)
  • 2020-12-02 03:22

    You can use global variables to pass data from one from to another

            Dim A As New Integer= 10
    

    Here how you declare the global The class can be define anywhere in the application.

    Public Class GlobalVariables
    Public Shared INTver As Integer
    End Class
    

    And how you use global variable to store the answer is here

    GlobalVariables.INTver= A
    

    put this lines in your "privet sub" and you can access the variable to any of your form that is in your WINDOWS application.

    0 讨论(0)
提交回复
热议问题