Change Your Thoughts and You Change Your World

Adding, Subtracting, Multiplying, and Dividing Fractions in Visual Basic.Net

   Hello world! I love Math. So I'm going to share with you today a simple DLL that will allow you to declare a fraction and perform basic operations on it. I created a class which can be found under Arnex.dll. It's Arnex.Fraction. With Arnex.Fraction you can perform the following:

  • Add (+)
  • Subtract (-)
  • Multiply (*)
  • Divide (/)

You can also compare fraction using the following:

  • Greater Than (>)
  • Less Than (<)
  • Is Equal To (=)
  • Is Not Equal To (<>)

Other useful functions are:


When displaying fractions, you should convert it to string using .ToString function. 

See sample code below to see how it works. Simply add Arnex.dll on your code and import it to your code.

Imports Arnex

Module Module1

    Sub Main()
        Dim a As New Fraction(4, 5)
        Dim b As New Fraction(2)
        Dim c As New Fraction
        Dim d As New Fraction With {
            .Numerator = 3,
            .Denominator = 7}
        Dim e As New Fraction(6, 9)

        Console.WriteLine("Denominator of " & b.ToString & " is " & b.Denominator)
        Console.WriteLine("The equivalent of " & a.ToString & " in decimal is " & a.ToDecimalForm)
        Console.WriteLine(e.ToString & " in simplest form is " & e.ToSimplestForm.ToString)

        c = a + d + e

        Console.WriteLine("The sum of a + d + e is " & c.ToString & " equivalent to " & c.ToMixedForm)

        Dim f As Fraction = a

        Console.WriteLine("F is " & a.ToString)
        Console.WriteLine("The product of 4/5 and 1/2 is " & (New Fraction(4, 5) * New Fraction(1, 2)).ToString)
        Console.WriteLine("The quotient of 4/5 and 1/2 is " & (New Fraction(4, 5) / New Fraction(1, 2)).ToMixedForm.ToString)

        If d > e Then
            Console.WriteLine(d.ToString & "is greater than " & e.ToString)
            Console.WriteLine(d.ToString & "is less than " & e.ToString)
        End If

        If d > e Then
            Console.WriteLine(d.ToString & "is greater than " & e.ToString)
            Console.WriteLine(d.ToString & "is less than " & e.ToString)
        End If

        Dim g As New Fraction(8, 12)

        If e = g Then
            Console.WriteLine(e.ToString & " is equal to " & g.ToString)
        End If

        Console.WriteLine("The difference between e and g is " & (e - g).ToString)
        Console.WriteLine(New Fraction(4, -7).ToString)

        Console.WriteLine("Is 3/5 a proper fraction? " & New Fraction(3, 5).IsProper)
        Console.WriteLine("Is 7/6 a proper fraction? " & New Fraction(7, 6).IsProper)
        Console.WriteLine("The reciprocal of " & a.ToString & " is " & a.Reciprocal.ToString)
        Console.WriteLine("The additive inverse of " & d.ToString & " is " & d.AdditiveInverse.ToString)


    End Sub

End Module

You may download Arnex.dll and a sample project here. The sample project was created using VS2013 Community Edition.

If ever you found some bugs, please inform me by commenting below so that I can correct it.

You're Awesome.

Detecting a Hard Drive's Serial Number in Visual Basic .Net

 Hello world. In this tutorial I am sharing to you a sample code in Visual Basic.Net to  retrieve a hard drive's serial number. 

 We will be using a DLL I created named Hardware.dll. To use it just add it as reference to your project and import it using the following:

Imports Hardware.DriverUtility

 Now let us use the dll in our .NET Program. Using Visual Studio. Create a console application and paste the following code. 

Imports Hardware.DriverUtility
Module TestDriveSerial
    Sub Main()
        Console.WriteLine("Long Serial Number: " & SerialNumber())
        Console.WriteLine("Hex Serial Number: " & Hex(SerialNumber()))
    End Sub
End Module

 The function SerialNumber() returns a Long data type. If the driver is not ready it returns  -1 value.

 You may download the DLL and sample project above. Please don't hesitate to comment below.

 You're awesome!

[Quotes] Paulo Coelho | Fear of suffering

Tell your heart that the fear of suffering is worse than the suffering itself. And no heart has ever suffered when it goes in search of its dream. - Paulo Coelho

AES Encryption and Decryption in VB.NET using Encyption.dll

   Hello World! Sharing with you a very simple .dll to encrypt and decrypt strings using AES Encryption in VB.NET. This DLL (Dynamic Link Library) is useful for storing passwords in your database.

  The Advanced Encryption Standard or AES is a symmetric block cipher used by the U.S. government to protect classified information and is implemented in software and hardware throughout the world to encrypt sensitive data. - Techtarget

   Simply add the following DLL as reference to your project and import Encryption.AESMethod in your code. The following DLL is created using .NET Framework 3.5. Now, how do we use it? Just follow the sample code below. The DLL I created has to functions: Encrypt() and Decrypt(). It also uses a key for encryption.

Imports Encryption.AESMethod

Module Test

    Sub Main()
        Dim OriginalText As String = ""
        Dim AESKey As String = "secretkey"
        Dim EncryptedText As String = ""

        EncryptedText = Encrypt(OriginalText, AESKey)
        Console.WriteLine("EncryptedText: " & EncryptedText)
        Console.WriteLine("OriginalText: " & Decrypt(EncryptedText, AESKey))
    End Sub

End Module


   To get a copy of the DLL, just download Encryption.dll. I am also sharing a sample code here, this was created using VS 2013 Community edition.

   Feel free to ask questions by commenting below. You're awesome.