Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Convert A Binary File To Ascii String


Dear All:I have a problem on converting a binary file to a Ascii String. The following is a sub to convert an input binary String to ascii string but I found that it does not workingCan someone point out where did I do wrong???Thanks in advancepublic Sub Bin2Asc(strBin as string, strAsc as string) Dim lLen as Long, i as Long, strBin2 as string lLen = len(strBin) strAsc = "" for i = 1 to lLen Dim strTmp as string Dim btByte as Byte strTmp = Hex(Asc(mid$(strBin, i, 1))) If len(strTmp) < 2 then strTmp = "0" & strTmp else If len(strTmp) = 4 then lLen = lLen - 1 End If strAsc = strAsc + strTmp If i = lLen then Exit for End If next iEnd Sub




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Convert Hex String To Binary File
Is there any easy way to convert a hex string into a binary file?

How To Convert Raw Binary Into Ascii Hex
i need to know how to convert raw binary into ascii hex, i searched around but couldnt find anything on it. anyone know?

Convert Ascii To Binary
Hi all.
I have a bit of a problem. I am getting a value from an OCX and it is in ascii. How can I convert the string so that it shows the binary representation of these values?

I.E. I get the value "Hi" "H" is 072 ascii and "i" is 105 ascii.

Then turning and converting those values to binary so that I get

"010010001101001" the binary equivilant.

Any help would be GREATLY appreciated

Convert Binary To ASCII
I'd like to convert binary code into ASCII. Does anyone have any code that could pull that off?? Thanx in advance!

How To Convert Ascii Into Binary
Hi,
I want to know that how we can convert our ascii text into binary one.

Convert Binary To Ascii
I am not familiar with binary file access, so forgive me if this is obvious:

When opening and reading a binary file, how do you convert it to Ascii?

Convert Ascii To Binary( 0[zeros] And 1[ones])
Most of you should know what binary is! I don't know how to do this:
convert ASCII characters to binary any help?
THANKS!

------------------
DiGiTaIErRoR

Convert Binary Value To ASCII (NEVER MIND, RESOLVED))
What is an easy way for that ?




Thank ya all!

Binary ASCII Hex Conversions And Reading From Binary File
A coworker has dumped a task off on me and I am not sure were to even look for what I need. First I need to read a binary file. then I need to take this information and display the information in Hex(in a text box). For my own use I would like to disply the binary information in a text box (as 0's and 1's) and the decimal value of the binary information.

Here is copy of my program, currently messy & clunky and in need of streamlining, but I figure other people might whant the code & it should make a good starting point for some one elses program
Thanks for the Help every one!!!!



Edited by - NcNghtStkr on 8/23/2005 7:13:17 PM

Convert String To ASCII
How would I go about converting a string into and ASCII string. Just for an example, say I had the string apple (the ascii characters arent right)

Apple
a=4 p=7 p=7 l=2 e=1
Then the ascii string would be 47721

Anyone?

Thanks

Convert Ascii String To Hex
Hi. I am having a problem finding the syntax to convert a 2 charactor String to a Hex value. The String will always be 2 charactors in length and will have ascii values from 00 to FF. Once in Hex, I will be using the value to set the .Height value of a Shape (Rectangle) which will represent the signal strength of a radio receiver. The receiver reports the signal level as a 2 charactor String, 00 to FF. I have tried a few different things and var types but keep getting a Type Mismatch.

Dim Signal_Level_Rec_A As Variant

