MS VB 2008 noob here, need sum help plz

Soldato
Joined
29 Aug 2011
Posts
3,068
Location
UK
Hey guys, I have made a program on VB 2008 that can make calculation.
I want to make the password box appear first with the form not visible but after I enter the correct password(in 3 attempts). it only happens when I press the start button here the password box would come up.

any help plz?
 
Last edited:
'Assuming you have a form called frmMain and it is set to hide at startup.



Dim strPassword, strEnterPassword As String
Dim intTries As Integer

strPassword = "sausages"
intTries = 0

Do

intTries = intTries + 1
strEnterPassword = InputBox("Please enter the password. Attempt: " & intTries)

If strEnterPassword = strPassword Then
MsgBox ("Your Password is correct")
frmMain.Show
Else
MsgBox ("Password Incorrect. Access Denied!")

End If

Loop Until intTries = 3 Or strEnterPassword = strPassword
 
Couple of things,
1.Your variable for "Tries" is declared as a "String" (it should be Integer).
2.By the naming I guess you have a label called "lblAccess"? what does this do?

Hmm well if I try putting Integer in and debugging it it gives me a error, leaving it as string works out.

the lblAccess wud be visible if I enter the correct password, and the form will appear up.
 
Conversion from string "sausage" to type 'Integer' is not valid, it highlights the password part. yeh lblAccess is a created label.
 
yep, so that is a data type mismatch error(you are trying to use both string and numeric data on a string variable)
Try my code, with frmMain.Show replaced by lblAccess.Visible = True
 
yep, so that is a data type mismatch error(you are trying to use both string and numeric data on a string variable)
Try my code, with frmMain.Show replaced by lblAccess.Visible = True

Thanks, I tried debugging but the password dialog still doesn't appear first, dont know where im going wrong. A real noob here lol
 
Have you set the startup object correctly?
When the project starts, it should execute the above code procedure first.

EDIT:
I think it is in the IDE, project options section.
 
Would this be right, just uploaded a pic:


I've selected the Set as Startup project, ran it but still doesnt show up first.
 
Have two forms. A main one and a startup one that shows the password entry box. Then on the first form show the second form and use Me.hide to hide the startup one.
 
Back
Top Bottom