Ok so some people have been asking me where did i learn my vbs from .. i learned from various websites, like the w3schools , even know that is for web scripting you can still use it from plain vbs.

I learn it from websites you'll learn it from me =D

So lets get started ...

What is vbs?
VBScript is a Microsoft scripting language. -_- so being Microsoft they go and make it so it only works on IE. But as well as being a web script it is used for all kinds of things ...
for example on pic 2) (that's the second pic) That is take from the System 32 folder. Vbs can also be used to make programs .. but that's VB.NET .. uses most of the same coding though.

Please enjoy the tutorial .. and please comment and rate.
And please tell me if someone has beet me to making a vbs tutorial .. but i couldn't find one.
Other than cammel8 who seems to be really good with vbs scripting =P .. but i'm still gonna make the tutorial.

Step 1: Basics of Vbs

Ok so here are the basics .. stuff you should already know ...

You save the files as: something.vbs
It's not like a batch file it doesn't have a screen telling you information.
In a way it's much like javascript. But at the same time it's nothing like it.

to make a var you use dim
e.g .. dim iRule
now you would have a variable call iRule

now you can start to add things to you vars .. like:
this would make a message box pop up saying hello. (pic 1)

Along with that you can add different buttons to the message box ..
here is all about message boxes: HERE
so many tutorials on them that i won't even bother to go into them.

Also with vars you can dim vars in an array:
dim iRule(3)
but that would turn out like this: (because 0 is included)


Using vars in the script..

You can use vars easily ..
you could have: (pic 2)

dim iRule
dim instructables


instructables=msgbox("hello " & iRule)

Because of the & it says 'hello instructables' becuse the value of iRule is instructables.


You can also have subs:
A sub is a procedure that does NOT give a return value.

Sub iRule(arg1,arg2,arg3)
End Sub

The arg 1,2,3 are the Arguments.

That about all of the basics .. enjoy them .. or keep reading for not so basics..
<p>About 6 years after the original post. Have just read this tutorial. Thumbs up to the original poster (aka IRule). The world needs more people like this - that show how to start making things happen and easy to follow (like in this tutorial). I didn't know any vbs scripting at all before. This tutorial is starting me off, and I think it is great.</p>
<p>I have made a program, it writes the basic HTML code for you in notepad all you have to do is edit.</p><p>Want to download the vbs file?</p><p>Visit: http://htmlbuddy.blogspot.com/</p>
<p>Hey dude! I have made a password protect VBS. When you enter the correct password into the inputbox I want it to open a .bat file which is located in the same folder as the VBS. But I can never find the right way to open the .bat via vbs. Here is the current code:</p><p>Option Explicit</p><p>Dim returnvalue, pass, Shell</p><p>pass=&quot;test&quot;</p><p>returnvalue=inputbox(&quot;Enter password&quot;)</p><p>If returnvalue=pass then</p><p>msgbox(&quot;Password correct!&quot;)</p><p>set Call=createobject(&quot;wscript.shell&quot;)</p><p>Call.run &quot;Hack Client.bat&quot;</p><p>set Call=Nothing</p><p>Else</p><p>do</p><p>msgbox(&quot;Password incorrect!&quot;)</p><p>loop</p><p>End If</p><p>Plz help me. Thanks!</p>
<p>First where is the folder located?</p><p>To find this out right click go to properties and click general.</p><p>Reply to me then I can help fix this error.</p>
<p>I have this script:</p><p>Set WshShell = CreateObject(&quot;WScript.Shell&quot;)<br>dim a<br>a = &quot;C:\Program Files (x86)\MyProgram\MyApplication.jar&quot;<br>WshShell.Run &quot;javaw -jar &quot; &amp; a</p><p>but when i execute, i got error message: </p><p>&quot;Error: Unable to access jarfile: C:\Program&quot;</p><p>Please help. How to fix this?</p><p>Thanks</p>
<p>Two errors found while I looked through your code.</p><p>First Error &quot;a=&quot;</p><p>Second Error &quot;C:\Program Files (x86)\MyProgram\MyApplication.jar&quot;</p><p>How to fix:</p><p>First of all instead of &quot;a=&quot; type wshshell.run</p><p>Second type &quot;&quot;&quot;C:\Program Files (x86)\MyProgram\MyApplication.jar&quot;&quot;&quot; where </p><p>&quot;C:\Program Files (x86)\MyProgram\MyApplication.jar&quot; is.</p><p>I did not understand the </p><p>WshShell.Run &quot;javaw -jar &quot; &amp; a</p><p>So I hope this helps.</p>
<p>@bayuforest</p><p>Try to do it with escape characters, because you have spaces in the file path. So the code would be:</p><p>a = &quot;&quot;&quot;C:\Program Files (x86)\MyProgram\MyApplication.jar&quot;&quot;&quot;</p><p>(yes with three &quot; before and after the path)</p><p>Cheers and have fun coding.</p>
<p>Can you tell me how to make the red X work please? I am just trying to close my message box</p>
visual basic 10.
<p>I was searching for this a very long time.. Thanks U saved my time</p>
<p>Does the case look for the actual variable, and not the value? </p>
How would I end this code? <br> <br>a=InputBox(&quot;Do you like Cheesecake?:&quot;,&quot;Var&quot;) <br>if var=yes then <br>msgbox (&quot;YAY! I like cheesecake too!&quot;) <br>if var=no then <br>msgbox (&quot;Aww..... You suck. Cheesecake is the best!&quot;) <br> <br>It's probably something obvious.
i looked over this script and it was kind of right but the if&nbsp;shouldn't&nbsp;be <strong><em>var= </em></strong>it should be<strong><em> a </em></strong>as that is the input box name. Also it took me a while to work out why it&nbsp;wasn't&nbsp;working but turns out that you&nbsp;hadn't&nbsp;declared&nbsp;the var and that was last thing i thought of lol, here it is working.<br> ..........<br> dim a<br> a=InputBox(&quot;Do you like Cheesecake?:&quot;,&quot;title&quot;)<br> if a=(&quot;yes&quot;) Then<br> &nbsp;msgbox(&quot;YAY! I like cheesecake too!&quot;)<br> elseif a=(&quot;no&quot;) Then<br> msgbox(&quot;Aww..... You suck. Cheesecake is the best!&quot;)<br> else<br> msgbox(&quot;Enter yes or no!&quot;)<br> End If&nbsp;<br> ..........<br> hope it helped, sorry for the slow reply.
<p>I know it's two years ago but I've played a bit a made this</p><p><br>dim a</p><p>a=InputBox(&quot;Do you like Cheesecake?:&quot;,&quot;title&quot;)</p><p>if a=(&quot;yes&quot;) Then</p><p> msgbox(&quot;YAY! I like cheesecake too!&quot;)</p><p>elseif a=(&quot;Yes&quot;) Then</p><p> msgbox(&quot;YAY! I like cheesecake too!&quot;)</p><p> elseif a=(&quot;No&quot;) Then</p><p>msgbox(&quot;Aww..... You suck. Cheesecake is the best!&quot;)</p><p>elseif a=(&quot;no&quot;) Then</p><p>msgbox(&quot;Aww..... You suck. Cheesecake is the best!&quot;)</p><p>else</p><p>msgbox(&quot;Enter yes or no!&quot;)</p><p>CreateObject(&quot;WScript.Shell&quot;).Run(&quot;&quot;&quot;cheesecake.vbs&quot;&quot;&quot;)</p><p>End If </p><p>Hope it's good :) It'll loop (if filename is cheesecake.vbs) until you write &quot;Yes&quot;, &quot;yes&quot;, &quot;No&quot; or &quot;no&quot; :)</p>
SORRY for the REALLY slow reply. Thanks man!
End If.
<p>A little bit complex.</p>
I could barely understand what it was you were saying about the vbs to batch conversion. I am trying to find a good converter online but f2ko's vbs to exe doesn't work(I have a batch to exe so I could convert vbs to batch to exe). I looked at this method and am trying to figure it out but you didn't say what I should do. I copied and pasted the vbs code into notepad and created the vbs, and it works when I run it, but what do I type in on the line? A msgbox script? One word? I also tryed making a file called test.bat and put in in the same file folder, opened the vbs tryed a msgbox script and word and nothing happened. I then tryed pasting the &quot;Batch&quot; code (you didn't say what that is for either) in test.bat and all it does is pop up some cmd window that says whatever I typed into the vbs (and not a vbs window) somethin it also says sometimes is an error with line 5 character 1. What is the correct Character? Please give me a full explaination on exactly what I sould do. Thanks
i am confused as to why you are confused ? Are you trying to make a <em><strong>vbs </strong></em>into a <em><strong>exe </strong></em>? if so, then if the f2ko converter does not work i do not know of what else to use, as i do very little scripting in actual vbs, meaning i have little need for them as exes.
set shellobj = CreateObject(&quot;WScript.Shell&quot;) shellobj.run &quot;notepad&quot; shellobj.sendkeys &quot;I &quot; wscript.sleep 1000 shellobj.sendkeys &quot;S&quot; wscript.sleep 1000 shellobj.sendkeys &quot;E&quot; wscript.sleep 1000 shellobj.sendkeys &quot;E &quot; wscript.sleep 1000 shellobj.sendkeys &quot;YOU!!! &quot; wscript.sleep 1000 shellobj.sendkeys &quot;{ENTER}&quot; wscript.sleep 4000 shellobj.sendkeys &quot;{ALT+F4}&quot;
<p>A great tutorial<br /> btw, can you send me the code of the batch notepad i modified for you? I recently upgraded to a better pc and lost the file<br /> thx<br /> &nbsp;</p>
Set wshShell =wscript.CreateObject(&quot;WScript.Shell&quot;)<br/>do<br/>wscript.sleep 200<br/>wshshell.sendkeys &quot;{NUMLOCK}&quot;<br/>wscript.sleep 100<br/>wshshell.sendkeys &quot;{CAPSLOCK}&quot;<br/>wscript.sleep 100<br/>wshshell.sendkeys &quot;{sCROLLLOCK}&quot;<br/>wscript.sleep 200<br/>wshshell.sendkeys &quot;{sCROLLLOCK}&quot;<br/>wscript.sleep 100<br/>wshshell.sendkeys &quot;{CAPSLOCK}&quot;<br/>wscript.sleep 100<br/>wshshell.sendkeys &quot;{NUMLOCK}&quot;<br/>loop<br/><br/>turn off numlock and run that<br/>
Do you mean <a rel="nofollow">SendKeys</a> method?
That's a lot like my loader:<br/><a rel="nofollow" href="https://www.instructables.com/id/keyboard_led_loader/">LED Loader</a><br/><br/>so what do you want it to do?<br/>
.... i never saw that i did 'cuz i was funny as hell
Do you know the script that find a path where is a script saved?<br /> (Because in vb6 it is in var AppPath)&nbsp;
i don't quite get you ....<br /> if you want a path can't you just type it in without the app.path ?<br /> then again I've never used VB6 so I'm still not sure what app.path does.<br />
is it possable to replace a shortcut target in VB? Whats the code? thanks
you want to change where a shortcut goes to ?<br/><br/>Set sh = CreateObject(&quot;WScript.Shell&quot;)<br/>Set shortcut = sh.CreateShortcut(&quot;shortcut.lnk&quot;)<br/>shortcut.TargetPath = &quot;C:\where eva&quot;<br/>shortcut.Save<br/>
yes, like poping up a mesagebox when I accidently click Internet explorer (I use Firfefok)lol is that the code? what other "objects" can I create? thanks a bunch sorry for all the quetions! Mike
yes that's the code , just save that script to a<strong> .vbs </strong> then change <strong>shortcut.ink</strong> to the name of your file and change <strong>C:\where eva</strong> to the new location you want the shortcut to lead ... <br/>e.g: <strong>shortcut.TargetPath = &quot;C:\folder\test.vbs&quot;</strong><br/><br/>the get object is used for certain functions:<br/><a rel="nofollow" href="http://msdn.microsoft.com/en-us/library/d5fk67ky%28VS.85%29.aspx">example</a><br/>different scripts need to call different functions.<br/>e.g the <strong>CreateObject(&quot;SAPI.SpVoice&quot;) </strong> is used to make the pc talk.<br/>
Oh, Thanks alot for taking the time to reply! Thanks again :)
hey do you know how to set a button like if i did yes and no buttuns then if i press yes some thing will come up but if i press no somethingelse will com up
simple version:<br/><hr/>Set objShell = CreateObject(&quot;Wscript.Shell&quot;)<br/>msg = Msgbox(&quot;Press yes to say hello.&quot;,36, &quot;Hello?&quot;)<br/>If msg = vbYes Then<br/> msgbox(&quot;Hello =]&quot;)<br/>Else<br/> Wscript.Quit<br/>End If<br/><hr/>Says hello if you press yes<br/>Quits if you press no<br/>Does nothing if you press the X .. so you have to answer =]<br/>Also: <a rel="nofollow" href="http://www.w3schools.com/vbscript/func_msgbox.asp">LINK</a> - will help<br/>
is there anything simpler?
no that the simplest way that i know of sorry =/<br/>btw its : dont need the top line of old 1<br/><hr/>msg = Msgbox(&quot;Press yes to say hello.&quot;,36, &quot;Hello?&quot;)<br/>If msg = vbYes Then<br/>msgbox(&quot;Hello =]&quot;)<br/>Else<br/>Wscript.Quit<br/>End If<br/>
thank you irule
this is a great tutorial, and it could finally get me going in vbs, thanks a ton!
Glad i could help

About This Instructable




More by iRule:Screen Lock (VB.NET) VBS Tutorial - Basics Batch Maker 
Add instructable to: