VB.NET Tutorials and Code


Count Words In String


  1. Dim ContentString As String = "Arrested Development"
  2. Dim WordCounter As Integer = UBound(Split(Trim(Replace(ContentString, Space(2), Space(1))))) + 1


    Replace Last Occurrence In String

    1. Dim NewString As String
    2. Dim SourceString As String
    3. Dim SearchString As String
    4. Dim ReplaceString As String
    5. NewString = StrReverse(Replace(StrReverse(SourceString), StrReverse(SearchString), StrReverse(ReplaceStr), , 1))
    6. Return (NewString )
    7.  


      Detect multiple instances of the application

      1. 'If we find two or more running processes by the same name
      2. If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
      3.     ' Tell the user he can only have on instance running
      4.     MessageBox.Show("Only one instance of this program can be open at a given time", "Duplicate instance detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
      5.     ' Close the application
      6.     Application.Exit()
      7. End If

        Reference: http://www.geekpedia.com/language20_VB.NET.html


Written by