Private Sub RecAComm_OnComm()
    Select Case RecAComm.CommEvent
        ' Errors
      Case comEventBreak ' A Break was received.
      Case comEventFrame ' Framing Error
      Case comEventOverrun ' Data Lost.
      Case comEventRxOver ' Receive buffer overflow.
      Case comEventRxParity ' Parity Error.
      Case comEventTxFull ' Transmit buffer full.
      Case comEventDCB ' Unexpected error retrieving DCB]

   ' Events
      'Case comEvCD ' Change in the CD line.
      'Case comEvCTS ' Change in the CTS line.
      'Case comEvDSR ' Change in the DSR line.
      'Case comEvRing ' Change in the Ring Indicator.
      Case comEvReceive ' Received RThreshold # of chars.
        Do
            DoEvents
            Comm_Recd_Rec_A = Comm_Recd_Rec_A & RecAComm.Input
        Loop Until InStr(Comm_Recd_Rec_A, vbCrLf) 'wait to receive <CR><LF> from receiver
        'Loop Until Len(Comm_Recd_Rec_A) = 4
        temp = Len(Comm_Recd_Rec_A)
        Comm_Recd_Rec_A = Right(Comm_Recd_Rec_A, temp - 1) 'strip off leading char.
        Comm_Recd_Rec_A = Left(Comm_Recd_Rec_A, temp - 3) 'strip off trailing CF,LF
         
        Rec_A_Meter_Comm_Rec.Caption = Comm_Recd_Rec_A
        If Left(Comm_Recd_Rec_A, 2) = "G0" Then 'status data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "G2" Then 'comm protovol version data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "GE" Then 'destination country data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "H9" Then 'scan status data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "I1" Then 'S-meter data follows 'This Case for Signal Level
            Signal_Level_Rec_A = Right(Comm_Recd_Rec_A, 2)
            Call Rec_A_Signal_Meter
        ElseIf Left(Comm_Recd_Rec_A, 2) = "I2" Then 'Center meter data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "I3" Then 'DTMF data follows
            DoEvents
        ElseIf Left(Comm_Recd_Rec_A, 2) = "NE" Then 'bandscope buffer data follows
            DoEvents
        End If '* add busy status I0/
             
      'Case comEvSend 'There are SThreshold number of characters in the transmit buffer
                      
      'Case comEvEOF ' An EOF charater was found in the input stream
                      
    End Select
    Comm_Recd_Rec_A = "" 'clear buffer
End Sub

Private Sub Rec_A_Signal_Meter() 'bargraph for Signal strength
    Dim temp As Byte
    temp = Signal_Level_Rec_A 'Trouble is here
    Rec_A_Meter_Signal_Level_Shape.Height = temp '* 3 'Signal_Level_Rec_A
    Rec_A_Meter_Signal_Level_Shape.Top = 1380 - Rec_A_Meter_Signal_Level_Shape.Height
End Sub '^ this number sets bottom position of bargraph


 

On Converting An ASCII String To Binary Digits
I'm trying to find out first of all if this has been done before and if i'm waisting my time by doing it again, and if not how best to go about doing it.

What I'm trying to do is make a simple form one button one text box (or rich text box) and one label. input text into text box hit button and text in box is converted into it's binary equivelant. not converting numbers into binary but the binary representation of its ASCII code (N=01001110, n=01101110, etc.) any help would be appreciated.

Read Hex/Binary String From Database As Ascii
Hello Everyone,

I'm connecting to a Microsoft SQL Database. One of the fields I need to read is a column of type "Binary" in SQL Server. Here, for instance, is a trace of an INSERT to this database.

INSERT INTO...... TABLE ... "CFG01",@P2 .... @P2 varbinary(100) ..... 0x593230303730343138303031202020204C02004E3C00592020202020202020202020 2020202020202020202020202020202020202020202020202020202020202020202020 20202020202020202020202020202020202020202020202020202020202020

(Relevant Parts Included)...

And what that 'Says' in ASCII is "Y20070418001................."
Y=59
2=32
0=30
0=30
7=37
0=30
4=34
1=31
8=38
0=30
0=30
1=31
....

So... Anyone know how to 'Read' That string into ASCII Characters? When I do a simple "SELECT CFG01 FROM TABLE", I get, in VB a string that looks like this...
"????????<?"... Not exactly what I need.

ANY Help greatly appreciated!

THANK YOU
Ben

Find String In Files (ASCII And Binary)
Hello,

How can i search inside all the files available in the Disk like Windows Find Function works.

How I Can Convert UTF8 String To ASCII
I read string from file. This string in UTF8 format. I need ASCII symbol. Function strconv() convertino only 16 bit unicod. For .NET i can use system.text class, but in excel VBA i don't use this class. Help, please.

Convert String To Binary
Hi, I was thinking to make an application, which contains two text box's and a command button. When you type something in the first text box and click the command button, the program should convert the text and type the output into the second text box. Is this possible or not, if it is possible I really apreciate if someone gives me the answer, thank you

How To Convert String To Binary
just like the topic,thanks

Convert Binary String To Hex
Hi, I am writing a program that takes data form a sensor and passes it through a USB comm port, displaying it on the screen. It will have real time updated graphs at some point, but that is getting a little ahead of myself.

The data is a 14 byte Hex string which looks a little like this;

