Introduction: Fun With Easy VBS!!!

A Beginners guide to fun, and easy to do visual basic script. VSB may seem hard to some, but in fact it is really easy. Windows can even run it without a compiler! If you know javascript, it should be really easy for you.

Step 1: Basic Message Boxes

Ok so lets go over the Basics.

Have you ever seen a message box like the one below,
you probaly have. These are used to alert users of whatever you want to say.

You can create your own by using the Function Msgbox

So the code to a message box that says hi would look like this,

Msgbox("hi")

Alternately you can make an unkillable message box by making a simple loop by using the Do, Loop commands.

Now that we covered message boxes, lets move to more advanced message boxes.

Step 2: Games and Stuff

If you ever wonder how to make text games than look no further. I might be wrong, but I believe that they used vbs. Now a lot of vb scripts use a compiler, but windows doesn't need one. Just type cscript before the file path, now if you know how to make bat files, then you can automate this process, but we wont get into that in this instructable.

Here is a little game i made

Option Explicit

Dim Answer

'types the question

Wscript.StdOut.Write "Nice Day Isin't it? "
answer = Wscript.StdIn.ReadLine

'if you type yes t

If answer="yes" Then
Wscript.echo ("I hope it stays this way")

'If you type no

ElseIf answer="no" Then

Wscript.echo ("I hope it gets better")

'anything else

Else

Wscript.Echo ("GoodDay to you")

'end

End If

now basically save this as .vbs and use the method before to run it.

Step 3: The Auto Typer

This code it to type something over and over again. I don't know how it is useful, but if you run it, you'll have to kill it in the task list

set shellobj = CreateObject("WScript.Shell")
shellobj.run "cmd"

do

shellobj.sendkeys "Y"
wscript.sleep 200
Shellobj.sendkeys "o "
wscript.sleep 200

loop

Step 4: The Matirx Has You

Ever wondered how to make you pc talk to you?

well copy this



option explicit
On Error Resume Next

' declare variables
dim wshshell, title, mystring, length, position, tmp, loopA, loopB, linesToWrite, columns, objUser, objSysInfo, myName, myNameLength, col1, col2, col3, col4, col5, maximum, elements

set wshshell = wscript.createobject("wscript.shell")
title = "the matrix"

wshshell.SendKeys "{ALT}"+"{ENTER}"

' get user info, used to get the name
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

' ---------------------------
sub waitfor(var)
' set up window, set title, wait for it to complete
tmp = false
do until tmp
wscript.sleep 1000
tmp = wshshell.appactivate(var)
loop
end sub

' ---------------------------
sub matrix(elements)
' print random numbers to make "the matrix" look
' assumes elements is divisible by 5
columns = 5
col1 = true
col2 = true
col3 = true
col4 = true
col5 = true
randomize()
linesToWrite = elements / columns
for loopA = 1 to linesToWrite
for loopB = 1 to columns
Select Case loopB
Case 1
If col1 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 2
If col2 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 3
If col3 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 4
If col4 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 5
If col5 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
End Select
wscript.sleep 5
next
wscript.Echo

' This flip-flops columns to display 20 percent of the time, independently of each other.
maximum = 0.20
If rnd() < maximum Then
If col1 = true Then col1 = false Else col1 = true
End If
If rnd() < maximum Then
If col2 = true Then col2 = false Else col2 = true
End If
If rnd() < maximum Then
If col3 = true Then col3 = false Else col3 = true
End If
If rnd() < maximum Then
If col4 = true Then col4 = false Else col4 = true
End If
If rnd() < maximum Then
If col5 = true Then col5 = false Else col5 = true
End If
next
wscript.Echo
wscript.Echo
end sub

' ---------------------------
sub key(msg)
' do printouts of "the matrix" messages, and erase them
wscript.sleep 1500
length = len(msg)
for position = 1 to length
wshshell.SendKeys mid(msg, position, 1)
wscript.sleep 250
next
wscript.sleep 3000
for position = 1 to length
wshshell.SendKeys "{BACKSPACE}"
wscript.sleep 75
next
end sub

' ---------------------------
' start "main" execution here

waitfor(title)

For loopA = 1 To 4
Select Case loopA
Case 1
mystring = "wake up, Neo..."
Case 2
mystring = "The matrix has you..."
Case 3
mystring = "Follow the white rabbit..."
Case 4
mystring = "Knock knock..."
End Select
' now print out the correct string
key(mystring)
next

'_ _ _ _ _ _ _ _ _ _

wscript.quit()


save it to C:\temp as matrix.vbs

the create the bat files


@echo off
color 0a
title the matrix
set /p matrix= | cscript /nologo

(Replace this with your path to the vbs file)

exit
set /p matrix=


Name that RabbitHole.bat. Then run it!!

this is an cool, but advanced thing to do with vbs

I just put it in because it is awesome

Step 5: End

There you go


The skys the limit to what you can do