FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


vBasic





n0obie4life
Code:

Private Sub Form_Load()

Dim recarray(20) As String * 20 ' Catch if they have ANY account..
Dim filename As String
Dim temp As String * 20
Dim a

filename = App.Path & "\info.dat" ' To record joor data

Open filename For Random As #1 Len = 20

For i = 1 To 20
Get #1, i, recarray(i)
Next

If recarray(1) = temp Then
   
    a = MsgBox("You do not have an account. Do you want to create one?", vbYesNo + vbQuestion, "Create New Account?")
   
    Select Case a
        Case vbNo
            MsgBox "Error 048 - No Account", vbCritical, "Error!"
            Unload Me
            Unload frmLogin
        Case vbYes
            frmNewAcct.Show
            Unload Me
    End Select

End If
End Sub

Private Sub cmdQuit_Click()
Dim quit
quit = MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Quit?")
Select Case quit
    Case vbYes
        Unload Me 'changed from "END". its bad.
        Exit Sub
    Case vbNo
        Exit Sub
    Case Else
        Exit Sub
End Select
End Sub

Private Sub cmdLogin_Click()

Dim recarray(20) As String * 20
Dim username(20) As String * 10
Dim password(20) As String * 8
Dim usernamepass, usernamepassactual As String * 20
Dim user As String * 10
Dim pass As String * 8
Dim temp As String * 20
Dim filename As String

filename = App.Path & "\info.dat" ' Load your data...

Open filename For Random As #1 Len = 20 'Open :)

user = LCase(txtUser.Text)
pass = LCase(txtPass.Text)

usernamepass = (user & ": " & pass)


For i = 1 To 20
    username(i) = (Left$(recarray(i), 10))
    result = Decrypt(username(i), 10)
   
    password(i) = (Right$(recarray(i), 8))
    result = Decrypt(password(i), 8)
Next

For i = 1 To 20
   
    If user = username(i) And pass = password(i) Then
        ' He got the password :)
        Unload Me
        Unload frmLogin
        frmMain.Show
    End If
   
Next

'if password and username not found then:
For i = 1 To 20
    If user = username(i) Then
        result = MsgBox("The password for this username is invalid", vbCritical, "Invalid Password")
        txtPass = ""
        txtPass.SetFocus
        Close #1
        Exit Sub
    End If
Next

result = MsgBox("The username is invalid", vbCritical, "Invalid Username")
txtUser.Text = ""
txtPass.Text = ""
txtUser.SetFocus
Close #1

End Sub


I get a "File already open" error. Help anyone..?
S3nd K3ys
Without reading all the code, try throwing in a "close" statement at some point before you open any files. If that fails, carefully go thru how many files you open, when you open them, and be sure you close them.

You may get this error, (but I doubt it, prolly a diff error code) if the file is in use by another process.

I'll look at the code more closely in a few (after coffee)
S3nd K3ys
Code:
For i = 1 To 20
    username(i) = (Left$(recarray(i), 10))
    result = Decrypt(username(i), 10)
   
    password(i) = (Right$(recarray(i), 8))
    result = Decrypt(password(i), 8)
Next


So, uhhh... what you making here, hmmm?? Wink
S3nd K3ys
Ok, looks like you're opening a file in the form load event, then opening a file with the same file number in the cmdLogin sub without closing the file you opened from the load event.

Just a hint, close any open files when you're done with them, don't leave them open. If you need to work on that file later from another sub, if possible close it when you're done and re-open it only when you need it.

HTH. If not, I'll try to reconstruct the program here and debug it. VB6?
n0obie4life
Yes. VB6.

Its a login form Smile.

What it does is this

1) User opens program
2) Program opens the info.dat file to check if he has an account
3) If user does not have an account, it will show frmNewAcct
4) If user has an account, it will continue loading.
5) Then user types in a password & userid
6) Program opens info.dat file again to check the pass and user
7) Correct, load. Wrong. Reject.

