Vb.net 变量未声明;由于其保护级别,可能无法访问

Vb.net 变量未声明;由于其保护级别,可能无法访问,vb.net,Vb.net,今天我决定想出一个在VB.net中对我有用的程序(我以前从未在VB.net中编写过代码)。到目前为止一切都很顺利,但我遇到了上面提到的错误。问题在于get-get-of-profiles注释下的windowssevenexistsonsource布尔值。我还将接受任何代码批评,因为我希望在开始之前摆脱不良做法!(sub没有结束,但我没有包括该代码) 代码: 在try块中声明变量windowssevenexitsonsource和windowssevenexistsondestination时,将

今天我决定想出一个在VB.net中对我有用的程序(我以前从未在VB.net中编写过代码)。到目前为止一切都很顺利,但我遇到了上面提到的错误。问题在于get-get-of-profiles注释下的windowssevenexistsonsource布尔值。我还将接受任何代码批评,因为我希望在开始之前摆脱不良做法!(sub没有结束,但我没有包括该代码)

代码:


在try块中声明变量windowssevenexitsonsourcewindowssevenexistsondestination时,将其范围限制在try块。尝试在子例程的开头声明它们

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    'Check that the entries required are not empty
    If String.IsNullOrEmpty(sourceipaddress.Text) Or String.IsNullOrEmpty(destinationipaddress.Text) Then
        MsgBox("Source or destination IP address is empty")
        Exit Sub
    End If

    'First we need to establish the operating system of the source and destination
    Try
        Dim windowssevenexistsonsource As Boolean = IO.Directory.Exists("\\" & sourceipaddress.Text & "\c$\users")
        Dim windowssevenexistsondestination As Boolean = IO.Directory.Exists("\\" & sourceipaddress.Text & "\c$\users")
    Catch ex As Exception
        MsgBox(ex.Message)
        Exit Sub
    End Try


    'Now we need to get a list of profiles in the relevant directory and put them into an array
    'Declare variables and empty the array
    Dim Sourcedirectorylistarray, destinationdirectorylistarray As String()
    Dim sourcedirectoryentry, destinationdirectoryentry As String
    Dim Sourcerootpath, destinationrootpath As String

    'Get List of Profiles
    Try
        If windowssevenexistsonsource = True Then
            Sourcedirectorylistarray = System.IO.Directory.GetDirectories("\\" & sourceipaddress.Text & "\c$\users\")
            destinationdirectorylistarray = System.IO.Directory.GetDirectories("\\" & destinationipaddress.Text & "\c$\users\")
        Else
            MsgBox("test")
        End If

    Catch ex As Exception
        MsgBox(ex.Message)
        Exit Sub
    End Try