JSL如何將表中的數據直接修改為指定的二進製文件?“Text.blk”是保存在C:\下的二進製文件,JSL如何對數據表中的數據進行寫入、改寫、替換。
下面的代碼是Excel的VBA代碼,可以將excel A列數據寫入C列:\文本.blk。

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自動化和腳本Re: JSL如何將表中的數據直接修改為指定的二進製文件?JMP很強大

Re: JSL如何將表中的數據直接修改為指定的二進製文件?謝謝克雷奇!
這樣就可以了。以後可以直接用JSL來做。
我試過了:具體數據還需要+1000000。

Re: JSL如何將表中的數據直接修改為指定的二進製文件?如果那是你需要的,你仍然需要添加 1,000,000,但是像這樣
dt = Open( "$desktop/1T.jmp" );
filename = Save Text File(
"$temp/deleteme.blk",
Matrix To Blob( dt:code << getvalues, "int", 4, "little" )
);
任何跟隨的人:
- LoadTextFile 和 SaveTextFile 函數通常處理字符串文本數據,可能會更改 CRLF 結尾,添加 UNICODE 字節順序標記,並且無法處理 ASCII NUL 字符。 但是,當與 JMP 的 BLOB 類型一起使用時,文件僅使用二進制數據進行讀取/寫入。
- BlobToMatrix 和 MatrixToBlob 是反函數。 它們將所有數組元素或所有 blob 元素視為 1、2、4 或 8 字節塊。 它們還可以使數組元素(始終是雙精度 8 字節數字)成為 blob 中的有符號或無符號整數或浮點數。 他們可以處理 blob 中的大端與小端表示。 BlobToMatrix 有一個額外的參數來在矩陣中創建多個列。
- 您可能希望使用 BlobPeek 來處理二進制數據中塊大小不一致的部分,而 ||連接運算符將 blob 重新連接在一起。
Re: JSL如何將表中的數據直接修改為指定的二進製文件?請重新下載“1T.blk”文件,
看它的結構,如何把表中的4行以“1T.blk”的形式保存。
謝謝克雷奇!

Re: JSL如何將表中的數據直接修改為指定的二進製文件?謝謝克雷格!
我懂了。 這是錯誤的方向。
不要將“1T.blk”數據寫入表中,而是將表中的數據保存為“1T.blk”。
我給“1T。 BLK”,只是表示表中數據將被保存的文件形式。
我試著寫 JSL:

