Archive for the ‘VB.Net’ Category

How to convert .net Form to Image
  1. Public Class Form1
  2.  
  3.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  4.         CreateBitmap(Me)
  5.     End Sub
  6.  
  7.     Private Sub CreateBitmap(ByVal con As Control)
  8.         'Dim g As Graphics = Me.CreateGraphics()
  9.  
  10.         Dim b As Bitmap = New Bitmap(Me.Width, Me.Height)
  11.         Me.DrawToBitmap(b, New Rectangle(0, 0, Me.Width, Me.Height))
  12.  
  13.         b.Save("test.jpg", Imaging.ImageFormat.Jpeg)
  14.         b.Dispose()
  15.         'g.Dispose()
  16.     End Sub
  17. End Class

, ,

No Comments


Enum: How to get the underlying value given the name

Use Parse method of the enum to get the value:

Enum x
a = 1
b = 2
End Enum

dim e as x

e = [enum].Parse(GetType(x), “a”)

,

No Comments


The following text is not allowed in this context:

This exception occurs when there is an extra string / character outside the element of the schema,

example:

schema_error

,

No Comments


InvalidOperationException : There was an error in XML document

This error occurred when there is an invalid character on the data. Before adding/saving to the datatable you need to replace the invalid character. The known invalid character is the null.

To replace it in vb.net
dim mData As string
Strings.Replace(mData, vbNullChar, “”)

No Comments


How to Convert Arraylist to String using .Net
  1. Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList) As String
  2.  Return ArrayListToString(ar, ","C)
  3. End Function
  4.  
  5. Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As Char) As String
  6.  Return ArrayListToString(ar, delim.ToString)
  7. End Function
  8.  
  9. Public Overloads Function ArrayListToString(ByVal ar As System.Collections.ArrayList, ByVal delim As String) As String
  10.  Return String.Join(delim, CType(ar.ToArray(GetType(String)), String()))
  11. End Function

, , ,

No Comments


How to convert string to Hex
  1. Function HexToDec(ByVal value As String) As Long
  2.     ' we just need a call to the Convert.ToInt64 static method
  3.     Return Convert.ToInt64(value, 16)
  4. End Function

,

No Comments


How to restart application in vb.net

Use application.restart

,

No Comments


Exception: Thread was being aborted

Try using flush method instead of end method of object.

Read Forum

, ,

No Comments


How to Replace Multiple space with only one space

Use regular expression

RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@”[ ]{2,}”, options);
tempo = regex.Replace(tempo, @” “);

VB.Net

Dim str As String = “Sample space 01″
Dim opts As RegexOptions = RegexOptions.None
Dim regx As New Regex(”[ ]{2,}”, opts)

str = regx.Replace(str, ” “)

,

No Comments


Subtracting Days of the Date

To subtract the date with a specified number of days, use the built in shared function of the Date which Date.Today.Add(Days), where Days is a day number. Instead of passing a positive number of days, put a negative sign in it.

Example to subtract 2 days from the current date.

Date.Today.Add(-2)

or you can also use the DateAdd() function and pass a negative day number.

,

No Comments



SetPageWidth