Solved

beep function ... super easy

Posted on 2004-09-13
9
1,685 Views
Last Modified: 2013-12-25
I can't get my "hello world" vbscript to work. I am running it with WSH. I copied most of it. Everything works but the beep and it is just annoying me.

here it is with sub

dim v
v = inputbox ("what is ur name?")
msgbox " hello, " & v


Beeep(5)

Sub Beeep(itimes)
dim itemp
For itemp = 1 to itimes
beep
next
end sub


>>>>>>> type mismatch beep

here is another way

dim v
v = inputbox ("what is ur name?")
msgbox " hello, " & v

beep


>>>>same thing type mismatch beep

I really just want to know why this beep doesnt work. I dont want to know how to run multiple functions to connnect to a beep.wav. I will learn that later. This of course worked without the beep.

ty,
jd
0
Comment
Question by:John_David
  • 3
  • 3
  • 3
9 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 12050366
Beep function is only available in VB, but not in VBScript (Microsoft Windows Script Technologies)
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 12050383
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 12050397
See this as well:

VBScript functions available in Visual Basic Scripting Edition
http://msdn.microsoft.com/library/en-us/script56/html/vtoriFunctions.asp
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:John_David
ID: 12051120
my "Im a noob" book says one of the simplest vbscript statements is beep. Ill check the links u gave later. Too busy to go surfing.

thnx
0
 
LVL 3

Expert Comment

by:domj
ID: 12051491
Ryancys is right, in theory you cant do it however this will work! ;-)

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set wshell=CreateObject("Wscript.Shell")
wshell.run "cmd /C " & chr(34) & "@echo " & chr(7) & chr(34),0,True
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Dom
0
 
LVL 3

Accepted Solution

by:
domj earned 50 total points
ID: 12051505
Sorry, here is your entire code in case you were wondering how to integrate it. (By the way, you will drive yourself nuts trying to train on VB with VBScript)! Good Luck!!!!!

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set wshell=CreateObject("Wscript.Shell")

dim v
v = inputbox ("what is ur name?")
msgbox " hello, " & v
Beeep(5)

Sub Beeep(itimes)
dim itemp
For itemp = 1 to itimes
wshell.run "cmd /C " & chr(34) & "@echo " & chr(7) & chr(34),0,True
next
end sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 

Author Comment

by:John_David
ID: 12051737
I sort of understand the top statment (I just don't know what Wscript.Shell is). Any chance of explaining (just a little bit) the statement in the sub?
0
 

Author Comment

by:John_David
ID: 12051744
I'm good at other languages. I have a cs degree, but ur right....I am going nutz...lol
0
 
LVL 3

Expert Comment

by:domj
ID: 12051803
OK, first of all you gotta understand that VBScript is NOT the same as VB. It is a hugely scaled down version a much more complex language. To go through the book you've got you should chase down a copy of Visual Studio (and it sounds like your learning VB6 not .NET).

That said, because VBScript is less featured than VB, it is sometimes necessary to reference some outside tools. In this instance, to produce the beep requires running the code '@echo' and then the ascii character number 7 from a command line. (Don't ask why, it just works! :-P) If you were using VB you could just use the 'Shell' command which does the same thing however it is not available in VBScript. It is however available in WScript which is another scripting tool built into Windows (from 98 onwards I think).

The 'set WShell=CreateObject("WScript.Shell")' line simply creates a new WScript Shell command and gives it a handle (WShell). Later, in the Sub when you want to make the beep sound, we simply call the Run method of the object with the parameters (in this case the command line to be run) and it accesses teh WScript method and executes.

Hope that was understandable! Good Luck.

Dom
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now