471,310 Members | 1,090 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Calling a Javascript function from a message box

Hello all,

I have simple function that I call from an alert box

alert(testScore);

It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a nice message box like VBA message
box #64 to appear. I know hardly anything at all about VB or VBA.
But, I do know you can call a VB function from Javascript. How? Is it
possible to get my testScores to appear from the VB function? Is it
hard? Where do I start looking?

Thanks
Kim
Jul 20 '05 #1
3 21296
ki********@tch.harvard.edu (Kim Forbes) writes:
I have simple function that I call from an alert box alert(testScore); It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears.
There is no sound or exclamation point in my browser.
I'd like a nice message box like VBA message
box #64 to appear. I know hardly anything at all about VB or VBA.
Me neither, so I don't know what a message box #64 is.
But, I do know you can call a VB function from Javascript.
Not in my browser. I.e., not in general. The specific case where it
works is Internet Explorer on Windows. You are not running Javascript,
but JScript, which has access to the Windows Scripting Host, just like
VBA.
How? Is it possible to get my testScores to appear from the VB
function? Is it hard? Where do I start looking?


Since it is Microsoft IE only, a good guess would be Microsoft's
webpage, searching for JScript and WSH.

This script will use the WSH function, but will require the user to
allow the ActiveXObject creation (at least in my security setting) .
---
<script type="text/javascript">
function myAlert(str) {
if (window && window.WScript) {
var shell=new ActiveXObject('WScript.Shell');
shell.Popup(str,undefined,undefined,64); // that's the #64?
} else {
alert(str);
}
}
---

You could also make a VBScript function and call it from JScript:
---
<script type="text/vbscript">
Function VBMsgBox(txt)
MyMsgBox = MsgBox(txt,64)
End Function
</script>
<script type="text/javascript">
function myAlert (str) {
if (typeof VBMsgBox != "undefined") {VBMsgBox(str);}
else {alert(str);}
}
</script>
---

In both cases, you must fall back on "alert" for all other browsers and
platforms.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
you can call a vbscript function from javascript but in my
experience you will have to write the vbscript function first.

<script language="vbscript">
function alert(x)
messagebox(x)
End
</script>

<script language="javascript">
messagebox("blah")
</script>

be aware though that not all browsers will support vbscript
I may be wrong but I think it will only be ie4 +

Hope this helps

Simon Christie

"Kim Forbes" <ki********@tch.harvard.edu> wrote in message
news:de**************************@posting.google.c om...
Hello all,

I have simple function that I call from an alert box

alert(testScore);

It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a nice message box like VBA message
box #64 to appear. I know hardly anything at all about VB or VBA.
But, I do know you can call a VB function from Javascript. How? Is it
possible to get my testScores to appear from the VB function? Is it
hard? Where do I start looking?

Thanks
Kim

Jul 20 '05 #3
Kim Forbes wrote:
I have simple function that I call from an alert box

alert(testScore);

It works fine.
Forgive me but I do not see any function here [except of alert(...)].
Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a nice message box like VBA message
box #64 to appear.
How does that box look like?
I know hardly anything at all about VB or VBA.
Not a very promising start.
But, I do know you can call a VB function from Javascript.
In Internet Explorer, it is possible to call
a VBScript subroutine from JavaScript.
How?
<script type="text/vbscript" language="VBScript">
<!--
Sub foobar
MsgBox "Hello, world!"
End Sub
'-->
</script>

<script type="text/javascript" language="JavaScript">
<!--
foobar();
//-->
</script>
Is it possible to get my testScores to appear from the VB function?
<computer> Please restate your request. </computer>
Is it hard? Where do I start looking?


A manual of your choice, possibly <http://msdn.microsoft.com/library/>,
or a group of the microsoft.* hierarchy. VB(Script)/VBA is off-topic here.
PointedEars

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by R.G. Vervoort | last post: by
5 posts views Thread by Krishna | last post: by
6 posts views Thread by szabelin | last post: by
4 posts views Thread by Anita C | last post: by
7 posts views Thread by Roger | last post: by
4 posts views Thread by Martin Feuersteiner | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.