Can some one help me with this code and the strange exception that the compiler throws
The Code:
Imports System.IO
Module Module1
Dim check As String = ""
Dim userName As String
Dim passWord As String
Dim userNameArray() As String
Dim passWordArray() As String
Dim passWordPass As Boolean = False
Dim userNamePass As Boolean = False
Dim counterU As Integer = False
Dim counterP As Integer
Dim oFileWriterU As New StreamWriter("C:\Username.txt")
Dim oFileWriterP As New StreamWriter("C:\Passwd.txt")
Dim oFileReaderU As New StreamReader("C:\Username.txt")
Dim oFileReaderP As New StreamReader("C:\Passwd.txt")
Public Sub Main()
Dim input As String = ""
check = oFileReaderU.ReadToEnd()
If check = "" Then ' beginning if
AddUser()
End If
Do Until input.Contains("-1") 'beginning loop
Console.WriteLine("What function do you want to preform")
Console.WriteLine("1. Add new user")
Console.WriteLine("2. Login")
input = Console.ReadLine()
If input.Contains("1") Then 'second if
AddUser()
Else
input = String.Empty
Do Until oFileReaderU.EndOfStream 'do until end of username
ReDim Preserve userNameArray(counterU)
userNameArray(counterU) = oFileReaderU.ReadLine
counterU += 1
Loop
counterU = 0
Do Until oFileReaderP.EndOfStream 'do until end of passwordfile
ReDim Preserve passWordArray(counterP)
passWordArray(counterP) = oFileReaderP.ReadLine
counterP += 1
Loop ' end of passwordfile loop
counterU = 0
counterP = 0
Console.Write("User Name: ")
input = Console.ReadLine()
While counterU <= userNameArray.Length 'counterU while loop
If input = userNameArray(counterU) Then 'input = userNameArray if
userNamePass = True
Exit While
Else
counterU += 1
End If 'input = userNameArray endif
End While 'counterU while loop
input = String.Empty
If userNamePass = True Then 'userNamePass=true if
Console.Write("Password: ")
input = Console.ReadLine()
While counterP <= passWordArray.Length 'counterP while loop
If input = passWordArray(counterP) Then 'input = passWordArray if
passWordPass = True
Exit While
Else
counterP += 1
End If 'input = passWordArray endif
End While 'end of counterP while loop
End If 'userNamePass=true endif
If userNamePass = True AndAlso passWordPass = True Then 'userNamepass = true andalso if
If counterP = counterU Then
Console.Clear()
Console.WriteLine("Login Successful")
Else
Console.WriteLine("Login Unsuccessful")
End If
Else
Console.WriteLine("Username or password fail")
End If ' userNamesPass = True andalso endif
End If 'end second endif
Loop
End Sub
Public Sub AddUser()
Console.Write("Please enter new user's name: ")
userName = SimpleCrypt(Console.ReadLine)
oFileWriterU.WriteLine(userName)
Console.Write("Please enter new user's password: ")
passWord = SimpleCrypt(Console.ReadLine)
oFileWriterP.WriteLine(passWord)
End Sub
Public Function SimpleCrypt( _
ByVal Text As String) As String
' Encrypts/decrypts the passed string using
' a simple ASCII value-swapping algorithm
Dim strTempChar As String, i As Integer
For i = 1 To Len(Text)
If Asc(Mid$(Text, i, 1)) < 128 Then
strTempChar = _
CType(Asc(Mid$(Text, i, 1)) + 128, String)
ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
strTempChar = _
CType(Asc(Mid$(Text, i, 1)) - 128, String)
End If
Mid$(Text, i, 1) = _
Chr(CType(strTempChar, Integer))
Next i
Return Text
End Function
End Module
The Exception:
An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'UserNameAndPasswd.Module1' threw an exception.
come see night shift at http://forum.thegamecreators.com/?m=forum_view&t=106003&b=25 see you there