![]()
This area is brand new and would like contributors. As of now, I will supply my own favorites. Also, I am planning on a search interface and until then, I'll post excerpts when ever I can make time. The following were requested most.
Please send your code tips to TipsTricks@pcgcorp.com
![]()
If you require further assistance with any of these routines, I can send the complete Classes.
| Giving your VB Toolbar a face lift (Explorer Style) |
| Sub
MakeToolBarFlat(tbMain As Object) Dim hwnd As Long, style As Long Dim result As Long ' Find child window and get style bits hwnd = FindWindowEx(tbMain.hwnd, 0&, "ToolbarWindow32", vbNullString) style = SendMessage(hwnd, TB_GETSTYLE, 0&, 0&) ' Get the effect style = style Or TBSTYLE_FLAT ' Use the API to set the new style result = SendMessage(hwnd, TB_SETSTYLE, 0, style) tbMain.Refresh End Sub |
| Get the User's Workstation name |
| Public
Function Workstation() As String On Error GoTo WorkstationErr ' Added on 7/15/98 5:52:31 PM -- %MJC% ' Dim PCName As String Dim x As Long PCName = Space$(256) x = GetComputerName(PCName, Len(PCName)) PCName = Trim(PCName) Workstation = LCase(Left(PCName, Len(PCName) - 1)) Exit Function ' %MJC% WorkstationErr: ' %MJC% MsgBox "CSettings::Workstation()" ' %MJC% Exit Function ' %MJC% End Function |
| Excerpt of a Binary Search, Linear Search, and Sorting from my CArrayRecordset Class. |
| Private Function BinarySearch(ColIndex As Integer, StrValue As
Variant) Dim Median As Long, Low As Long, Hi As Long 'If you have an Array with 1000 elements, it could take 1000 iterations before finding the result. Ouch, however, with a binary search, you start at the middle 500 then determine wheather to go lower or higher. At that point your next stop is 250 or 750 and so on. After the first iteration, you've eliminated 500 records!!! Low = 0
' If the minimum number of
elements in the array is |
| Simple Hex Format Function |
| Public Function LngToHex(n As Long) As Long Dim sValue As String Dim nValue As String Dim Index As Integer nValue = Hex$(n) 'Padding For Index = 1 To 8 - Len(nValue) nValue = "0" & nValue Next Index sValue = "&H" For Index = 4 To 1 Step -1 sValue = sValue + Mid$(nValue, Index * 2 - 1, 2) Next LngToHex = Val(sValue) End Function |
Excerpt
from my CSQLAssist Class |
| Function
InsertParam(SQL As String, ParamValue As Variant, Optional StartPos As Integer) On Error GoTo InsertParamErr Dim n As Integer If StartPos = 0 Then StartPos = 1 n = InStr(StartPos, SQL, "?") If n = 0 Then InsertParam = SQL Exit Function End If InsertParam = Mid(SQL, 1, n - 1) & ParamValue & Mid(SQL, n + 1) Exit Function InsertParamErr: MsgBox "InsertParam(" & ParamValue & ")" & "Unable to Insert Parameter Into " & SQL Exit Function End Function |
| ADO -- Working with recordsets offline then marshall them back when your done |
| 'Local Objects Function LoadJobs(nJobID as Long) Dim ObjSvr as CMiddlerTier Dim rs as ADODB.Recordset set rs = ObjSvr.GetJob(nJobID) rs.edit ObjSvr.SaveJob rs 'Business Objects set rs.ActiveConnection = cn Function
LoadByJobID(nID As Long) as Object 'Replace "'% if you are
using as a COM Object under MTS cn.Close ' Close the
connection |