How to get the current path using VBScript

To get the current path using VBScript you can use the snippet below.

Samples

VBScript Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to catch specific MS-SQL SQLExceptions in C# and VB.NET

To catch specific SQLExceptions using Microsoft.NET and Microsoft Sequel Server you can use the snippet below. You also need to look for the specific error numbers/codes you want to catch. To do this you can either execute the following query in the SQL Management Studio or you can use this
List of SQLException Numbers/Codes (Direct-DL around 15mb).

Samples

T-SQL Sample

C# Sample

VB.NET Sample

Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5not working .NET 4.6

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to extract a password protected zip file using DotNetZip in C# and VB.NET

To extract (unzip) a password protected zip file using the Ionic DotNetZip Library, you can use the snippet below.

Samples

[tab name=”C# Sample”]

[/tab]
[tab name=”VB.NET Sample”]

[/tab]

[end_tabset]

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

Top 10 reads of July 2015

These are our Top 10 reads of July 2015.

  • How to match strings using wildcards in C# and VB.NET
  • IsSmallerThan generic extension method for C# and VB.NET
  • How to prevent your IOS app from going into sleeping mode using Objective-C
  • How to convert Color to Hex and Hex to Color using C# and VB.NET
  • How to read a embedded resource to String in C# and VB.NET
  • How to convert a Securestring to String using C# and VB.NET
  • How to change the encoding of a String using C# and VB.NET
  • How to get focusedrow cell value using Devexpress XtraGrid in C# and VB.NET
  • How to get the selected row index in Devexpress Xtragrid Control using C# and VB.NET
  • thanks to all visitors, bookmark us, share us, talk about us, Follow us!, Like us! let’s grow bigger! You can even participate in our Github Projects!

    Please rate this snippet

    Left, Right, Mid methods for C#

    This snippet let’s you use the Left, Right, Mid methods known from VisualBasic in C# without referencing Microsoft.VisualBasic Namespace.

    public static string Left(string input, int index)
    {
    	return input.Substring(0, index);
    }
    public static string Right(string input, int index)
    {
    	return input.Substring(input.Length - index, index);
    }
    
    public static string Mid(string input, int startingIndex, int endingIndex)
    {
    	return input.Substring(startingIndex, endingIndex);
    }
    
    public static string Mid(string input, int startingIndex)
    {
    	return input.Substring(startingIndex);
    }
    

    Please rate this snippet

    How to show and select a file in explorer using VBA

    To show and select a file in explorer using VBA you can use the following snippet.
    This snippet should also work in VB6.

    Sample VBA

    Dim path As String
    Dim explorerPath As String
    Dim cmd As String
    
    explorerPath = Environ$("WINDIR") + "\Explorer.exe "
    path = "C:\Users\Codesnippets\Desktop\test\Test.xml"
    cmd = explorerPath + " /select , " + Chr(34) + path + Chr(34)
    Call Shell(cmd, vbNormalFocus)
    

    Please rate this snippet

    How to create and write a textfile in VBA

    To create and write a textfile in VBA you can use the following snippet.
    This should also work when using VB6.

    Sample VBA

    Dim fso as Object
    Dim oFile as Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFile = FSO.CreateTextFile("C:\Users\Codesnippets\Desktop\Test.txt")
    
    oFile.WriteLine "This is a sample line!" 
    oFile.Close
    
    Set fso = Nothing
    Set oFile = Nothing  
    

    Please rate this snippet

    How to use the Microsoft Speech API in VBScript

    To use the Microsoft Speech API in VBScript you can use the following snippet.

    Sample VBScript

    dim sTextToSpeech 
    sTextToSpeech = "HELLO WORLD!"
    set ObjVoice = CreateObject("SAPI.SpVoice") 
    ObjVoice.Speak sTextToSpeech 
    

    Please rate this snippet