2014-01-22 53 views
0

因此,這只是讀取我的csv文件中的第一行記錄。我最終希望它能夠閱讀所有內容,並將其與用戶輸入進行比較,如果正確的話可以做一些事情。 我將非常感謝任何形式的幫助和建議。我的代碼只能讀取我的csv文件中的第一行記錄

讚賞,

For Each line As String In File.ReadAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls\stdnt&staffdtls.csv") 
     Dim item() As String = line.Split(","c) 
     If (enteredusername = item(0)) And (enteredpassword = item(1)) Then 
      Console.WriteLine() 
      Console.Clear() 
      Console.WriteLine("Welcome," & item(3) & item(4)) 
      Threading.Thread.Sleep(1000) 
      Console.Clear() 
     Else 
      Console.WriteLine() 
      Console.ForegroundColor = ConsoleColor.Red 
      Console.WriteLine("Sorry, username or password not found, please try 
     again.") 
      Console.ResetColor() 
      Main() 
     End If 

     If item(2) = "p" Then 
      pupilmenu() 
     ElseIf item(2) = "s" Then 
      staffmenu() 
     ElseIf item(2) = "a" Then 
      adminmenu() 
     End If 
    Next 
+0

你嘗試註釋掉你的循環的完整的內部並用'Console.WriteLine(line)'替換它? –

回答

1

它看起來像你的問題是,你有你的邏輯,你For循環內。很難肯定地說,它是什麼,你需要做的,不知道更多的細節,但我懷疑它可能應該是這樣的更多的東西:

Dim foundItem() as String = Nothing 
For Each line As String In File.ReadAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls\stdnt&staffdtls.csv") 
    Dim item() As String = line.Split(","c) 
    If (enteredusername = item(0)) And (enteredpassword = item(1)) Then 
     foundItem = item 
     Exit For 
    End If 
Next 
If foundItem IsNot Nothing Then 
    Console.WriteLine() 
    Console.Clear() 
    Console.WriteLine("Welcome," & item(3) & item(4)) 
    Threading.Thread.Sleep(1000) 
    Console.Clear() 
    If foundItem(2) = "p" Then 
     pupilmenu() 
    ElseIf foundItem(2) = "s" Then 
     staffmenu() 
    ElseIf foundItem(2) = "a" Then 
     adminmenu() 
    End If 
Else 
    Console.WriteLine() 
    Console.ForegroundColor = ConsoleColor.Red 
    Console.WriteLine("Sorry, username or password not found, please try again.") 
    Console.ResetColor() 
    Main() 
End If 
+1

是的,你的權利。現在它搜索得非常好。再一次感謝你。 – SkyTrees

+0

沒問題。你明白爲什麼這樣做,爲什麼你的第一次嘗試沒有?我希望這是自我解釋,但讓我知道你是否感到困惑。 –

+0

確實如此,否則會問。謝謝你,只是簡單地「複製和粘貼」對我來說毫無意義。 – SkyTrees

相關問題