但是我還是不知道如何將表格中的數據以圖表的形式保存下來。保存的文件後綴名不是關鍵。
dt = Current Data Table();
dt << New Column( "new", formula( If( Left( Char( :code ), 2 ) == "12", 1000000 + :code, :code ) ) );
dt << run formulas;
Column( "new" ) << deleteFormula;
Wait( 0 );
mx = dt << GetAsMatrix( {2} );
mx << Save( "C:\1T.BLK" );//The saved file suffix name is not the key.Re: JSL如何將表中的數據直接修改為指定的二進製文件?我對 BLK 文件一無所知,對 VBA 知之甚少,但 *可能* BLK 文件非常簡單:
b = loadTextFile("z:/text.blk",blob()); // load your file
mat = blobtomatrix(b,"int",4,"little"); // operate on matrix data
/*:
[1123029, 1113555, 1110044, 1113038, 1113581, 1128108, 1110073, 1113509, 1113521,
1113037, 1113576, 1113586, 1113580, 1113035, 1113027, 1113592, 1113599, 1110059,
1113556, 1113565, 1113595, 1113543, 1113600, 1113520, 1113575, 1110072, 1113571,
1110067, 1113029, 1113582, 1113601, 1113011, 1110058, 1113034, 1113561, 1113593,
1113550, 1113008, 1110066, 1113548, 1113583, 1113039, 1113562, 1113537, 1113577,
1113527, 1113587, 1113541, 1113596, 1110053, 1113578, 1113526, 1113566, 1113591,
1113585, 1113589, 1110074, 1113572, 1110060, 1113590, 1113568, 1113021, 113555,
113038]如果您期望在較早的文件中有 64 個整數,那就是它包含的全部內容。 我不知道值的順序是什麼(行專業?列專業?其他?)。
Re: JSL如何將表中的數據直接修改為指定的二進製文件?謝謝克雷奇!
我學習了你的JSL代碼,我沒有乳溝。
我太粗心了,錯誤地上傳了“text.blk”文件。對不起。
原來上傳的是表中四個數據不對應的。
我的要求是將表格的4個數據點輸出為一個新的文件為*.blk文件。輸出前刪除了原來的BLK文件。
我重新上傳了特定的 VBA Excel 文件,打開它並單擊“BLK”按鈕,這將生成一個“1t. “C:\”路徑下的“BLK”文件。

請求如何寫JSL代碼可以實現VBA的這個功能:表中的四個數據是直接生成的,和VBA生成的BLK文件完全一樣。
謝謝!
Re: JSL如何將表中的數據直接修改為指定的二進製文件?b = loadTextFile("z:/text.blk",blob()); // load your file
hex = hex(b); // operate on hex data
show(hex); // the binary data is now character data
last4hex = right(hex,8); // two hex characters per byte
last4blob = blobpeek(b,length(b)-4,4); // operate on blob data
show(hex(last4blob)); // same data as above
mat = blobtomatrix(b,"int",4,"big"); // operate on matrix data
show(mat[nrows(mat)],hextonumber(last4hex),blobtomatrix(last4blob,"int",4,"big")); // all the same
// change the hex data (1-based offset to substr function, doubled. this is why programmers count from 0.)
show(substr(hex,5,4)); // the 3rd and 4th bytes, "1100". lets change them to "FE23"
hex = substr(hex,1,4) || "FE23" || substr(hex,9);
show(hex);
f1=savetextfile("$temp/text1.blk", hextoblob(hex)); // convert hex to blob before saving
// do the same with a blob (0-based offset to blobpeek function)
f2=savetextfile("$temp/text2.blk",blobpeek(b,0,2)||hextoblob("FE23")||blobpeek(b,4));
// do the same with a matrix. the matrix above is 4-bytes/element, lets use 1 instead
mat = blobtomatrix(b,"int",1,"big");
mat[3]=hextonumber("FE"); // 1-based matrix index
mat[4]=hextonumber("23");
f3=savetextfile("$temp/text3.blk",matrixtoblob(mat,"int",1,"big"));
// check our work:
b1=loadtextfile(f1,blob());
b2=loadtextfile(f2,blob());
b3=loadtextfile(f3,blob());
if(b1==b2==b3, write("\!nmatch, as expected"), write("\!nERROR"));
// this shows the changed data
show(shortesteditscript(hex(b),hex(b1)));Re: JSL如何將表中的數據直接修改為指定的二進製文件?我試著寫了它,但關鍵點仍然不清楚。
謝謝!

Re: JSL如何將表中的數據直接修改為指定的二進製文件?謝謝克雷格!
這些操作可以直接使用JSL來完成嗎?
我想知道您是否可以將第一個方法編寫為 JSL。
謝謝專家!
Re: JSL如何將表中的數據直接修改為指定的二進製文件?將 loadTextFile 與 blob 選項一起使用(它會忽略文件類型)。 然後,根據你想做什麼,其中之一:
- 將 blob 轉換為十六進制,操作十六進制(字符數是二進製字節的兩倍),將十六進制轉換回 blob
- 使用 blobPeek() 對 blob 進行分段,然後使用注入的數據重新組裝 blob
- 使用 blobToMatrix 提取數據,使用 matrixToBlob 重新組裝 blob。 這可能是最強大、最快、最容易或最難使用的,具體取決於文件。 blobToMatrix 函數會將整個 blob(可能來自上面的 2)分解為矩陣中的 1、2、4 或 8 字節塊;塊可以是大端或小端整數或浮點數。 (例如,如果數據是立體聲 wav 文件,您可以製作一個 16 位整數樣本的 2 列矩陣。)
最後,使用 saveTextFile 保存 blob。 它不需要 blob 選項,因為您可以給它一個 blob 或一個文本字符串來保存。
Re: JSL如何將表中的數據直接修改為指定的二進製文件?文本.BLK
代碼
123029
128108
113555
113038