Archive for the ‘VB.Net’ Category
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, ” “)
Subtracting Days of the Date
Posted by: admin in .NET, C#, Date Formatting, VB.Net on May 26th, 2009
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.
How to assign Null Values to Date Type Variable in .Net
Posted by: admin in .NET, Date Formatting, VB.Net on May 18th, 2009
Actually, you can’t assign a null value to a Date Type variable but you can check if the variable has been set or not by comparing its current value versus default value (#12:00:00 AM#) of date/datetime, you can get the default value by using
-
Date.MinValue or DateTime.MinValue
To do this, let say you have a variable called LastUpdate with a data type of Datetime
-
Dim LastUpdate as DateTime
-
dim dr as Datarow
-
-
If DateTime.MinValue = LastUpdate Then
-
'Its Null value
-
'if you want to save the value to the database then use the DBNull.Value
-
dr("LastUpdate") = DBNull.Value
-
Else
-
dr("LastUpdate") =LastUpdate
-
End If
Operation Timeout on GetRequestStream
Resolution:
1. Just make sure the HttpWebResponse instance is closed. Example you have this
-
Dim Response As HttpWebResponse
-
-
Response = wr.GetResponse()
-
-
'You have to close Response
-
Response.Close
How to Convert String to Date Format
Posted by: admin in .NET, C#, Date Formatting, String Manipulation, VB.Net on May 3rd, 2009
To Convert String To Date Format, use the DateTime.ParseExact function
DateTime.ParseExact(s as String, format as String, provider As IFormatProvider) as DateTime
Parameters:
- s
- Type: System.String
A string that contains a date and time to convert.
- format
- Type: System.String
A format specifier that defines the required format of s.
- provider
- Type: System.IFormatProvider
An object that supplies culture-specific format information about s.
Example:
-
Private Function ToDate() As DateTime
-
-
Dim str As String = "20060505"
-
-
Dim mDate As DateTime
-
-
-
-
mDate = DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
-
-
Return mDate
-
-
End Function
Read More about DateTime.ParseExact Method (String, String, IFormatProvider)
How to create Temporary filename in vb.Net
-
Private Sub TempFile()
-
Dim sTempFileName AsString = System.IO.Path.GetTempFileName()
-
Dim fsTemp AsNew System.IO.FileStream(sTempFileName, IO.FileMode.Create)
-
-
MessageBox.Show(sTempFileName)
-
-
'write data to the temp file
-
fsTemp.Close()
-
-
System.IO.File.Delete(sTempFileName)
-
End Sub
How to Insert Xml Node from One document to another XML Document in vb.net
If you want to insert xmlnode from one document to another, you have to import the xmlnode.
dim xmlDoc01 as XMLDocument
dim xmlDoc02 as XMLDocument
private sub InsertNod() ’insert xmlnode from xmlDoc01 to xmlDoc02
{
xmldoc01.AppendChild(xmlDoc01.ImportNode(xmlDoc01.ChildNodes(0), true))
}