PDA

View Full Version : Problem Doing a VB Login Password Loop


singularity2006
11-23-2003, 09:21 PM
I'm currently doing a do until loop for a login screen. I'm pretty sure this can easily be done without a loop but it's a requirement for the program as defined by the instructor so I might as well stick it in. It seems to work, but is there perhaps a more elegant or correct way of doing things?

Private Sub Form_Load()
Form1.Hide
Call Login
Form1.Show
End Sub

Private Sub Login()
'This sub initiates the form login process.

n = 0
Do Until n = 3
Password = InputBox("Please enter your password", "IHS ASB Web Equipment Roster")
Select Case Password
Case Is = "begin"
Exit Do
Case Else
n = n + 1
End Select
Select Case n
Case Is = 3
End
End Select
Loop

End Sub

draconix
12-04-2003, 10:09 PM
Private Sub Form_Load()
Form1.Hide
Call Login
Form1.Show
End Sub

Private Sub Login()
'This sub initiates the form login process.
n = 0
Do Until n = 3
Password = InputBox("Please enter your password", "IHS ASB Web Equipment Roster")

If Password = "begin" Then
Exit Do
Else
n = n + 1
End If
Loop

If n = 3 Then
End
End If
End Sub

Used if-else instead of select because there are only two choices. Moved the n = 3 check to the outside of the loop because that's cleaner. That's all for now.

Isaiah

OC-NightHawk
12-06-2003, 12:06 AM
@draconix

The code is ok but why have multipul if statements that check for the same thing. Heres my suggestion. One note, using multipul exit points in a function or sub routine makes it harder for the code to be maintained. Its a big no no, and in some places will cost you your job. I'm not kidding its a bad habbit. Also from this code I take it that the password is still hard wired.


Private Sub Form_Load()
Dim result As Long
Dim n as long

Form1.Hide
n = 0
'This sub initiates the form login process.
do until n = 3
result = Login
If result = true Then
Form1.Show
n=3 'terminates the loop
Else
If n=3 then
End
Else
n = n + 1
End if
End If
loop
End Sub

Private Function Login() as boolean

Password = InputBox("Please enter your password", "IHS ASB Web Equipment Roster")

If Password = "begin" Then
Login=True
End If

End Sub

singularity2006
12-06-2003, 05:21 PM
Currently, the login password is what defines all the user variables, which is currently still hard coded. Anyhow, here's what it looks like:

Private Sub Login()

bytCounterUntilExit = 0
strPassword(1) = "begin"
strPassword(2) = "friendly"
strPassword(3) = "morning"
strPassword(4) = "miso"
strPassword(5) = "sensitive"

Do Until bytCounterUntilExit = 3
strPasswordInput = InputBox("Please enter your password:" & Chr(10) & "(" & bytCounterUntilExit & " attempts out of 3)", "IHS ASB Web Equipment Roster")
Select Case strPasswordInput
Case strPassword(1)
strFirstName = "CHUCK"
strLastName = "LEE"
strIDNumber = "52351256"
Call RecordLogin
Exit Do
Case strPassword(2)
strFirstName = "RICHARD"
strLastName = "LAM"
strIDNumber = "40753451"
Call RecordLogin
Exit Do
Case strPassword(3)
strFirstName = "ERIC"
strLastName = "LUONG"
strIDNumber = "71100505"
Call RecordLogin
Exit Do
Case strPassword(4)
strFirstName = "JOHN"
strLastName = "JI"
strIDNumber = "53007442"
Call RecordLogin
Exit Do
Case strPassword(5)
strFirstName = "LILLY"
strLastName = "NGUYEN"
strIDNumber = "40782261"
Call RecordLogin
Exit Do
Case Else
bytCounterUntilExit = bytCounterUntilExit + 1
End Select

Select Case bytCounterUntilExit
Case Is = 3
MsgBox "Sorry, you only get three tries!", , "Login Failed!"
Open "login_activity.csv" For Append As #1
Write #1, "FAILED LOGIN"; "ATTEMPTED@"; Format(Now, "Short Date"); Format(Now, "Short Time")
Close #1
End
End Select
Loop

End Sub

In anycase, I'm definitely gonna rewrite this program to have most of the data stored externally but that'll be for a later date. This term project I actually intend to use @ work with my students in the web lab. The only issue is that because of lack of interest, the school's ASB has only give me 3 students to work on their website, http://staff.esuhsd.org/~ih-govt/ (I designed several revisions since I last went to that school). And at this point, I just don't have enough students to necessitate having external files. And at the same time, I'm running out of time and have to turn my project in anyway. =D