AA 55 01 02 3E F9 00 00 00 00 00 C7 55 AA

The problem is that the sensor is transmitting this hex string as binary. I have tryed to convert the binary to hex but with no joy. The only method I can get to work is to convert the binary to Ascii, and then to hex using the following code;

Dim InBuff As String
Dim Data As String


Private Sub MSComm1_OnComm()

If MSComm1.CommEvent = comEvReceive Then
InBuff = Asc(MSComm1.Input)
End If

Data = Hex(InBuff)

Text1.Text = Data

End

This works to an extent, however the text box will only display one byte at a time and I need the whole string displayed. Is there anyway to convert the whole string at the same time, or if not, how do I string all the individual bytes together to form the original string?


Thank you for your time and help,

Stuart Mills.

Convert Binary String To A Double
I need to convert a Binary String to a Double using VB 6.0 sp5.
This string is read from the Winsock control from a device on the network.

Here is the Binary String
"1011100010100010110011100110000101110011001101001110001001000000"

Here is the Hex values
184 162 206 97 115 52 226 64

Does anyone know a function to covert this string.
Can I use a User defined type to do the conversion.

Thanks

ASCII File To Binary
Hello all,

I want to convert an Ascii file to binary. Is it possible thro' vb??

Some details are as follows:
I am using a library Roper Scientific Winx/32 automation for grabing images from a camera. Now this supports four formats.i.e Ascii,tif8,tiff,spe. I'm saving this image as ascii. This is because resolution changes using tif8 ot tiff format. And spe format is not detected through Matlab in which i want to finally read this image.This is it. So i think somehow i will be able to convert this ascii file to binary so that i can read it through matlab.So can u ppl help me in this?

Thanks & Regards

How To Convert Binary Code To Ascii Code
Does anyone know how to convert binary file to text file

Convert String To Binary Format And Vice Versa
hi friends,

can we convert binary format to string and string format to binary format?
if yes can u help me how to do it.

thanx

How To Determine Whether File Is Ascii Or Binary
Hi there
Any idea how to make a VB program able to determine from a filename whether the file is ascii or binary?

Converting A Binary File To Ascii
I am creating a tool in VB to search HTML and PDF files and for selected strings. Comparing strings in the HTML file was ok as HTML is an ascii file and I only had to implement some code to remove the tags.

The problem I am having is comparing strings in the PDF file as they are binary files. Is there a way of using VB to convert the file nto ascii prior to comparing the strings?

I hope that makes sense.

Thanks

Determine If A File Is Binary Or ASCII
Is there any easy way to determine if a file is binary or ASCII?

How To Convert It To ASCII File
I download a log file from SUN server,if i open it with notpad,it looks like: ???? % @#w./.....; it's a binary file , my custumer can't read it unless it is a ASCII file.so i want to know how to convert it to ASCII file readable with .TXT or .XLS


maybe I should use following :
open "d:log001" For Binary As 1
...
...
Get .....
...
Close 1
Open "d:
esult.txt" For Random As 1
.....
Put ...

but it's difficult to know the rule of binary file,
any advice is very useful to me!thanks

Reading Binary File Created In C (AScii)
Heyas,

I am racking my brain over this and hopefully some kind soul can put me out of my misery.

I have a binary file which stores data so:

typedef
{
char key[7];
char desc[20];
short supp_code;
long free_stock;
short min_stock;
char date[7];
float price;
}RECORD DATA;

Now whatever I do I cannot read this from VB without an error somewhere.

The closest I get is

Public Type StockRecord
key As String * 6
NC1 As String * 1
desc As String * 19
NC2 As String * 1
supp_code As Byte 'short
NB1 As Byte
free_stock As Integer 'long
NB2 As Byte
NB3 As Byte
minstock As Byte 'short
NB4 As Byte
YY As String * 2
MM As String * 2
DD As String * 2
NC4 As String * 1
price As Single 'float
End Type


I trust I am being very stupid somewhere - but bear with me.

Where NC stores Null chars and NB stores what seem to be bytes in the file that are not compatible with ASCII wheres as ofcourse in VB we work in UNI.

C Strings are ofcourse NULL terminated hence after each string I am reading the null and this is simply not used.

The above will give me everything except the minstock goes wrong for some records and right for others. Obviously Im doing something wrong with reading and discarding individual bytes and am probably barking up the wrong tree completely.

Can someone please either tell me the correct way to read a C data type short or correct my VB UDT / advise how I should be doing this?

