Byte Converter using VB6.0

Here in this tutorial, we will create a program that convert bits, bytes, kilobytes, megabytes, gigabytes, and terabytes to their corresponding bytes cases. We all know that 1 byte is equal to 8 bits and 1 kilobyte is equal to 1024 bytes. So that is the formula that we will going to use in this tutorial. Now, let's start this tutorial! 1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open. 2. Next, add only one Button named Command1 and labeled it as "Convert". Insert two combobox that will serve as unit of bytes named Combo1 and Combo2. Insert also two textbox named Text1 for inputting a desired value and Text2 for displaying the byte conversion. You must design your interface like this: design 3. Put this code in Form_Load to load the unit of bytes in the combobox.
  1. Private Sub Form_Load()
  2. Combo1.AddItem ("Bits")
  3. Combo1.AddItem ("Bytes")
  4. Combo1.AddItem ("Kilobytes")
  5. Combo1.AddItem ("Megabytes")
  6. Combo1.AddItem ("Gigabytes")
  7. Combo1.AddItem ("Terabytes")
  8.  
  9.  
  10. Combo2.AddItem ("Bits")
  11. Combo2.AddItem ("Bytes")
  12. Combo2.AddItem ("Kilobytes")
  13. Combo2.AddItem ("Megabytes")
  14. Combo2.AddItem ("Gigabytes")
  15. Combo2.AddItem ("Terabytes")
  16.  
  17. End Sub
4. In your button1 as the conversion button, put this code below. Initialize num1 as integer and make that as a valid number in input.
  1. Dim num1 As Integer
  2. num1 = Val(Text1.Text)
  3. If Not IsNumeric(num1) Then
  4. MsgBox ("Make sure your conversion is numeric.")
  5. Exit Sub
  6. End If
Have a code for select case in your combo1.text as the inputted unit and the output unit will be in Combobox2. For Bits Conversion:
  1. Select Case Combo1.Text
  2. Case "Bits"
  3. With Combo2
  4. If .Text = "Bits" Then Text2.Text = num1
  5. If .Text = "Bytes" Then Text2.Text = num1 / 8
  6. If .Text = "Kilobytes" Then Text2.Text = num1 / 8 / 1024
  7. If .Text = "Megabytes" Then Text2.Text = num1 / 8 / 1024 / 1024
  8. If .Text = "Gigabytes" Then Text2.Text = num1 / 8 / 1024 / 1024 / 1024
  9. If .Text = "Terabytes" Then Text2.Text = num1 / 8 / 1024 / 1024 / 1024 / 1024
  10.  
  11. End With
For Byte Conversion:
  1. Case "Bytes"
  2. With Combo2
  3. If .Text = "Bits" Then Text2.Text = num1 * 8
  4. If .Text = "Bytes" Then Text2.Text = num1
  5. If .Text = "Kilobytes" Then Text2.Text = num1 / 1024
  6. If .Text = "Megabytes" Then Text2.Text = num1 / 1024 / 1024
  7. If .Text = "Gigabytes" Then Text2.Text = num1 / 1024 / 1024 / 1024
  8. If .Text = "Terabytes" Then Text2.Text = num1 / 1024 / 1024 / 1024 / 1024
  9.  
  10. End With
For Kilobytes Conversion:
  1. Case "Kilobytes"
  2. With Combo2
  3. If .Text = "Bits" Then Text2.Text = num1 * 1024 * 8
  4. If .Text = "Bytes" Then Text2.Text = num1 * 1024
  5. If .Text = "Kilobytes" Then Text2.Text = num1
  6. If .Text = "Megabytes" Then Text2.Text = num1 / 1024
  7. If .Text = "Gigabytes" Then Text2.Text = num1 / 1024 / 1024
  8. If .Text = "Terabytes" Then Text2.Text = num1 / 1024 / 1024 / 1024
  9.  
  10. End With
For Megabytes Conversion:
  1. Case "Megabytes"
  2. With Combo2
  3. If .Text = "Bits" Then Text2.Text = num1 * 1024 * 1024 * 8
  4. If .Text = "Bytes" Then Text2.Text = num1 * 1024 * 1024
  5. If .Text = "Kilobytes" Then Text2.Text = num1 * 1024
  6. If .Text = "Megabytes" Then Text2.Text = num1
  7. If .Text = "Gigabytes" Then Text2.Text = num1 / 1024
  8. If .Text = "Terabytes" Then Text2.Text = num1 / 1024 / 1024
  9.  
  10. End With
For Gigabytes Conversion:
  1. Case "Gigabytes"
  2. With Combo2
  3. If .Text = "Bits" Then Text2.Text = num1 * 1024 * 1024 * 1024 * 8
  4. If .Text = "Bytes" Then Text2.Text = num1 * 1024 * 1024 * 1024
  5. If .Text = "Kilobytes" Then Text2.Text = num1 * 1024 * 1024
  6. If .Text = "Megabytes" Then Text2.Text = num1 * 1024
  7. If .Text = "Gigabytes" Then Text2.Text = num1
  8. If .Text = "Terabytes" Then Text2.Text = num1 / 1024
  9.  
  10. End With
For Terabytes Conversion:
  1. Case "Terabytes"
  2. With Combo2
  3. If .Text = "Bits" Then Text2.Text = num1 * 1024 * 1024 * 1024 * 1024 * 8
  4. If .Text = "Bytes" Then Text2.Text = num1 * 1024 * 1024 * 1024 * 1024
  5. If .Text = "Kilobytes" Then Text2.Text = num1 * 1024 * 1024 * 1024
  6. If .Text = "Megabytes" Then Text2.Text = num1 * 1024 * 1024
  7. If .Text = "Gigabytes" Then Text2.Text = num1 * 1024
  8. If .Text = "Terabytes" Then Text2.Text = num1
  9.  
  10. End With
Output: output For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

Submitted byabdul rahaman rashid (not verified)on Thu, 01/21/2016 - 20:38

i would like to learn from you

Add new comment