Get month name from integer VB.NET

On January 2, 2009, in Programming, by Mike Hudson

Use this simple VB.NET code to return the name of the month from an integer.
Example: 1 = January ….. 12 = December

Private Function GetMonthName(ByVal monthNum As Integer) As String
Try
Dim strDate As New DateTime(1, monthNum, 1)
Return strDate.ToString("MMM")
Catch ex As Exception
End Try
End Function
Tagged with:  

File size calculator

On January 2, 2009, in Programming, by Mike Hudson

Use this simple VB.NET code to convert bytes to MB’s, GB’s etc. Handy for returning sizes of files/folders

Function ConvertSize(Size)
Do While InStr(Size,",") 'Remove commas from size
CommaLocate = InStr(Size,",")
     Size = Mid(Size,1,CommaLocate - 1) & _
       Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate)
       Loop</p> <p>Suffix = " Bytes"

   If Size >= 1024 Then suffix = " KB"
   If Size >= 1048576 Then suffix = " MB"
   If Size >= 1073741824 Then suffix = " GB"
   If Size >= 1099511627776 Then suffix = " TB" 

        Select Case Suffix
            Case " KB" Size = Round(Size / 1024, 1)
            Case " MB" Size = Round(Size / 1048576, 1)
            Case " GB" Size = Round(Size / 1073741824, 1)
            Case " TB" Size = Round(Size / 1099511627776, 1)
        End Select

        ConvertSize = Size & Suffix

End Function
Tagged with:  

Get current username VBScript

On December 26, 2008, in Programming, by Mike Hudson

Use this really simple VBScript to get the currently logged on user name.

Set wshNetwork = CreateObject("WScript.Network")
strUser = wshNetwork.Username
WScript.Echo "Current User: " & strUser
Tagged with:  

List operating system properties VBScript

On December 26, 2008, in Programming, by Mike Hudson

Use this fairly simple VBScript to list general opearating system properties.

' List Operating System Properties
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}" & strComputer & "rootcimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice
Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber
Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
Wscript.Echo "Caption: " & objOperatingSystem.Caption
Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet
Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
Wscript.Echo "Debug: " & objOperatingSystem.Debug
Wscript.Echo "Encryption Level: " & objOperatingSystem.EncryptionLevel
dtmConvertedDate.Value = objOperatingSystem.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDate
Wscript.Echo "Install Date: " & dtmInstallDate
Wscript.Echo "Licensed Users: " & _
objOperatingSystem.NumberOfLicensedUsers
Wscript.Echo "Organization: " & objOperatingSystem.Organization
Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite
Wscript.Echo "OS Type: " & objOperatingSystem.OSType
Wscript.Echo "Primary: " & objOperatingSystem.Primary
Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
Wscript.Echo "Version: " & objOperatingSystem.Version
Next
Tagged with:  

Create an Internet Explorer Favorite VBScript

On December 26, 2008, in Programming, by Mike Hudson

Use this simple script to create an internet explorer favorite link to the Microsoft MSDN library.

Const ADMINISTRATIVE_TOOLS = 6
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS)
Set objFolderItem = objFolder.Self 
Set objShell = WScript.CreateObject("WScript.Shell")
strDesktopFld = objFolderItem.Path
Set objURLShortcut = objShell.CreateShortcut(strDesktopFld & "MSDN.url"
objURLShortcut.TargetPath = "http://msdn.microsoft.com"
objURLShortcut.Save
Tagged with:  

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!