cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lwx228
Level VIII

How can JSL modify data in a table directly to a specified binary file?

"Text.blk" is a binary file saved in C:\, how JSL can write, rewrite, and replace the data in the data table.
The following code is the VBA code of Excel, which can write the data of excel column A to C text.blk.

2020-10-29_19-57-29.png

 

Sub text()
    Dim arr, I, filename As String, t As Long
   filename = "c:\text.BLK"
    Open filename For Binary As #1: arr = Range("a2:a" & Cells(Rows.Count, "a").End(3).Row)
    For r = 1 To UBound(arr)
        If Left(arr(r, 1), 2) = "12" Then arr(r, 1) = 1000000 + arr(r, 1)
    Next
    For I = 1 To UBound(arr, 1)
        If IsNumeric(arr(I, 1)) Then Put #1, , CLng(arr(I, 1))
    Next
    Close #1
End Sub
12 REPLIES 12
Craige_Hales
Super User

Re: How can JSL modify data in a table directly to a specified binary file?

You'll still need to add 1,000,000 if that's what you need, but something like this

 

dt = Open( "$desktop/1T.jmp" );
filename = Save Text File(
	"$temp/deleteme.blk",
	Matrix To Blob( dt:code << getvalues, "int", 4, "little" )
);

Anyone following along:

  • the LoadTextFile and SaveTextFile functions normally work with character string text data and will possibly change the CRLF endings, add UNICODE Byte Order Mark, and can't deal with the ASCII NUL character. But, when used with JMP's BLOB type, the file is read/written with just the binary data.
  • BlobToMatrix and MatrixToBlob are inverse functions. They treat all the array elements or all the blob elements as 1, 2, 4, or 8 byte chunks. They also can make the array elements (which are always double precision 8 byte numbers) be signed or unsigned integers or floating point numbers in the blob. And they can handle big- vs little-endian representations in the blob. And BlobToMatrix has an extra argument to make multiple columns in the matrix.
  • You might want to use BlobPeek to deal with sections of the binary data that are not uniform chunk sizes, and the || concatenate operator to join blobs back together.

 

Craige
lwx228
Level VIII

Re: How can JSL modify data in a table directly to a specified binary file?

Thank Craige!

That will do.It can be done directly with JSL in the future.

I tried: the specific data still needs +1000000.

  • The BLK file is read by other software.

 

2020-11-01_07-36-52.png

lwx228
Level VIII

Re: How can JSL modify data in a table directly to a specified binary file?

  • JMP is powerful

  • 2020-11-01_10-30-10.png