Article View: comp.lang.basic.visual.misc
Article #354Re: HELP! I need a loop! Can't figure this...
From: Joe "Nuke Me Xemu" Foster
Date: Sat, 11 Mar 2000 00:00
Date: Sat, 11 Mar 2000 00:00
115 lines
4201 bytes
4201 bytes
"MikeG in Philly" <PhilaPA@hotmail.com> wrote in message news:38cae00b@news3.enter.net...
> Hi Folks: the following code snippet is a loop for a password, and it works
> fine as it is...but I need to give the user three tries before exiting the
> sub and can't figure out the loop...can you help?
> Here's the code...
> Private Sub cmdOK_Click()
> Dim strLName As String
> Dim strPW1 As String
> Dim strLevel As String
> intCount = intCount + 1
Is intCount a global, form-level, or static variable, or what?
> Open "a:\password.dat" For Input As #1
> Do While Not EOF(1)
> Input #1, strLName, strPW1, strLevel
>
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
Why shouldn't the password be case sensitive? Check out StrComp in the help.
> LCase(Trim(strLevel)) = 3 Then
> frmMain.Show
> Me.Hide
> Close #1
> Exit Sub
>
> Else
Either use ElseIf or fix your indenting.
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
> LCase(Trim(strLevel)) = 2 Then
> Me.Hide
> frmMain.Show
> frmMain.cmdAssign.Visible = False
> frmTables.cmdOrders.Visible = False
> frmTables.cmdOL.Visible = False
> frmTables.cmdPurch.Visible = False
> frmTables.cmdCR.Visible = False
> Close #1
> Exit Sub
> Else
> If LCase(Trim(strLName)) = LCase(Trim(txtUserName.Text)) And
> LCase(Trim(strPW1)) = LCase(Trim(txtPassword.Text)) And
> LCase(Trim(strLevel)) = 1 Then
> Me.Hide
> frmMain.cmdView.Visible = False
> frmMain.Show
> Close #1
> Exit Sub
> End If
> End If
> End If
> Loop
> Close #1
> MsgBox "Sorry, wrong password."
> End Sub
Here's how I might do it, based on what you've shown us:
Open "a:\password.dat" For Input As #1
Do While intCount > 0 And Not EOF(1)
Input #1, strLName, strPW1, strLevel
If StrComp(strLName, txtUserName.Text, 0) <> 0 Then
' nope
ElseIf StrComp(strPW1, txtPassword.Text, 0) <> 0 Then
' sorry
ElseIf strLevel = 3 Then
intCount = 0
ElseIf strLevel = 2 Then
intCount = 0
frmMain.cmdAssign.Visible = False
frmTables.cmdOrders.Visible = False
frmTables.cmdOL.Visible = False
frmTables.cmdPurch.Visible = False
frmTables.cmdCR.Visible = False
ElseIf strLevel = 1 Then
intCount = 0
frmMain.cmdView.Visible = False
End If
Loop
Close #1
If IntCount = 0 Then
frmMain.Show
Me.Hide
ElseIf IntCount < 3 Then
txtPassword.Text = vbNullString
txtPassword.SetFocus
MsgBox "Sorry, wrong password."
ElseIf IntCount = 3 Then
MsgBox "Game over, man! Game over!"
Unload Me
End If
I'd really want to use at least a one-way hash for that password file.
--
Joe Foster <mailto:jfoster@ricochet.net> Space Cooties! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!
Technical Details
Message-ID:
<scm0r3mea5n96@corp.supernews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38cae00b@news3.enter.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 108062,4281b5412007ec6b X-Google-Attributes: gid108062,public X-Google-Thread: 110e3b,4281b5412007ec6b X-Google-Attributes: gid110e3b,public From: "Joe \"Nuke Me Xemu\" Foster" <joe@bftsi0.UUCP> Subject: Re: HELP! I need a loop! Can't figure this... Date: 2000/03/11 Message-ID: <scm0r3mea5n96@corp.supernews.com> X-Deja-AN: 596302561 References: <38cae00b@news3.enter.net> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: newsabuse@supernews.com Organization: L. Ron Hubbard Memorial Jeerleading Team X-MSMail-Priority: Normal Reply-To: "Joe \"Nuke Me Xemu\" Foster" <jfoster@ricochet.net> Newsgroups: comp.lang.basic.visual.misc,cz.comp.lang.basic.visual