Common Visual Basic Codes

What to do:

Code to do it:

how to make a password checker:

you need 1 text box and 1 command button, in the command button   type this code:


If text1.text = "your password(choose one)" then
Msgbox "Your password was correct!"
end
end if
If text1.text <>  "your password" then
Msgbox "Your password was not correct. Check your password and try again later."
end
end if

how to make a message box appear when you load a program:

double click the form and type in the following code in Form_Load:

Msgbox "Whatever you want it to say"
end

how to make a message box keep on appearing after you press ok:

double click the form and type in the following code in Form_Load:

Do
Msgbox "What you wanna say"
Loop

how to make a form unload after 5 seconds:

you need 1 timer
set the interval of the timer to 5000
double click the timer and type in the following code:


Unload Me

how to center a form on the screen:

double click the form and type the following code in Form_Load:

Form1.Move(Screen.width-form1.width)\2,(screen.height-form1.height)\2

how to center a form at the top of the screen:

double click the form and type in the following code in Form_Load:

Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / (Screen.Height)

how to make a form always stay on top:

Dim lRetVal As Long

lRetVal = SetWindowPos(form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOSIZE Or SWP_NOMOVE)

Paste the following code into a module:

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1


how to scroll caption on titlebar:

Sub TitleScroll(frm As Form) Dim X As Integer


Dim current As Variant
Dim Y As String
Y = frm.Caption
frm.Caption = ""
frm.Show
For X = 0 To Len(Y)
If X = 0 Then
frm.Caption = ""

current = Timer