Posts Tagged ‘vb.net’
How to replace one or more whitespace in vb.net
Posted by: admin in .NET, Regular Expression (NET) on September 1st, 2011
-
Imports System.Text.RegularExpressions</p>
-
Module Example
-
Public Sub Main()
-
Dim input As String = "This is text with far too much " +
-
"whitespace."
-
Dim pattern As String = "\s+"
-
Dim replacement As String = " "
-
Dim rgx As New Regex(pattern)
-
Dim result As String = rgx.Replace(input, replacement)
-
Console.WriteLine("Original String: {0}", input)
-
Console.WriteLine("Replacement String: {0}", result)
-
End Sub
-
End Module
How to use Bitwise in Vb.Net
Enum eStatusNumber
One = 1
Two = 2
Three = 4
Four = 16
Five = 32
End Enum
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Test(eStatusNumber.Five Or eStatusNumber.Three)
End Sub
Private Sub Test(ByVal com As eStatusNumber)
If (com And eStatusNumber.One) = eStatusNumber.One Then
MsgBox("One")
End If
If (com And eStatusNumber.Two) = eStatusNumber.Two Then
MsgBox("Two")
End If
If (com And eStatusNumber.Three) = eStatusNumber.Three Then
MsgBox("Three")
End If
If (com And eStatusNumber.Four) = eStatusNumber.Four Then
MsgBox("Four")
End If
If (com And eStatusNumber.Five) = eStatusNumber.Five Then
MsgBox("Five")
End If
End Sub
VB.Net code can be downloaded here "EnumBitWise Sample".
Reference 1
Reference 2
How to generate random colors in vb.net
Module RandomColors
Public Function GetRandomQBColor() As System.Drawing.Color
Dim rndom As New Random
Dim color_num As Integer = rndom.Next(0, 15)
Return System.Drawing.Color.FromArgb(QBColor(color_num) + &HFF000000)
End Function
Public Function GetRandomRGBColor() As System.Drawing.Color
Dim rndom As New Random
Return System.Drawing.Color.FromArgb(255, rndom.Next(0, 255), rndom.Next(0, 255), rndom.Next(0, 255))
End Function
End Module
How to open the windows explorer programmatically in .net
How to open the windows explorer using vb.net
-
System.Diagnostics.Process.Start("explorer.exe", "c:\tmp")
How create a Container User Control
Posted by: admin in .NET, User Control on December 28th, 2010
-
Imports System.ComponentModel
-
Imports System.ComponentModel.Design
-
-
<Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
-
Public Class UserControl1
-
-
End Class
How to select a row in GridView
-
<asp:GridView ID="GridViewCategory" runat="server" AutoGenerateColumns="False"
-
DataKeyNames="CategoryID"
-
EmptyDataText="There are no data records to display."
-
CssClass = "GridViewStyle"
-
AlternatingRowStyle-CssClass="alt"
-
PagerStyle-CssClass="pgr"
-
SelectedRowStyle-CssClass="selected"
-
Width="100%" onrowdatabound="GridViewCategory_RowDataBound"
-
>
-
<Columns>
-
<asp:TemplateField HeaderText="ID">
-
<ItemTemplate>
-
<asp:LinkButton ID="lnkSelect" runat="server" CommandName="Select" CommandArgument='<%# Bind("CategoryID") %>' Text='<%# Bind("CategoryID") %>'></asp:LinkButton>
-
</ItemTemplate>
-
<ItemStyle Width="50px" />
-
</asp:TemplateField>
-
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
-
</Columns>
-
<PagerStyle CssClass="pgr" />
-
<AlternatingRowStyle CssClass="alt" />
-
</asp:GridView>
Code behind:
-
protected void GridViewCategory_RowDataBound(object sender, GridViewRowEventArgs e)
-
{
-
if (e.Row.RowType == DataControlRowType.DataRow)
-
{
-
LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[1];
-
-
e.Row.Attributes.Add("onClick", ClientScript.GetPostBackClientHyperlink(lb, ""));
-
e.Row.Attributes.Add("onMouseClick", "javascript:this.style.cursor='pointer';");
-
e.Row.Attributes.Add("onMouseOut", "javascript:this.style.cursor='normal';");
-
}
-
}
or
if you did not put a SELECT command button in the gridview, you can use the following code to mimic the Select function
-
protected void GridViewCategory_RowDataBound(object sender, GridViewRowEventArgs e)
-
{
-
if (e.Row.RowType == DataControlRowType.DataRow)
-
{
-
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
-
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
-
-
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridViewCategory, "Select$" + e.Row.RowIndex);
-
}
-
}
How to Debug Window Service without installing
Posted by: admin in .NET, Window Services on September 3rd, 2010
Usually if we want to debug the windows service project to see if it is behaving as we expected, what we do is by installing the windows service and attaching that project to the process.
There is also another way to debug without installing it, what we need to do is by creating another project such as console project then copy and paste the code below.
-
Sub Main()
-
#If Not Debug Then
-
Dim servicesToRun As System.ServiceProcess.ServiceBase()
-
-
servicesToRun = New System.ServiceProcess.ServiceBase() {New MyService()}
-
System.ServiceProcess.ServiceBase.Run(servicesToRun)
-
#Else
-
Dim service As AS2Client.AS2SenderService = New MyService()
-
service.myentrysub()
-
-
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
-
-
#End If
-
-
-
-
End Sub
References:
Run Windows Service as a Console program