Man thanks for any help

CandyMan

Reading Binary File Created In C (AScii)
Heyas,

I am racking my brain over this and hopefully some kind soul can put me out of my misery.

I have a binary file which uses a structure:

typedef
{

Detecting File Type? ASCII Or Binary?
Hi All,

I am trying to create an application with VB6 that can detect file type while recursing a folder structure and if it is an ASCII file, strip the ctrl-M's from the file for inclusion in a Windows environment created package for installation on a UNIX environment.

We have a NT script running now that goes through a large list of file extensions and for each one runs the DOS2UNIX utility to strip the Windows type line endings (ctrl-M's), but I want ot make it more efficient by not having to know what extensions are needed and recursively go through each folder of a structure and detect what type of file is listed and run the stripping of ctrl-M's if it is an ASCII file.

Any ideas on the detection of file type?

Thank you in advance,
John

Convert Text File To Ascii
Does anyone have some code out there that will convert a text file to an ascii file????

Convert A Unicode Text File To ASCII
I'm trying to read a text file into visual basic, change a part of it, and write it back out a text file. I had been having problems using OPEN (always resulted in an error 36), even though I had tried using LOF and EOF.

I found that the problem was the text file that I am trying to read from is in Unicode. Is there an easy way to convert this text file into an ASCII text file before I read from it?

Converting ASCII File To Binary File
OK, I searched the forums for something matching this, and the only solution i saw didn't work properly.

What I need to do is take a Text File (which will be in the following format, if thats important)


Quote:




## CORE BOARD FILE. Current CORE Version 1.0. Please do not change this line.##
2
2
N:E:S:W
## Editing any more below this line, may seriously affect the working of your game ##
grass.bmp::tree
grass.bmp::tree
grass.bmp::tree
grass.bmp::tree







and convert it into binary and then save it. Any ideas?

How Convert ASCII (DOS Charset) String To ANSI (Windows Charset)?
HI!

I have a litle problem. I read some strings from an ASCII (DOS charset) file. this file include some special germans chars...like : ,,, .

If I read a string that include one of those special chars. When I show the string in a message box the message box doesn't show the special chars only something like this: ,, .

How I can convert this ASCII (DOS charset) string to ANSI (Windows charset) string? to show this special chars?



gicio

Convert Any File To Binary Information ???
Is there a way to read any file "byte-by-byte" (or bit...wotever) and write the 0s and 1s into a text file???

...... and vise versa?

Thanks in advance!

Convert Binary To Orginal File
Hey all,

Does anyone have a clue how to convert binary data back to it's orginal format?

For example i have binary data which was once a picture how do i get it back??

thanks
b

Convert The Contents Of Txt File To Binary
I have a txt file with a lot of different numbers (0-255). How can i convert the content (or file) to binary so i can store it in a binary field in the database???

Convert Ascii Constant To Ascii Value With Program
How would I go about doin the following? If a string contains "vbKeyF1", how would i get vbKeyF1's ASCII value equivalent (ie: 112) to be written in another string?



Edited by - Marce22 on 10/10/2003 7:04:38 PM

Convert Binary File To Text File
I have a binary file, i want to covert this file to text file by reading byte by byte.
Can any one give me a sample code to do this?
Thank you

How To Convert Binary File To Text File
Hi all

I want to convert a Binary format file to a text format file.
How can i do it?

Thanks in advance
Venky

Convert Large Binary Files (3270 Exports) To Text File Format.
Access XP doesn't appear to import Binary files when exported directly from Attachmate.
Some of these files are quite large 18mb - to 100mb.

When I attempt to open the files in Access XP they fail and lockup Access XP. I have looked at the file format with some Hex compare utilities and they report that the file is 'Binary'.

If I take the same exact file and open it in Notepad then click save the file date and time changes and the file works perfectly with Access XP. (And the HEX compare utility no longer indicates that the file is binary)

Now that I am aware of this limitation - How do I take the file called XYZOutput.txt - open it in VB with FSO and write it back out as the same file name?

My theory was - If I can open the file in notepad - make NO CHANGES - but click 'SAVE' - the file structure changes from binary to text.

I have the following code to open the file and close it - but in VB it does not change the structure the way notepad.exe did?

One catch - the routine needs to handle large files, and since they are large I don't want to make a second file. I don't know what the file size limitation is of Notepad.exe. I want to fix the broken file. So for example - If my file is called "XYZOutput.txt" I want the VB routine to open this large file 'fix the formatting from binary to text' and save it.

'' Code ----------------------------------

    Dim fso As FileSystemObject
    Dim fil As File
    Dim ts As TextStream

    Set fso = CreateObject("scripting.filesystemobject")
    Set fil = fso.GetFile(sourcefile)
    Set ts = fil.OpenAsTextStream(ForAppending)
    ts.Close
    Set fso = Nothing
      
Kramerica

Extended Ascii/unicode String Conversion To Stanard Ascii
I encountered problems when sending certain characters from Windows VB to IBM Mainframe Cobol/DB2 such as
‘(left single quote) or ’(right single quote). All the characters after the extended ascii got cut off. I don't have problems when sending '(single quote).

Is there any vb functions to convert it? Or maybe changing the  
XEOLEDB mapping below would fix it (sample code below)?

{L"DESCRIPTION4", NULL, 68,STANDARD_COL_FLAG, 56, DBTYPE_BSTR, 0,0,0},


I am not familiar with IBM Mainframe and the service connecting VB to it. My only solution right now is to use the replace function but I am afraid there will be a performance problem.

thanks
clark

Getting A String In A Binary File
My file looks like this

[ Data Structure ]
[ string data ]
[ Data structure ]

The size of the [ stringdata ] Section is stored in the first data structure, I know how to get the first data structure but how do I get just the string data and not the other data structure at the bottom

Reading Binary File To String
My game saves it's game level using Binary access, however right now I want to load them to a string like you can normaly do with input so I can send it over a winsock, but the string size is ~8kb and my file is ~32kb. I tryed a few variation of the code used below but everyone I try doesn't read the entire file. I'm wondering if the fact that the file is orginaly save with the binary file format is what is causing this problem. Any help?

Code:
Open "c: emp
ew.txt" for input as #1
Do Until EOF(1)
Input #1, MyData
Loop
Close #1

Determine (possible) Position Of A String From A Binary File
Hi!
I am just trying to convert a Delphi code to Visual Basic and met the following problem: how can I determine the (possible) position of a string from a binary file (WMA, OGG Vorbis...)? I am using InStr(), but I don't know how to load the file to the memory as fast as Delphi does. In order to get the position, I have to wait 1 - 5 minutes, which is extremly long.

Any ideas?

Save Text String As Binary File(?)
in text form file might look like this:


Code:
Content-Type: image/jpeg;
name="A8BQOLHLMBDD.JPG"
Content-Transfer-Encoding: base64
filename="A8BQOLHLMBDD.JPG"

/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQr

etc on into 'infinity'










but when downloaded it comes out as a picture

is there vb code to interpret all that text that, for example, in this case, will convert it into an image, or whatever file it might happen to be?

How To Search A Text String In Binary File ?
Hi,

I need to search a text string in a file, e.g "My computer is down". This is a binary file. I can open it by NotePad or WordPad and find out it.

I use a small function to do it, as such


Dim nFile%
Dim tmpline As String
Dim k As Integer

SpcFileIsEmpty = True
On Error GoTo ERR_Handle

nFile = FreeFile
Open sSpcFile For Binary As #nFile
tmpline = InputB(512, #nFile)
Do While Not LOF(nFile)
tmpline = Input(512, #nFile)
k = InStr(1, tmpline, sOrginalText, vbTextCompare)
If k > 0 Then
SpcFileIsEmpty = False
Exit Do
End If
Loop

Close #nFile

This file is possible very big. Each time, I read 512 bytes (why ?).

If there is a method more performence and can assure the result correct?

Thanks

NY

Loading A Binary File Into A String And Find / Replace
Hi,

I'm trying to take a binary file (a Flash movie .swf file), load it into a String variable in VB, then search for occurrences of the string 'word1' and change it to 'Price'. Then, I want to write the data back to disk as a new file. Sounds simple, but I'm stumped for how to do it!

Hope someone can help - thanks!

Richard

Binary To Ascii
Me again, how do you open a binary file , convert it to ascii and put that in a txtbox? I have tried, at the top I can read my location but then its just unreadable data, it doesnt look like binary or hex to me;


Quote:




X v (gCQ @ l*o MIBOOK +gCN @ /3h WARBOOK O e4 @ -lN2 -gCG




is that encrypted?

Copyright 2005-08 www.BigResource.com, All rights reserved