Jump to content
Hertz

VB -Binary to Text and reverse

Recommended Posts

Posted

This program convert Binary to text and text to binary. This program has one Form1 (Main.frm), textbox (Text1.Text), two button, (cmdConvtoBin and cmdConvtoText) and a module1 (Binary.bas)

Acest program converteste din binar in text si invers.Acest program are un Form1(Main.frm,textbox(Text1.Text),doua butoane(cmdConvtoBin si cmdConvtoText) si un module1(Binary.bas)

Form

Private Sub cmdConvtoBin_Click()
MainText = Text1.Text
ConvertBin MainText
Text1.Text = MainText
End Sub

Private Sub cmdConvtoText_Click()
MainText = Text1.Text
ConvertToText MainText
Text1.Text = MainText
End Sub

Private Sub Form_Load()
Text1.Text = ""
End Sub

Module

Public MainText As String

Public Sub ConvertToText(BinText As String)
Dim BinChar As String
Dim CharX As String
Dim ConvertedMessage As String
Dim Z As Integer
Dim NewChar As Integer
Dim Bx As Integer
Dim BBx As Integer
For Bx = 1 To Len(BinText)
BinChar = Mid(BinText, Bx, 8)
Z = 128
NewChar = 0
For BBx = 1 To 8
CharX = Mid(BinChar, BBx, 1)
If CharX = "1" Then
NewChar = NewChar + Z
Z = Z / 2
Else
Z = Z / 2
End If
Next BBx
ConvertedMessage = ConvertedMessage & Chr(NewChar)
Bx = Bx + 7
Next Bx
BinText = ConvertedMessage
End Sub

Public Sub ConvertBin(TheString As String)
Dim C As Integer
Dim DD As Integer
Dim EE As Integer
Dim BinArray(7) As String
Dim TempString As String
Dim NewTheString As String
For C = 1 To Len(TheString)
DD = Asc(Mid(TheString, C, 1))
BinArray(7) = DD Mod 2
DD = DD / 2
BinArray(6) = DD Mod 2
DD = DD / 2
BinArray(5) = DD Mod 2
DD = DD / 2
BinArray(4) = DD Mod 2
DD = DD / 2
BinArray(3) = DD Mod 2
DD = DD / 2
BinArray(2) = DD Mod 2
DD = DD / 2
BinArray(1) = DD Mod 2
DD = DD / 2
BinArray(0) = DD Mod 2
For EE = 0 To UBound(BinArray)
TempString = TempString + BinArray(EE)
Next EE
NewTheString = NewTheString + TempString
TempString = ""
Next C
TheString = NewTheString
NewTheString = ""
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...