Code:
For i = 1 To 20
    username(i) = (Left$(recarray(i), 10))
    result = Decrypt(username(i), 10)
   
    password(i) = (Right$(recarray(i), 8))
    result = Decrypt(password(i), 8)
Next


Is an external module to encrypt and decrypt Smile.
n0obie4life
Code:
Private Sub Form_Load()

Dim recarray(20) As String * 20 ' Catch if they have ANY account..
Dim filename As String
Dim temp As String * 20
Dim a

filename = App.Path & "\info.dat" ' To record joor data

Open filename For Random As #1 Len = 20 'Open :)

For i = 1 To 20
Get #1, i, recarray(i)
Next

If recarray(1) = temp Then
   
    a = MsgBox("You do not have an account. Do you want to create one?", vbYesNo + vbQuestion, "Create New Account?")
   
    Select Case a
        Case vbNo
            MsgBox "Error 048 - No Account", vbCritical, "Error!"
            Unload Me
            Unload frmLogin
        Case vbYes
            frmNewAcct.Show
            Unload Me
    End Select
   
Close #1

End If
End Sub

Private Sub cmdQuit_Click()
Dim quit
quit = MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Quit?")
Select Case quit
    Case vbYes
        Unload Me 'changed from "END". its bad.
        Exit Sub
    Case vbNo
        Exit Sub
    Case Else
        Exit Sub
End Select
End Sub

Private Sub cmdLogin_Click()

Dim recarray(20) As String * 20
Dim username(20) As String * 10
Dim password(20) As String * 8
Dim usernamepass, usernamepassactual As String * 20
Dim user As String * 10
Dim pass As String * 8
Dim temp As String * 20
Dim filename As String

filename = App.Path & "\info.dat" ' Load your data...

Open filename For Output Lock Read As #1 Len = 20 'Open :)

user = LCase(txtUser.Text)
pass = LCase(txtPass.Text)

usernamepass = (user & ": " & pass)


For i = 1 To 20
    username(i) = (Left$(recarray(i), 10))
    result = Decrypt(username(i), 10)
   
    password(i) = (Right$(recarray(i), 8))
    result = Decrypt(password(i), 8)
Next

For i = 1 To 20
   
    If user = username(i) And pass = password(i) Then
        ' He got the password :)
        Unload Me
        Unload frmLogin
        frmMain.Show
        Close #1
    End If
   
Next

'if password and username not found then:
For i = 1 To 20
    If user = username(i) Then
        result = MsgBox("The password for this username is invalid", vbCritical, "Invalid Password")
        txtPass = ""
        txtPass.SetFocus
        Close #1
        Exit Sub
    End If
Next

result = MsgBox("The username is invalid", vbCritical, "Invalid Username")
txtUser.Text = ""
txtPass.Text = ""
txtUser.SetFocus

Close #1

End Sub


UPdated the code.
S3nd K3ys
n0obie4life wrote:
...

UPdated the code.


That looks better.

If you're interested, I have a suggestion for you on this app... Error trapping

Throw in something like this to trap errors. Funny things can happen when accessing files and you don't have error trapping. (Any apps for that matter)

Code:
Private Sub Form_Load()

<snip>

On Error goto FileError

filename = App.Path & "\info.dat" ' To record joor data

<snip>

FileError:
Close
If Err = 75 Then MsgBox "Error " & Err & ": unable to access disk"
If Err = 71 Then MsgBox "Error " & Err & ": no disk in drive"
End Sub



Hope that helps. (BTW, I knew it was a login app after I read thru the code and saw the errors, I was just bustin yer chops. Wink )
n0obie4life
Thanks for your help Smile
Related topics
What computer languages you know?
cracking
Re-Design Forums...
Software development
[UNIK] -- Présentation des membre et de leur projet !! --
Beginning Programming... Help!
VB.NET learning
Computer Programmer
SQL vs mySQL
I need help with programming...
juegos en flash
En Beđendiđimiz Programlama dilleri?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.