I have a code:

Private Sub OK_Click()


Dim Username As String

Username = InputBox("Username")

If Username = "Martyna" Then
MsgBox "Welcome, " & Username

Else: MsgBox "Sorry, access is denied, please Check your username and try again"

End If
End Sub

and it should ask 3 time for username then if it's not correct display message : 'sorry, access is denied, please Check your username and try again'

i have to use loop but i dont know how to do it.
any help?

1. declare a byte variable
2. check the value for 3>= before prompting for inputbox
3. increment the value by by 1 after the inputbox

do you know, using looping condition is so hard to code,, but lets try to search.... i know it have article that can help you.... gudluck

' Try this do while loop

I have a code:

Private Sub OK_Click()


Dim Username As String
dim cnt as integer

cnt=1
do while (cnt<=3)

Username = InputBox("Username")

If Username = "Martyna" Then
MsgBox "Welcome, " & Username
exit do

Else: MsgBox "Sorry, access is denied, please Check your username and try again"
cnt=cnt-1
End If
loop

End Sub

and it should ask 3 time for username then if it's not correct display message : 'sorry, access is denied, please Check your username and try again'

i have to use loop but i dont know how to do it.
any help?

Put that in sub main, and add Form1.show before your exit do...


Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.