Discussion:
Abrir un archivo .BIN
(demasiado antiguo para responder)
Federico Ezequiel
2006-07-11 12:57:56 UTC
Permalink
Hola:

Me pueden orientar respecto a cómo abrir un archivo .BIN y cargar los datos,
por ejemplo, en un textbox en forma de ceros y unos?
Muchas gracias.

Ezequiel
Rubén Vigón
2006-07-11 13:57:59 UTC
Permalink
Hola Federico Ezequiel,

He retocado un poco el ejemplo que te preparé el otro día para que permita también abrir y visualizar el contenido de los archivos *.BIN; puedes descargarlo de http://vigon.mvps.org/ejemplos/editor_binario_2.zip (5,16 Kb)

Un saludo!

Rubén Vigón
Microsoft MVP Visual Basic
http://vigon.mvps.org
Federico Ezequiel
2006-07-11 17:04:08 UTC
Permalink
Rubén:

Muchísimas gracias. No sabés cuanto me ayudaste.
Saludos.

Ezequiel

"Rub�n Vig�n" <***@ESTOmvps.org> escribi� en el mensaje news:#Ud$***@TK2MSFTNGP04.phx.gbl...
Hola Federico Ezequiel,

He retocado un poco el ejemplo que te preparé el otro día para que
permita también abrir y visualizar el contenido de los archivos *.BIN;
puedes descargarlo de http://vigon.mvps.org/ejemplos/editor_binario_2.zip
(5,16 Kb)

Un saludo!

Rubén Vigón
Microsoft MVP Visual Basic
http://vigon.mvps.org

Saga
2006-07-11 14:22:28 UTC
Permalink
Y ya que la variedad es bvellaza, ahi te va este ejemplo minimo.


Abre un proyecto nuevo estandar exe.

Coloca un Command button un in Text box y agrega este codigo
despues del Option explicit:


Private Sub Command1_Click()

Dim ArBytes() As Byte
Dim intFH As Integer
Dim i As Integer

'Nota: Aqui pongo el nombre del archivo como boot.bin, cambialo segun
'tus necesidades.

'Abre archivo en binario.
intFH = FreeFile()
Open App.Path & "\boot.bin" For Binary Access Read As intFH

'Reserva espacio dentro del buffer.
ReDim ArBytes(1 To LOF(intFH))

''Lee el contenido del archivo y cierralo.
Get #intFH, 1, ArBytes
Close intFH

'Barre todo el arreglo, convierte a ASCII y ponlos
'dentro del text box.
For i = LBound(ArBytes) To UBound(ArBytes)
Text1.SelStart = Len(Text1.Text)
Text1.SelText = sysToBin(ArBytes(i))
Next i

End Sub

Private Sub Form_Load()

'Estas propiedades s necesitan asiganr en tiempo
'de diseño.
' Text1.MultiLine = True
' Text1.ScrollBars = 2

Text1.Text = ""
Me.Caption = "Lectura archivo .BIN"

End Sub

Private Function sysToBin(ByVal bytByte As Byte) As String

'Convierte a binario.

Dim strHex As String

strHex = Format$(Hex(bytByte), "00")

sysToBin = Hex2Bin(Left$(strHex, 1)) & Hex2Bin(Right$(strHex, 1))

End Function

Private Function Hex2Bin(ByVal strHex As String) As String

Dim i As Integer
Dim strBinCodes As String
Dim strBuf As String

'Inicializa tabla con codigos binarios.
strBinCodes = "00000001001000110100010101100" & _
"11110001001101010111100110111101111"

'Uno por uno, convierte y acumula codigo binario
'correspondiente al digito hexadecimal.
For i = 1 To Len(strHex)
strBuf = strBuf & Mid$(strBinCodes, Val("&H" & Mid$(strHex, i, 1)) * 4 + 1, 4)
Next i

Hex2Bin = strBuf

End Function

