Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert java to vbscript?

Status
Not open for further replies.

bct10

Technical User
May 3, 2004
37
US
Hi all i habe this java that run in a web browser
id like to makek it a standalone vbscript

Use functions ToVariant() and FromVariant(); others
serve as helpers only.
*/

function ToVariant (x)
{
if (x == null);
else if (typeof(x) == "object")
{
if (x.getDate)
{ // cross-frame-safe determination of Date object
return ToVBDate_((x - vbDateBase_)/86400000); // msec per day
}
else if (x.sort)
{ // cross-frame-safe determination of Array object
return ToVBArray_(x);
}
else
return x.valueOf();
}
else
return x;
}

function FromVariant (v)
{
switch (typeof(v))
{
case "date":
return new Date(v);

case "unknown": // VBArray
var a = (new VBArray(v)).toArray();
for (var i=0; i < a.length; i++)
a = FromVariant(a);
return a;

default:
return v;
}
}

Array.prototype.getVariantAt = function (i)
{
return ToVariant(this);
}

// GetVariantAt is slower than Array.prototype.getVariantAt,
// but enables "cross-frame calling"

function GetVariantAt (arr, i)
{
return ToVariant(arr);
}
//-->
</SCRIPT><SCRIPT language="VBScript">
<!--
Dim vbDateBase_
vbDateBase_ = CDate(0)

function ToVBDate_ (d)
ToVBDate_ = CDate(d)
end function

function ToVBArray_ (arr)
Dim ubound, a(), i
ubound = arr.length - 1
Redim a(ubound)
for i=0 to ubound
' a(i) = arr.getVariantAt(i)
a(i) = GetVariantAt(arr, i) ' slower, but enables "cross-frame calling"
next
ToVBArray_ = a
end function
-->
</SCRIPT>


<object classid="clsid:53867031-6B4D-4F7D-B089-5DFEC731F5FA" id="NETComm1">
<param name="Settings" value="9600, N, 8, 1">
<param name="CommPort" value="1">
<param name="Handshaking" value="0">
<param name="InputBufferSize" value="0">
<param name="InputLength" value="0">
<param name="InputMode" value="0">
<param name="NullDiscard" value="0">
<param name="OutputBufferSize" value="1024">
<param name="ParityReplace" value="?">
<param name="OnCommReceiveThreshold" value="0">
<param name="RTSEnable" value="-1">
<param name="OnCommSendThreshold" value="0">
<param name="DTREnable" value="-1">
</object>


<form name=serialdata>
<table>
<tr>
<td>&nbsp;Input</td>
<td><input type=text name=read_data></td>
<td></td>
</tr>
<tr>
<td>Output</td>
<td><input type=text name=write_data></td>
<td><input type=button onclick="port_write()" value="Send"></td>
</tr>
</table>
<br>
<br>
<table>
<tr>
<td>COM port</td>
<td><input type=text name=port value="1"></td>
</tr>
<tr>
<td>Settings</td>
<td><input type=text name=settings value="9600, N, 8, 1"></td>
</tr>
<tr>
<td></td>
<td>
<input type=button onclick="port_start()" value="Start">
<input type=button onclick="port_stop()" value="Stop">
</td>
</tr>
</table>
</form>

<script language="javascript" id="test">
<!--

function port_start()
{
NETComm1.CommPort = document.serialdata.port.value;
NETComm1.Settings = document.serialdata.settings.value;
NETComm1.RThreshold = 1;
NETComm1.PortOpen = true;
}

function port_stop()
{
NETComm1.PortOpen = false;
}

function port_write()
{
NETComm1.Output = document.serialdata.write_data.value;
}

//-->
</script>

<script for="NETComm1" event="OnComm()" language="JavaScript">
<!--

if(NETComm1.InBufferCount == 0)
{
//
}
else
{
document.serialdata.read_data.value = NETComm1.InputData;
}

</script>


 
Not from this forum, but applicable never the less. faq184-248.

You need to give some thought to your questions and ask specific questions where you are stuck. You seem to want others to do all your work for you without even an explanation of what you are trying to do.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top