我正在嘗試在 as400 模擬器(IBM 的 Personal Communications iSeries)中自動化一個程序,為此,我使用了一些代碼(我完全沒有從
這是我應該從模擬器獲得的區域,只是“Sy”:

This sometimes works and sometimes it doesn't. I tried on different parts of the emulator and the issue is the same. Getting the cursor position and sending a string work fine, it is just when I'm trying to get a string from the emulator.
I don't even know where to look for answers as this code was originally posted in 2005.
uj5u.com熱心網友回復:
我發現了問題。在該方法中,ReadScreen我創建了一個StringBuilder期望 3000 個字符的方法。當我在方法out的引數中使用時,我處理的是一個記憶體地址而不是兩個變數。由于我為至少 3000 個字符分配了空間,當我讀取的字串很小時,有時它會帶有來自“未使用”空間的垃圾。我所做的是將 的預期大小更改為StringBuilder我嘗試讀取的字串長度減 1(如果它只是長度,我仍然會得到一個垃圾字符)。這是代碼:
public static UInt32 ReadScreen(int position, int len, out string txt)
{
StringBuilder Data = new StringBuilder(len - 1); //This line was the problem.
UInt32 rc = (UInt32)position;
UInt32 f = HA_COPY_PS_TO_STR;
UInt32 l = (UInt32)len;
UInt32 r = EhllapiFunc.hllapi(out f, Data, out l, out rc);
txt = Data.ToString();
return r;
}
我的解釋可能是錯誤的,因為我還在學習 C# 并且代碼最初是 2005 年的,但是這個修改對我有用。如果我誤解了什么或者我做錯了什么,請隨時糾正我。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/332918.html
標籤:c# winforms ibm-midrange hllapi
上一篇:無法更改TextBox文本
