vb

 

    Public Shared Function ToDateEOM(ByVal dt As Object) As DateTime
        '//-- หาวันที่สิ้นเดือน EndOfMonth โดยใช้รูปแบบตาม culture ดังนี้
        '//-- ถ้า CultureName en-US ต้องเป็น MM/dd/yyyy (ปีใช้คศ)
        '//-- ถ้า CultureName en-GB ต้องเป็น dd/MM/yyyy (ปีใช้คศ)
        '//-- ถ้า CultureName th-TH ต้องเป็น dd/MM/yyyy (ปีใช้พศ)
        Dim tmpDate As DateTime
        Try
            tmpDate = System.DateTime.Parse(dt.ToString())
            Return DateSerial(Year(tmpDate), Month(tmpDate) + 1, 1).AddDays(-1)
        Catch
            Return DateTime.MinValue
        End Try
    End Function

'//Module
Declare Function SHGetSpecialFolderLocation Lib "Shell32.dll" _
  (ByVal hwndOwner As Long, ByVal nFolder As Long, _
  pidl As ITEMIDLIST) As Long

Declare Function SHGetPathFromIDList Lib "Shell32.dll" _
  Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
  ByVal pszPath As String) As Long

Public Type SH_ITEMID
    cb As Long
    abID As Byte
End Type

Public Type ITEMIDLIST
    mkid As SH_ITEMID
End Type
' The Desktop - virtual folder
Public Const CSIDL_DESKTOP = &H0
' Program Files
Public Const CSIDL_PROGRAMS = 2
' Control Panel - virtual folder
Public Const CSIDL_CONTROLS = 3
' Printers - virtual folder
Public Const CSIDL_PRINTERS = 4
' My Documents
Public Const CSIDL_DOCUMENTS = 5
' Favorites
Public Const CSIDL_FAVORITES = 6
' Startup Folder
Public Const CSIDL_STARTUP = 7
' Recent Documents
Public Const CSIDL_RECENT = 8
' Send To Folder
Public Const CSIDL_SENDTO = 9
' Recycle Bin - virtual folder
Public Const CSIDL_BITBUCKET = 10
' Start Menu
Public Const CSIDL_STARTMENU = 11
' Desktop folder
Public Const CSIDL_DESKTOPFOLDER = 16
' My Computer - virtual folder
Public Const CSIDL_DRIVES = 17
' Network Neighbourhood - virtual folder
Public Const CSIDL_NETWORK = 18
' NetHood Folder
Public Const CSIDL_NETHOOD = 19
' Fonts folder
Public Const CSIDL_FONTS = 20
' ShellNew folder
Public Const CSIDL_SHELLNEW = 21

Public Const MAX_PATH As Integer = 260

Public Function fGetSpecialFolder(CSIDL As Long) As String
    Dim sPath As String
    Dim IDL As ITEMIDLIST
    '
    ' Retrieve info about system folders such as the
    ' "Desktop" folder. Info is stored in the IDL structure.
    '
    fGetSpecialFolder = ""
    If SHGetSpecialFolderLocation(Form1.hWnd, CSIDL, IDL) = 0 Then
        '
        ' Get the path from the ID list, and return the folder.
        '
        sPath = Space$(MAX_PATH)
        If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
            fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "\"
        End If
    End If
End Function

'//--- Sample

Debug.Print "Desktop Folder " & fGetSpecialFolder(CSIDL_DESKTOPFOLDER)

 

http://vbcity.com/forums/topic.asp?tid=1393

Function HHMM(dMinute As Long) As String
 Dim dHH As String
 Dim dMin As String
 dHH = dMinute \ 60
 dMin = dMinute Mod 60
 If Val(dMin) < 10 Then
   dMin = "0" & dMin
 End If
 HHMM = dHH & ":" & dMin
End Function

edit @ 1 Apr 2008 10:34:12 by theera