開發 ActiveX 用戶端應用程式碼
開發 ActiveX Windows 程式 (例如 Visual Basic、VBScript 及 Active Server Pages) ,以使用 WebSphere® ActiveX 至 EJB 橋接器來存取 Enterprise Bean。
開始之前
重要事項: 本主題假設您熟悉 Windows 平台上的 ActiveX 程式設計及開發。 如需 ActiveX 應用程式用戶端及 ActiveX 至 EJB 橋接器的程式設計概念相關資訊,請參閱 ActiveX 至 Enterprise JavaBeans™ (EJB) 橋接器主題及相關主題。
請將 ActiveX 至 EJB 橋接器中提供的資訊視為良好的程式設計準則。
關於這項作業
程序
範例
檢視 System.out 訊息 :ActiveX 至 Enterprise JavaBeans (EJB) 橋接器沒有主控台可用來檢視 Java System.out 訊息。 若要在執行獨立式用戶端程式 (例如 Visual Basic) 時檢視這些訊息,請將輸出重新導向至檔案。
下列範例說明如何將輸出重新導向至檔案:
launchClientXJB.bat MyProgram.exe > output.txt- 若要在執行服務程式 (例如 Active Server Pages) 時檢視 System.out 訊息,請將 Java System.out OutputStream 物件置換為 FileOutputStream。 例如,在 VBScript 中:
'Redirect system.out to a file ' Assume that oXJB is an initialized XJB.JClassFactory object Dim clsSystem Dim oOS Dim oPS Dim oArgs ' Get the System class Set clsSystem = oXJB.FindClass("java.lang.System") ' Create a FileOutputStream object ' Create a PrintStream object and assign to it our FileOutputStream Set oArgs = oXJB.GetArgsContainer oArgs.AddObject "java.io.OutputStream", oOS Set oPS = oXJB.NewInstance(oXJB.FindClass("java.io.PrintStream"), oArgs) ' Set our System OutputStream to our file clsSystem.setOut oPS
ActiveX 用戶端應用程式使用 helper 方法進行資料類型轉換。 通常, ActiveX (Visual Basic 及 VBScript) 與 Java 方法之間的資料類型轉換會自動進行,如 ActiveX 至 EJB 橋接器中所述,轉換資料類型。 不過,如果無法自動轉換,則會提供位元組 helper 函數和貨幣 helper 函數。
- Byte helper 函數由於 Java 位元組資料類型是帶正負號的 (-127 到 128) ,而 Visual Basic 位元組資料類型是不帶正負號的 (0 到 255) ,因此將不帶正負號的位元組轉換成 Visual Basic Integers ,看起來像 Java 帶正負號的位元組。 若要進行此轉換,您可以使用下列 helper 函數:
Private Function GetIntFromJavaByte(Byte jByte) as Integer GetIntFromJavaByte = (CInt(jByte) + 128) Mod 256 - 128 End Function - 貨幣輔助程式函數Visual Basic 6.0 無法像 Java 方法一樣適當地處理 64 位元整數 (如 Long 資料類型)。 因此, Visual Basic 使用「貨幣」類型,本質上是 64 位元資料類型。 使用「貨幣」類型 (變式類型 VT_CY) 的唯一副作用是在類型中插入小數點。 若要在 Visual Basic 中擷取及操作 64 位元 Long 值,請使用類似下列範例的程式碼。 如需此轉換「貨幣」資料類型技術的詳細資料,請參閱 Microsoft 知識庫上的 Q189862
HOWTO: 在 VBA 中執行 64 位元算術運算
。' Currency Helper Types Private Type MungeCurr Value As Currency End Type Private Type Munge2Long LoValue As Long HiValue As Long End Type ' Currency Helper Functions Private Function CurrToText(ByVal Value As Currency) As String Dim Temp As String, L As Long Temp = Format$(Value, "#.0000") L = Len(Temp) Temp = Left$(Temp, L - 5) & Right$(Temp, 4) Do While Len(Temp) > 1 And Left$(Temp, 1) = "0" Temp = Mid$(Temp, 2) Loop Do While Len(Temp) > 2 And Left$(Temp, 2) = "-0" Temp = "-" & Mid$(Temp, 3) Loop CurrToText = Temp End Function Private Function TextToCurr(ByVal Value As String) As Currency Dim L As Long, Negative As Boolean Value = Trim$(Value) If Left$(Value, 1) = "-" Then Negative = True Value = Mid$(Value, 2) End If L = Len(Value) If L < 4 Then TextToCurr = CCur(IIf(Negative, "-0.", "0.") & _ Right$("0000" & Value, 4)) Else TextToCurr = CCur(IIf(Negative, "-", "") & _ Left$(Value, L - 4) & "." & Right$(Value, 4)) End If End Function ' Java Long as Currency Usage Example Dim LC As MungeCurr Dim L2 As Munge2Long ' Assign a Currency Value (really a Java Long) ' to the MungeCurr type variable LC.Value = cyTestIn ' Coerce the value to the Munge2Long type variable LSet L2 = LC ' Perform some operation on the value, now that we ' have it available in two 32-bit chunks L2.LoValue = L2.LoValue + 1 ' Coerce the Munge value back into a currency value LSet LC = L2 cyTestIn = LC.Value