How to convert HTML Color code to RGB color code

The following VB.Net code converts HTML color code to equivalent RGB color code.

Module modMain
  Public Function ConvertHTMLToRGBColor(ByVal sHtmlColor As String) As Color
    'Remove the # if exists
    sHtmlColor = sHtmlColor.Replace("#", "")
    Return Color.FromArgb(System.Convert.ToInt32(sHtmlColor.Substring(0, 2), 16), System.Convert.ToInt32(sHtmlColor.Substring(2, 2), 16), System.Convert.ToInt32(sHtmlColor.Substring(4, 2), 16))
  End Function
End Module

Tested with VS 2008

Posted in VB.Net | Tagged .net code, convert HTML color code to RGB color code, html color, rgb color, vb.net code | Leave a comment

How to print some data from bas Module

Here is the sample code you can use to print your data from the bas module:

Module modMain
  Dim sText As String
  Public Sub printRecord()
      Dim pDocument As New Printing.PrintDocument
      AddHandler pDocument.PrintPage, AddressOf pd_PrintPage
      sText = "DotNet Blogger - Your favorite Microsoft Visual Studio .Net Programming Blog."
      pDocument.Print()
  End Sub

  Private Sub pd_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
      'this uses a module level variable
      e.Graphics.DrawString(sText, New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, 50, 50)
  End Sub
End Module

Tested with VS 2008

If you found any issues with the code posted above, please leave a comment. We will fix the code as soon as possible.

Posted in VB.Net | Tagged how to print, module, print, print data | Leave a comment

How to open a webpage when we click a button?

To open a webpage in your system’s default web browser, when you click a button in your form, write the following code in your button click event:

Dim sURL as String = "http://www.dotnetblogger.info"
Process.Start(sURL)

The above piece of code will lauch the web page as specified with the default browser.

Tested with VS 2008

If you found any issues with the code posted above, please leave a comment. We will fix the code as soon as possible.

Posted in VB.Net | Tagged button click, How to, open html page from .net, open webpage, open website, VB.Net, vs 2008 code, web page | Leave a comment

How to Check whether the application/process is running or not by passing the process name

Here is the awesome VB.Net code to check whether the application/process is running or not by passing the process name:

Module modMain
  Sub Main()
    'Check whether acrobat is running or not
    If IsProcessRunning("acrobat") Then
      Console.WriteLine("Yes. Acrobat is running")
    Else
      Console.WriteLine("No. Acrobat is not running")
    End If
  End Sub
  Private Function IsProcessRunning(ByVal sProcess As String) As Boolean
    For Each oProc As Process In Process.GetProcessesByName(sProcess)
      Return True
    Next
  End Function
End Module

Project Type: Console
Language: VB.Net
Tested with: VS 2008

Posted in System & API, VB.Net | Tagged application running, c#.net .Net, How to, How to check application running, VB.Net, vb.net code | Leave a comment

How to Write/Create Text file?

Here is the simplest way of creating a new Text file. If the file already exists, then the text will be appended to the existing file.

My.Computer.FileSystem.WriteAllText("Full_Path_of_Your_Text_File.txt","Text you would like to write to text file", True)

The above piece of code will write to a text file. If you would like to overwrite the existing file, if already exists then, the following piece of code will help:

My.Computer.FileSystem.WriteAllText("Full_Path_of_Your_Text_File.txt","Text you would like to write to text file", False)

Tested with VS 2008

If you found any issues with the code posted above, please leave a comment. We will fix the code as soon as possible.

Posted in .Net, VB.Net | Tagged .net code, create text file, dotnet code, text file, vb.net code, write text file, write text to a flat file | 1 Comment