In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "vbs/js basic code method tutorial", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "write vbs/js basic code method tutorial"!
1. Our first vbs program: the same old Dongdong who lost his teeth.
* hello.vbs**
Dim hello
Hello= "hello world!"
Wscript.echo hello
Wscript echo "this is my first vbs"
You can see that wscript.echo can be used in two ways, and this is not difficult.
You can double-click to run it, and you can enter it on the command line of the current directory:
Cscript hello.vbs
2. Call other programs in the script:
Using the run () method, you must first create an instance of shell before using it.
* shell.vbs**
Set ws=wscript.createobject ("wscript.shell")
Ret=ws.run ("notepad", 3Jing true)
If ret=0 then
Wscript.echo "succeed!"
Else
Wscript.echo "there is an error,the error number is:"
Wscript.echo cstr (ret)
End if
*
Here run has three parameters, the first of which is the path of the program you want to execute
The second program is in the form of a window, and 0 runs in the background.
1 indicates normal operation
2 indicates that the program is activated and displayed as minimized
3 indicates that the program is activated and displayed as maximized
There are 10 of these parameters. I only listed the 4 most commonly used parameters.
The third parameter indicates whether the script will wait or continue to execute. If set to true, the script will wait for the calling program to exit before executing backwards.
Have you noticed that I also have a variable that accepts a return value before run. Generally speaking, if the return value is 0, it means successful execution. If it is not 0, then this variable
The return value is the error code, which can be used to find the corresponding error.
3. Inputbox and msgbox
People who know vb should be familiar with two things, and there is no difference in usage.
Input=inputbox ("please enter you password", "passwd")
If input "1234"
Then
Msgbox "you enter a wrong passwd"
End if
Of course, you can also add buttons to msgbox to accept the user's choice with a variable.
For example: ret=msgbox "continue?", vbyesnocancel
The return value is compared with the constant as follows:
Vbok 1
Vbcancel 2
Vbabort 3
Vbretry 4
Vbignore 5
Vbyes 6
Vbno 7
4. Error handling
He vb uses on error resume next as well.
There is nothing to say about this. If you encounter a mistake, skip to the next sentence.
Of course, this method is very retarded, and there needs to be a method. Vbscript provides an object err object.
He has two ways, clear,raise.
5 attributes: description,helpcontext, helpfile,number,source
We can use err.number to get the error number, for example
* err.vbs**
On error resume next
Axi11
Bust 0
C=a/b
If err.number0 then
Wscript.echo err.number & err.description & err.source
End if
We can use err.raisel to manually throw errors
For example, we need to generate a path not found error to tell the user that he has entered the wrong path.
On error resume next
Err.raise 76
Msgbox "error:" & err.description
Err.clear
Thank you for reading, the above is the content of "Writing vbs/js basic Code method tutorial". After the study of this article, I believe you have a deeper understanding of the problem of writing vbs/js basic code method tutorial, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.