There are alot of things which doesn't need to type alot of junk code while our task can be completed without declaring useless variables, constants, etc plus they use alot of resources when we run our executable so i decided to put some simple codes here which can achive our task easily
1-Description: Prevents than one instance of an application from running
'Place the following code in a Form_Load() or Sub Main()
If App.PrevInstance = True Then
Unload Me
*********************************************************************************
2-'Description: Unloads an application properly ensuring restoration of resources
'Place the following code in a Form_Unload()
Dim i as integer
While forms.Count > 1
' Find first form besides "me" to unload
i = 0
While forms(i).Caption = Me.Caption
i = i + 1
Wend
Unload forms(i)
Wend
' Last thing to be done...
Unload Me
End
*********************************************************************************
3- Description: Function returns True if date falls on a weekend
'Public Function IsWeekend(ByVal vntDate As Variant) As Boolean
Dim bResult As Boolean
If IsDate(vntDate) Then
If (WeekDay(vntDate) Mod 6 = 1) Then bResult = True Else bResult = False
Else
Err.Raise 13, "Type Mismatch, Must Be Date"
End If
IsWeekend = bResult
'End Function
*********************************************************************************
4- Description: Function returns True if year is a leap year
'Function IsLeapYear(ByVal sYear As String) As Boolean
If IsDate("02/29/" & sYear) Then
IsLeapYear = True
Else
IsLeapYear = False
End If
'End Function
*********************************************************************************
5- 'Description: Detects if a file exists.
'Function FileExists (filename As String) As Integer
On Error Resume Next
x% = Len(Dir$(filename))
If Err Or x% = 0 Then FileExists = False Else FileExists = True
'End Function
*********************************************************************************
6- Description: Determines screen resolution
CR$ = Chr$(13) + Chr$(10)
TWidth% = screen.Width \ screen.TwipsPerPixelX
THeight% = screen.Height \ screen.TwipsPerPixelY
MsgBox "Screen Resolution:" + CR$ + CR$ + Str$(TWidth%) + " x" + Str$(THeight%), 64, "Info"
*********************************************************************************
7- 'Description:Hide Mouse & Show Mouse
'put this in your module
Declare Function ShowCursor& Lib "user32" _
(ByVal bShow As Long)
'Add this code to Command1.
Private Sub Command1_Click()
ShowCursor (bShow = True)
End Sub
'Add this to Command2.
Private Sub Command2_Click()
ShowCursor (bShow = False)
End Sub
*********************************************************************************
8- Description: Opens / Closes the CD drive door without OCX
'Private Declare Function mciSendString Lib "winmm.dll" Alias_
"mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
'Open CD drive door
retvalue = mciSendString("set CDAudio door open", returnstring, 127, 0)
'Close CD drive door
retvalue = mciSendString("set CDAudio door closed", returnstring, 127, 0)
*********************************************************************************
9- Description: Hide Application from Task Manager
App.Taskvisible=false