Showing posts with label g7bmp. Show all posts
Showing posts with label g7bmp. Show all posts

Wednesday, 24 July 2013

Part of the Day

This is the best way to find the time of day to put into a letter.


dim hours as int = DateTime.Now.Hour
dim str as string
if hours < 12 Then
    str = "Morning"
else if hours < 17 then
    str = "Afternoon"
else if hours > 17 then
    str = "Evening"
End If

Tuesday, 25 June 2013

Insert Row with Identity


To insert values with a specific id use the following code this will insert a line of data with a defined id.

Beware whilst this is running NO AUTO IDENT WILL WORK keep every one away from this table.

SET IDENTITY_INSERT Table name ON

 INSERT table name (UID, Value) VALUES (2006, 'any value')

 SET IDENTITY_INSERT Table name OFF


If this fails due to a syntax error in the insert statement then  the Identity will remain OFF


Thursday, 13 June 2013

Check if process is running

I had a need to check if a process was running so a quick Google gave me this which worked a treat
Thanks to  http://social.msdn.microsoft.com

Dim p() As Process

Private Sub CheckIfRunning()
    p = Process.GetProcessesByName("processName")
    If p.Count > 0 Then
     ' Process is running
    Else
        ' Process is not running
    End If
End Sub

Monday, 13 May 2013

Count mail messages in exchange queue VB.NET



To monitor for long queues in the SMTP mail on exchange (works on 2003) find the queue  folder on the exchange server and note its path.

in you VB project add this to a timer.


dim mypath as string
mypath = "\\mailservername\d$\Program Files\Exchsrvr\Mailroot\vsi 1\Queue"

Dim counter = My.Computer.FileSystem.GetFiles(mypath)

if counter > 'What ever you decide 
 'do something
end if

and their you have it if your queue gets clogged up for any reason then you will be alerted.

How to count files in a folder in VB.net




This extract is taken from MSDN



Dim counter = My.Computer.FileSystem.GetFiles("C:\TestDir")

As simple as that 

Wednesday, 8 May 2013

Send e-mail from Outlook from VB.NET

 To create an Outlook e-mail message in VB.net (2005)

Imports Microsoft.Office.Interop



  Dim OutlookMessage As Outlook.MailItem
        Dim AppOutlook As New Outlook.Application
        Try
            OutlookMessage = AppOutlook.CreateItem(Outlook.OlItemType.olMailItem)
            Dim Recipents As Outlook.Recipients = OutlookMessage.Recipients
            Recipents.Add("nick.gough@sprintcare.com")
            OutlookMessage.Subject = comid
            OutlookMessage.Body = "Testing outlook Mail"
            OutlookMessage.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
            OutlookMessage.Attachments.Add(myfile)
'##use  this to ----- to Open the message for editing
            OutlookMessage.Display() 

or
            OutlookMessage.Send()
to send message
        Catch ex As Exception
            MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line
        Finally
            OutlookMessage = Nothing
            AppOutlook = Nothing
        End Try

Tuesday, 7 May 2013

Use string builder to create connection string.


 Use this string builder to create your Sql connection string


Public Function CreateConnectionString(ByVal strUserName As String, ByVal strPassword As String) As String
        On Error GoTo err
        Dim strConnBuilder As New SqlConnectionStringBuilder


        With strConnBuilder
            .ApplicationName = "Your Application Name"
            .AsynchronousProcessing = False
            .ConnectTimeout = 20
            .IntegratedSecurity = True
            .NetworkLibrary = "DBMSSOCN"
            .MinPoolSize = 1
            .MaxPoolSize = 50
            .DataSource = "Your SQL server name or IP Address"
            .InitialCatalog = "Your database name"

        End With
        Return strConnBuilder.ConnectionString
        Exit Function
err:
        errormsg("SysModule-CreateConnectionString" & Err.Description)
    End Function


Call somthing like this
 sqlCon1 As New SqlConnection(CreateConnectionString("", ""))

Switch on/ off Non Delivery Reports (NDR) Exchange 2003


To switch off/on NDR's in Microsoft Exchange

  1. Open the Exchange system Management Console.
  2. Expand global settings in the tree.
  3. Click Internet Message Format
  4. Right click the mail format in the right pane (probably Default) and select properties.
  5. Select the advanced tab.
  6. Check or uncheck the Allow non-delivery reports
  7. Press OK.

Thursday, 4 April 2013

Microsoft Office Compatibility


If you have an old version of Microsoft Office and can not open some of the documents you are receiving then download and install the
Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint File Formats from
http://www.microsoft.com/en-us/download/details.aspx?id=3

This will allow you to view these documents.

Thursday, 21 March 2013

Auto open Date Picker



This is one method for auto expanding a date time picker in VB.NET

DateTimePicker1.Focus()

 SendKeys.Send("{F4}")





This is copied from an article from Hans Passant

Multi Point USB Charger

  USB Plug Charger, 4-Port USB Fast Charger Plug with 33W Intelligent Quick Charge 3.0 Wall Charger, Multi USBPower Adapter UK Fast Charging...