Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Writing Binary Files
Message
 
To
08/06/2006 04:33:38
Jon Neale
Bond International Software
Wootton Bassett, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP1
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01127600
Message ID:
01127790
Views:
16
> The application writes out a long int (4bytes I beleive) into a binary file.

In VFP 6 you can do this with the following function:
*========================================================
* Converts a number into a binary string
*========================================================
Function ToInt
LParameter tnValue, tnBytes
    Local lcString, lnByte
    lcString = ""
    For m.lnByte = 1 to m.tnBytes
      lcString = m.lcString + Chr(m.tnValue%256)
      tnValue = Int(m.tnValue/256)
    Endfor
Return m.lcString
use it like this:
STRTOFILE( ToInt(0,4), "file name")  && write binary 0
STRTOFILE( ToInt(1,4), "file name")  && write binary 1
> The value can either be 1 or 0. The value within the file comes out as " ",

To display binary files, you need a hex viewer. For displaying purposes I've a small program called hexview:
LParameter tcString

	Local lnPos, lnChar, lnCol, lnRow, lcascii
	lnCol = 0
	lnRow = 0
	lcascii = ""
	For lnPos = 1 To Len(tcString)
		If lnCol%16 = 0
			If lnPos > 1
			  ?? "   " + lcascii
			Endif
			? Transform(lnRow,"@0")+" : "
			lnRow = lnRow+16
			lcascii = ""
		Endif
		lnCol = lnCol + 1
		lnChar = Asc(SubStr(tcString,lnPos,1))
		?? RighT(Transform(lnChar,"@0"),2)+" "
		if lnchar >= 32
			lcascii = lcascii + chr(lnchar)
		else
			lcascii = lcascii + "."
		endif
	Endfor
    ?? space((16-len(lcascii))*3)+"   " + lcascii
which I call like this:
HexView(FILETOSTR("file name"))
--
Christof
Previous
Reply
Map
View

Click here to load this message in the networking platform