Category Archives: Source Code

How To: Make the Service Starts Automatically After Install

The Following Code should be added on the Project Installer

Imports System.ServiceProcess

Protected Overrides Sub OnCommitted(ByVal savedState As System.Collections.IDictionary)

MyBase.OnCommitted(savedState)

Dim myController As New ServiceController(“yourServiceName”)

myController.Start()

myController.Close()

End Sub

Advertisements

VBA : Read From XLS File and Return Recordset based on a given Select Statement

Usage Sample:

    Dim oRs As New ADODB.Recordset
    If cmbGov.Text = “” Then
        Set oRs = getXLSSet(“Select * from [Area$]”)
    Else
        Set oRs = getXLSSet(“Select * from [Area$] where Gov = ‘” & cmbGov.Text & “‘”)
    End If
  
    Dim y As Integer
    For y = 1 To oRs.RecordCount
        frmhome.cmbArea.AddItem (oRs.Fields(0).Value)
        oRs.MoveNext
    Next


Function:
‘Function to read XLS Files based on a given select statement
Public Function getXLSSet(sourceStr As String) As Recordset
On Error GoTo Catch
    Dim oRs As ADODB.Recordset, oConn As ADODB.Connection, sConString As String, vValue As Variant
    
    sConString = “Provider= Microsoft.Jet.OLEDB.4.0;” & ” Data Source=” & sXLFile & “;Extended Properties=Excel 8.0;”
    Set oConn = New ADODB.Connection
    
    With oConn
        .CursorLocation = adUseClient
        .Open sConString
    End With
    
    Set oRs = New ADODB.Recordset
    
    With oRs
        .CursorType = adOpenStatic
        .CursorLocation = adUseClient
        .LockType = adLockPessimistic
        .Source = sourceStr
        .ActiveConnection = oConn
        .Open
        .MoveFirst
    End With
    
    ”Work with the RS
        Set getXLSSet = oRs
    
    Exit Function
Catch:
    ‘MsgBox “Can’t Process Your Request” & vbCr _
    ‘& “Please Check you Levels or Excel File”
End Function


MicroStation : Enable/Disbale Fill From VBA

‘Enable Disable Fill
Private Sub btnFill_Click()
   If FillOnOff = False Then
    CadInputQueue.SendKeyin “MDL KEYIN BENTLEY.VIEWATTRIBUTESDIALOG,VAD VIEWATTRIBUTESDIALOG SETATTRIBUTE 0 Fill False”
    FillOnOff = True
   Else
    CadInputQueue.SendKeyin “MDL KEYIN BENTLEY.VIEWATTRIBUTESDIALOG,VAD VIEWATTRIBUTESDIALOG SETATTRIBUTE 0 Fill True”
    FillOnOff = False
   End If
    
    CommandState.StartDefaultCommand
End Sub