Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Excel VBA Incrementing Code [HELP]

Patch2012

Professional
Advanced Member
Messages
195
Reaction score
0
Points
26
'mga master any idea how to increment vba in excel


Private Sub CommandButton1_Click()

Dim Usname, Pass As String

Usname = Unamebox
Pass = Pwordbox


If Usname = "test1" And Pass = "test" Then
MsgBox "Login Success", vbInformation
Unload Me
i = 1

Else
MsgBox "Access Denied", vbCritical
i = i + 1

End If

If i = 2 Then
ActiveWorkbook.Close


End If


End Sub
 
- ideclare mo muna si i, since gusto mo sya mag-hold ng number (whole number), declare it as integer

- initialize a value for i, hindi ka makakapag-increment ng value nang hindi mo alam kung ano ang original value nito.

- wag mo ilagay sa loob ng command button yun declaration at initialization ng value ng i, dahil magpapa-ulit ulit ka lang ng value.

- REMOVE mo na yung i = 1 dun sa loob ng **If Usname = "test1" And Pass = "test" Then**, useless yun dahil ang gusto mo bilangin ay yung incorrect password guesses di ba?
 
Ang trigger ng checking kung tama ang username at password ay yung click ng command button.
 
Dim i As Integer 'declare mo to as general sa form mo, para mag sisilbing counter mo

Public Sub LogInButton_click()
Dim Usname, Pass As String

'yung textbox mo palitan mo ung name to UserTxtbox and PassTxtBox

If VerifyUserPass(UserTxtbox.Value, PassTxtBox.Value) = True Then 'eto function to para iverify yung password at username
MsgBox " YEY LOGIN NA"
Else
i = i + 1
End If
'etong isxceeded function is to get the value of i and then return if true
If isExceeded(i) = True Then
MsgBox "You Exceeded the number of log in"
ActiveWorkbook.Close
Exit Sub
End If
End Sub
Public Function VerifyUserPass(username As String, password As String) As Boolean
If username = "Test1" And password = "test" Then
VerifyUserPass = True
Else
VerifyUserPass = False
End If
End Function
Public Function isExceeded(i As Integer) As Boolean
If i = 2 Then
isExceeded = True
Else
isExceeded = False
End If
End Function
 
Back
Top Bottom