CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 1999
    Posts
    21

    Text to Binary file conversion

    Hello

    Is there any utilities/activeX/source code which I can use to convert an ascii text file into a binary file????
    Thanks!


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Text to Binary file conversion

    Private Sub cmdText_Click() 'This sub converts the text to binary
    Dim lInput As Double
    Dim sOutput As String
    Dim sOutput2 As String
    Dim iX, iY As Integer

    If Len(txtText) > 0 Then 'if valid text exists
    sOutput2 = "" 'reset output string
    For iY = 1 To Len(txtText.Text) 'for each character in the text
    lInput = Asc(Mid(txtText.Text, iY, 1)) 'retreive the Ascii value of this character
    sOutput = "" 'reset the output string for this character
    While lInput > 0
    iX = lInput Mod 2 'return the modulus
    sOutput = iX & sOutput 'append result to output string for this character
    lInput = Int(lInput / 2) 'return the next number for calculation
    Wend
    While Len(sOutput) < 8
    sOutput = 0 & sOutput 'add leading zeros if the result is shorter than 8 characters
    Wend
    sOutput2 = sOutput2 & " " & sOutput 'append result and a separating space to output string
    Next
    MsgBox "The binary eqivalent of the text string '" & txtText.Text & "' is:" & vbLf & vbLf & sOutput2, vbInformation + vbOKOnly, "Success" 'display result
    txtText.Text = "" 'reset text box
    Else 'if no valid text exists
    MsgBox "Please enter some text.", vbCritical + vbOKOnly, "Error"
    End If
    txtText.SetFocus 'reset focus to textbox
    End Sub

    Private Sub txtNumber_Change()
    Dim X As Integer

    If IsNumeric(txtNumber.Text) = False Then 'if latest character isn't a number
    If Len(txtNumber.Text) > 1 Then
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1) 'remove the last caracter from the string
    Else
    txtNumber.Text = ""
    End If
    Else
    If InStr(1, txtNumber.Text, ".", vbTextCompare) > 0 Then 'remove any periods
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1)
    ElseIf InStr(1, txtNumber.Text, "+", vbTextCompare) > 0 Then 'remove any plus signs
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1)
    ElseIf InStr(1, txtNumber.Text, "-", vbTextCompare) > 0 Then 'remove any minus signs
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1)
    ElseIf InStr(1, txtNumber.Text, "$", vbTextCompare) > 0 Then 'remove any dollar signs
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1)
    ElseIf InStr(1, txtNumber.Text, ",", vbTextCompare) > 0 Then 'remove any commas
    txtNumber.Text = Left(txtNumber.Text, Len(txtNumber.Text) - 1)
    End If
    End If
    txtNumber.SelStart = Len(txtNumber.Text) 'reset the cursor position
    End Sub


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured