Ive got this labratory equipment that is connected to my PC. It uses special OCX file to communicate with the device (reading, setting parameters and such). I got this code from manual that seems to be working. I get a message box saying "Magnification =1272.814 Last error=API not initialized".
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onLoad()
Dim Value
Dim er
call Api1.Initialise("")
call Api1.Get("AP_MAG",Value)
call Api1.GetLastError(er)
call window.alert("Magnification = " + CStr(Value)+"Last error="+er)
call Api1.ClosingControl()
end sub
-->
</SCRIPT>
<TITLE>New Page</TITLE>
</HEAD>
<BODY>
<object classid="CLSID:71BD42C4-EBD3-11D0-AB3A-444553540000" id="Api1">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_ExtentX" VALUE="2096">
<PARAM NAME="_ExtentY" VALUE="1058">
<PARAM NAME="_StockProps" VALUE="0">
</OBJECT>
</BODY>
</HTML>
So because I have 0% knowledge in vbs and about 10% in jscript I`m trying to rewrite the same thing in Javascript. And I also have some necessary code already written in js.
<script language="JScript">
var Api1=new ActiveXObject("ApiCtrl");
var value;
var er;
Api1.Initialise("");
Api1.Get("AP_MAG",value);
Api1.GetLastError(er);
window.alert("Magnification = " + value+"\n Last error="+er);
Api1.ClosingControl();
</script>
Unfortunately I get a type mismatch error in either .Get
or .GetLastError
methods either with var value; var er;
or var value=""; var er="";
Here is what API manual has to say
long GetLastError(VARIANT* Error)
[out] Error is the error string associated with the error code for the last error Remarks: This call will return a VT_BSTR VARIANT associated with the last error. Return Value: If the call succeeds, it returns 0. If the call fails, an error code is returned from the function.
long Get(LPCTSTR lpszParam, VARIANT* vValue)
[in] lpszParam is the name of the parameter e.g. “AP_MAG”
[in][out] vValue is the value of the parameter Remarks: This call will get the value of the parameter specified and return it in vValue. In C++, before calling this functions you have to specify the variant type (vValue.vt) to either VT_R4 or VT_BSTR. If no variant type is defined for vValue, it defaults to VT_R4 for analogue parameters (AP_XXXX) and VT_BSTR for digital parameters (DP_XXXX). If the variant type is VT_R4 for an analogue parameter, then the floating point representation is returned in the variant. If a VT_BSTR variant is passed, analogue values are returned as scaled strings with the units appended (e.g. AP_WD would return “= 10mm”). For digital parameters, VT_R4 variants result in a state number and VT_BSTR variants result in a state string (e.g. DP_RUNUPSTATE would return state 0 or “Shutdown” or the equivalent in the language being supported). In C++, if the variant type was specified as VT_BSTR then the API will internally allocate a BSTR which the caller has to de-allocate using the SDK call ::SysFreeString (vValue.bstrVal)