convert to binary
March 25, 2009 by admin
Filed under Visual Basic
Public Function CBin(ByVal Nr As Long, Optional Precision As Integer =
As String
Do Until Nr = 0
CBin = CStr((Nr Mod 2)) + CBin
Nr = Nr 2
Loop
CBin = Format(Val(CBin), String(Precision, “0″))
End Function
Private Sub Form_Load()
MsgBox CBin(88)
End Sub
bytes to whatever
March 23, 2009 by admin
Filed under Visual Basic
Function SetBytes(Bytes) As String
On Error GoTo errorhandler
If Bytes >= 1073741824 Then
SetBytes = Format(Bytes / 1024 / 1024 / 1024, “#0.00″) _
& ” GB”
ElseIf Bytes >= 1048576 Then
SetBytes = Format(Bytes / 1024 / 1024, “#0.00″) & ” MB”
ElseIf Bytes >= 1024 Then
SetBytes = Format(Bytes / 1024, “#0.00″) & ” KB”
ElseIf Bytes < 1024 Then
SetBytes = Fix(Bytes) & ” Bytes”
End If
Exit Function
errorhandler:
SetBytes = “cannot compute”
End Function
Private Sub Form_Load()
MsgBox SetBytes(1100)
End Sub
change windows wallpaper
March 22, 2009 by admin
Filed under Visual Basic
Declare Function SystemParametersInfo Lib “user32″ Alias “SystemParametersInfoA” (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SETDESKWALLPAPER = 20
Dim lngSuccess As Long
Dim strBitmapImage As String
strBitmapImage = “h:windowsstraw.bmp”
lngSuccess = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strBitmapImage, 0)
List all printers
March 20, 2009 by admin
Filed under Visual Basic
Place a combo box on a form and enter the following code.
Private Sub Form_Load()
Dim printer
For Each printer In Printers
Combo1.AddItem printer.DeviceName
Next
End Sub
change drive name
March 19, 2009 by admin
Filed under Visual Basic
Private Declare Function SetVolumeLabelA Lib “kernel32″ _
(ByVal lpRootPathName As String, _
ByVal lpVolumeName As String) As Long
Public Function SetVolumeName(sDrive As String, n As String) As Boolean
Dim i As Long
i = SetVolumeLabelA(sDrive + “:” & Chr$(0), n & Chr$(0))
SetVolumeName = IIf(i = 0, False, True)
End Function






















