2011-07-11 18 views
0

今日、私はVB.netで私にとって役に立つプログラムを考え出しました(これまでVB.netでコード化したことはありません)。すべてがこの時点までうまくいっていますが、私は上記のエラーで困っています。問題は、プロファイル取得のコメントの下にあるwindowssevenexistsonsourceブール値です。私が始めてしまう前に、悪い習慣から抜け出したいと思うように、私はコードの批判もうまく取ります! (サブは終わりを行いますが、私はそのコードを含めていない)変数が宣言されていません。

コード:あなたの変数の宣言では

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 

答えて

1

windowssevenexitsonsourcewindowssevenexistsondestinationをあなたのtryブロックで、あなたはtryブロックにその範囲を限定しています。あなたのサブルーチンの始めにそれらを宣言してみてください。

+1

男に賞金を与える!ありがとうございました。 – Trinitrotoluene

関連する問題