In anycase, this is some fun stuff. Hah, just for some background info, I originally never wanted to do programming because of issues regarding my piss poor math skills and then some. I wanted to go into design and web administration. My parents then came out of nowhere my junior year and hassled me for 2 years about going to med school. BEing the proper asian child I am, I tried the sciences for a year, did damn well, had fun, got my A's, but got tired of coming out of chem lab every night high as a kite. In an all too emotional argument, for exactly one day, they gave in and said "we support you in what you want to do." For one day I was ready to jump back into web design. Then the day after I got lectured about going into law. -.-" Asians, go figure.

Anyhow, seeing that law is graduate stuff, and if i I do, I'd be doing business law, I still need a BS degree. I pointed myself @ business administration since having a business background before hitting business/corporate law would be suitable. So in anycase, I also pointed myself @ business administration w/ a concentration in accounting information systems. Man, this database stuff feels so powerful. I never knew how powerful it was until I did this simple program here.

Anyhow, I'm year 2 in college, 2 more years to go to finish my lower level GE (the first year was wasted doing all science, they don't help my current major at all)..... time to get schooled. :thumbsup:

OC-NightHawk
12-06-2003, 09:05 PM
Originally posted by singularity2006
Man, this database stuff feels so powerful. I never knew how powerful it was until I did this simple program here.

You'd never know it if you didn't try, but yeah it is kind of cool in a stupid little way isn't it. :arteest:

If you want to get into some even cooler database stuff go get your self of MS SQL Server 2000 or what ever the current version 120 day trial is. Then have at it with making the database use it. Now that is some interesting stuff. I my self plan on taking my texhnical knowledge and sinking it into a web presence for accepting orders for custome built computers of any level; prepaid of course. Then I'll run flyers and ads in the school paper and hope some people buy some machines. Last time I did a trial run to gauage interest for custome high performace machines for personal workstations and made $2000 pure profit after building three machines. Not too shabby.:applause:

StefanDidak
12-06-2003, 10:23 PM
Originally posted by OC-NightHawk
If you want to get into some even cooler database stuff go get your self of MS SQL Server 2000 or what ever the current version 120 day trial is.

Or get MSDE, which is free, identical to SQL2K, but has a 2GB datastore limit.

OC-NightHawk
12-07-2003, 01:36 AM
Originally posted by StefanDidak
Or get MSDE, which is free, identical to SQL2K, but has a 2GB datastore limit.

This is available at Microsoft's site and free? Whats the catch?:) Can it host a database on the web or handle multipul users or is it strictly just a single user desk top type engine?

StefanDidak
12-07-2003, 01:46 AM
Originally posted by OC-NightHawk
This is available at Microsoft's site and free? Whats the catch?:) Can it host a database on the web or handle multipul users or is it strictly just a single user desk top type engine?

I'm not sure where it's on the site but they've been giving it away with practically everything from Office flavors that include Access, etc. Some of our engineers have been using it as a local solution to prototype on before rolling anything out on the real SQL server. I believe the only catch is the 2GB limit and that it's set to 5 concurrent batches. Oh, and it doesn't come with any special tools like the SQL Enterprise Manager that would allow you to design the system visually. Then again, the SQL-EM hasn't been a great design for that anyway. :)

OC-NightHawk
12-07-2003, 08:40 AM
Originally posted by StefanDidak
I'm not sure where it's on the site but they've been giving it away with practically everything from Office flavors that include Access, etc. Some of our engineers have been using it as a local solution to prototype on before rolling anything out on the real SQL server. I believe the only catch is the 2GB limit and that it's set to 5 concurrent batches. Oh, and it doesn't come with any special tools like the SQL Enterprise Manager that would allow you to design the system visually. Then again, the SQL-EM hasn't been a great design for that anyway. :)

Design it visualy through that tool? :applause: .... thats funny. No actually I wrote my self a toy application that does every thing it does but with a nice interface instead of that blasted computer management junk feel. I myself like the Office style feel so I have it working like a Access on steroids. :) Nothing like doing it your self to make sure there are as few bugs as possible. And if there is a bug I only have myself to blame, and then have the added bonus of being able to go in and squish it then and there. I consider it a toy only in the sense that I made it for fun educational purposes.

CGTalk Moderation
01-16-2006, 07:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.