2017-03-11 15 views
0

これらのifステートメントとelseステートメントをVisual Basic 2010 Expressで整理する必要があります。おそらくコードからわかるように、プログラムが正しく動作しているときは、プログラムは外部でテキストファイルにあるデータを表示しなければなりません。このデータが見つからない場合は、ラベルにエラーメッセージが表示されます。 助けてくれてありがとう。Visual BasicのIfとElseステートメント

コード:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    Dim filename As String = "..\..\usernamepassword.txt" 
    Dim objreader As New System.IO.StreamReader(filename) 
    Dim contents As String 
    Dim check As String 
    Dim checkfile As New System.IO.StreamReader("..\..\checkfile.txt") 
    check = checkfile.ReadToEnd 
    For i As Integer = 1 To check 
     contents = objreader.ReadLine 
     Dim data As New List(Of String)(contents.Split(",")) 
     If forename.Text = data(2) Then 
    'first if statement is here \/ 
      If surname.Text = data(3) Then 
       fullname.Text = (data(2) & " " & data(3)) 
       dob.Text = data(4) 
       phone.Text = data(5) 
       address.Text = data(6) 
       password.Text = data(1) 
      'else statement \/ 
      Else 
       Label2.Text = "Sorry, no result found for this student." 
       Label5.Text = "Please note this system is caps sensitive." 
      End If 
     End If 
    Next i 
    Dim s As String = "" 
    forename.Text = s 
    surname.Text = s 
End Sub 

エンドクラスは

+0

フルラインには何が含まれていますか? – Sniper

+0

私はあなたが何を意味するのか分かりません –

+0

テキストファイルに何が入っていますか?最初の名前と同じ名前のミドルネームとパスワード – Sniper

答えて

0

あなたはそれが整数でなければなりません場合、文字列として宣言されてきたこの

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
Dim filename As String = "..\..\usernamepassword.txt" 
Dim found as Boolean = False 
Dim objreader As New System.IO.StreamReader(filename) 
Dim contents As String 
Dim check As String 
Dim checkfile As New System.IO.StreamReader("..\..\checkfile.txt") 
check = checkfile.ReadToEnd 
For i As Integer = 1 To check 
    contents = objreader.ReadLine 
    Dim data As New List(Of String)(contents.Split(",")) 
    If forename.Text = data(2) Then 
'first if statement is here \/ 
     If surname.Text = data(3) Then 
      fullname.Text = (data(2) & " " & data(3)) 
      dob.Text = data(4) 
      phone.Text = data(5) 
      address.Text = data(6) 
      password.Text = data(1) 
      found = True 
      Exit For 
     End If 
    End If 
Next i 
If found = False Then 
    Label2.Text = "Sorry, no result found for this student." 
    Label5.Text = "Please note this system is caps sensitive." 
End If 
Dim s As String = "" 
forename.Text = s 
surname.Text = s 
End Sub 
+0

ありがとうございました! –

+0

うまくいけば、答えとしてマークしてください。 – Sniper

+0

新しいユーザーは、通常、回答を受け入れる方法やそれをすべきかどうかを知りません。その場合は、[ツアー](http://stackoverflow.com/tour)または[回答の受け取りはどうしますか?](https://meta.stackexchange.com/questions/5234/how-does-答えを受け入れる)ので、彼らはいくつかのガイダンスを持っています。 –

0

チェックのようにそれを処理する必要があります。 オンに厳密に設定してオフを推測する

関連する問題