r/visualbasic • • Jun 03 '14

Your Favorite VB Namespace? ('Imports ...')

E.g: System.Math System.Net.Sockets

5 Upvotes

6 comments sorted by

3

u/candyforlunch VB.Net Master Jun 04 '14
System.Linq

because linq should be used all day every day :D

1

u/JakDrako Jun 04 '14

I used to agree. Then I saw this:

dim sn = "1234567890"
dim lastSixDigits = sn.reverse.take(6).reverse.aggregate(string.empty, function(s, c) string.concat(s, c))

:)

2

u/JakDrako Jun 03 '14

Er, whichever one I need to get the job done?

System.Security.Cryptography is cool, although I don't get to use it much.

Public Function AESEncrypt(ByVal input As String, ByVal pass As String) As String
    Dim AES As New System.Security.Cryptography.RijndaelManaged
    Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
    Dim encrypted As String = ""
    Try
        Dim hash(31) As Byte
        Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
        Array.Copy(temp, 0, hash, 0, 16)
        Array.Copy(temp, 0, hash, 15, 16)
        AES.Key = hash
        AES.Mode = CipherMode.ECB
        Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
        Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
        encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
    Catch ex As Exception
        Debug.Assert(False)
    End Try
    Return encrypted
End Function

2

u/Vectronic Jun 03 '14

The only ones that's pretty much guaranteed to be used:

System.IO
System.Text.RegularExpressions
System.Threading

It makes, File.*, Regex.*, and Thread.* easier to type.

Although System.Math is always used, I don't bother, because using Math.*() is easier to read, I know it's using a built in function, as apposed to one of my own. Unless I have a class/module that does nothing but math functions, then I'll import it for that.

Other than that, like JakDrako said... whichever ones need to be, or make it easier/faster.

2

u/CharlieMay VB.Net Intermediate Jun 03 '14

System.Data.SQLClient, System.Data.Oledb My own Namespace for things I written to save time.

1

u/ginolard Jun 04 '14

Ugh, Regular Expressions.

My favourite quote about Regex is "When someone has a problem they think, 'I know! I'll use Regular Expressions!'. Now they have two problems"