By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

Calling a Javascript function from a message box

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.