Private Sub Form_Resize()

'Ajusta el tamaño del cuadro de texto y posicion del boton.

If Me.Height - 1300 > 0 And Me.Width - 350 > 0 Then
Text1.Height = Me.Height - 1300
Text1.Width = Me.Width - 350
End If

If Me.Height - 1100 > 0 And Me.Width - 1450 > 0 Then
Command1.Move Me.Width - 1450, Me.Height - 1100
End If

End Sub

Saludos
Saga
--
Soluciones Para Mejorar
www.reset.com.mx
Post by Federico Ezequiel
Me pueden orientar respecto a cómo abrir un archivo .BIN y cargar los datos,
por ejemplo, en un textbox en forma de ceros y unos?
Muchas gracias.
Ezequiel
Federico Ezequiel
2006-07-11 17:04:38 UTC
Permalink
Saga:

Muchas gracias. Voy a probarlo también.
Saludos.

Ezequiel
Post by Saga
Y ya que la variedad es bvellaza, ahi te va este ejemplo minimo.
Abre un proyecto nuevo estandar exe.
Coloca un Command button un in Text box y agrega este codigo
Private Sub Command1_Click()
Dim ArBytes() As Byte
Dim intFH As Integer
Dim i As Integer
'Nota: Aqui pongo el nombre del archivo como boot.bin, cambialo segun
'tus necesidades.
'Abre archivo en binario.
intFH = FreeFile()
Open App.Path & "\boot.bin" For Binary Access Read As intFH
'Reserva espacio dentro del buffer.
ReDim ArBytes(1 To LOF(intFH))
''Lee el contenido del archivo y cierralo.
Get #intFH, 1, ArBytes
Close intFH
'Barre todo el arreglo, convierte a ASCII y ponlos
'dentro del text box.
For i = LBound(ArBytes) To UBound(ArBytes)
Text1.SelStart = Len(Text1.Text)
Text1.SelText = sysToBin(ArBytes(i))
Next i
End Sub
Private Sub Form_Load()
'Estas propiedades s necesitan asiganr en tiempo
'de diseño.
' Text1.MultiLine = True
' Text1.ScrollBars = 2
Text1.Text = ""
Me.Caption = "Lectura archivo .BIN"
End Sub
Private Function sysToBin(ByVal bytByte As Byte) As String
'Convierte a binario.
Dim strHex As String
strHex = Format$(Hex(bytByte), "00")
sysToBin = Hex2Bin(Left$(strHex, 1)) & Hex2Bin(Right$(strHex, 1))
End Function
Private Function Hex2Bin(ByVal strHex As String) As String
Dim i As Integer
Dim strBinCodes As String
Dim strBuf As String
'Inicializa tabla con codigos binarios.
strBinCodes = "00000001001000110100010101100" & _
"11110001001101010111100110111101111"
'Uno por uno, convierte y acumula codigo binario
'correspondiente al digito hexadecimal.
For i = 1 To Len(strHex)
strBuf = strBuf & Mid$(strBinCodes, Val("&H" & Mid$(strHex, i, 1)) * 4 + 1, 4)
Next i
Hex2Bin = strBuf
End Function
Private Sub Form_Resize()
'Ajusta el tamaño del cuadro de texto y posicion del boton.
If Me.Height - 1300 > 0 And Me.Width - 350 > 0 Then
Text1.Height = Me.Height - 1300
Text1.Width = Me.Width - 350
End If
If Me.Height - 1100 > 0 And Me.Width - 1450 > 0 Then
Command1.Move Me.Width - 1450, Me.Height - 1100
End If
End Sub
Saludos
Saga
--
Soluciones Para Mejorar
www.reset.com.mx
Post by Federico Ezequiel
Me pueden orientar respecto a cómo abrir un archivo .BIN y cargar los datos,
por ejemplo, en un textbox en forma de ceros y unos?
Muchas gracias.
Ezequiel
Loading...