Get to know the basics of coding for simple tasks

Jul 7, 2015 12:41 GMT  ·  By

Even if it at a first look some basic tools Windows provides don’t seem to be of much use, there’s a lot of potential hidden in each small utility. Yesterday we learned that simple scripts can be created in Notepad, and today we’re going to explore the area a little further.

Sure enough there’s already an app for any of the following tricks, and the effort of downloading and installing it is far less than writing and testing these codes. However, it’s always good to know that you always have an alternative at hand.

If you haven’t already found out from here or there, writing codes in Notepad can result in different pranks to play on your friends, or even useful gadgets for daily activities. So here are not three, but five neat hints.

The first step in all situations is to create a New Text Document on your desktop. Then open it and it mostly goes down to pasting some code and editing a few lines.

1 ~ Creating a Startup Reminder

For important activities you need to perform before anything else, this is a simple way of having a message prompt you when the computer starts.

The code used creates a simple message window and shows your text. First, paste this in a blank text document:

code
X=Msgbox(“YOUR_MESSAGE”,number_of_buttons,”TITLE”)
Now, replace YOUR_MESSAGE with the task you need to perform. Just remember to leave the quotation marks there.

The second part, num_of_buttons determines the type of confirmation buttons the message box is fitted with. It is represented by a number, with each one making the following buttons available:  

NUMBER BUTTON TYPE
0 Normal message box, just an OK button
1 OK and Cancel
2 Abort, Retry, Ignore
3 Yes, No, Cancel
4 Yes and No
5 Retry and Cancel
16 Critical message icon
32 Warning query icon
48 Warning message icon
64 Information message icon
4096 Always stay on top of the desktop
The TITLE is exactly what it says, and it changes the text that appears in the title bar. A neat trick is to set it to show time and date, just like in the examples below. If you want to use a code to display time and date, remove the quotation marks, but leave them for a simple text title.  
CODE DATE FORMAT
FormatDateTime(Now) 2/29/2016 1:02:03 PM
FormatDateTime(Now, vbGeneralDate) 2/29/2016 1:02:03 PM
FormatDateTime(Now, vbLongDate) Monday, February 29, 2016
FormatDateTime(Now, vbShortDate) 2/29/2016
FormatDateTime(Now, vbLongTime) 1:02:03 PM
FormatDateTime(Now, vbShortTime) 13:02
If properly written down, the code needs to look something like this:

code
Time and Date title:
X=Msgbox("It’s Tuesday. Did you bring your coat?",4,FormatDateTime(Now, vbLongDate))

Plain Text title:
X=Msgbox("It’s Tuesday. Did you bring your coat?",4,"To do Today")
Under the File menu, choose to Save As. When the save dialog appears, change the Save To Type to All files. Give it a name and change the extension to .VBS for it to work.

Now you need to make it run at startup. Press Win + R and write down shell:startup to bring up the startup folder. Copy the .VBS file there and it now runs every time you reach the desktop. When you want to change the message, simply edit the file in Notepad.  

Daily Tasks
CREATING THE SCRIPT
ADDING TO STARTUP

2 ~ Keeping a password-protected Log or Diary

This is a pretty easy procedure that creates a log file, adding a timestamp each time it’s opened.

In a New Text Document, simply write down .LOG and remember to include full stop, as well as all capital letters. Press Enter once and save your file under any name.

A timestamp is added each time the file is opened, which is also neat to tell is someone else tried to read your personal stuff.

Adding a password:

-> Install WinRAR. -> Right-click on your journal file and choose to Add to Archive from the WinRAR entry. Click on Set Password and write one down. -> This secures the journal, without the possibility to access or edit it unless the password is provided. You can edit the journal right inside the archive, with it being automatically updated.  

Password Protected Journal
CREATING THE JOURNAL
PASSWORD PROTECTION

3 ~ Close and open the CD/DVD tray

This one is rather tricky, and if some third-party application messed up the system eject CD function, it won’t work.

With a New Text Document open paste the following code:

code
set WshShell = WScript.CreateObject("wscript.Shell")
intButton = WshShell.Popup ("Do you wish to open the CD tray?", 0, "CD-Rom Mngr", 36)

If intbutton = 6 Then
Set player = CreateObject("WMPlayer.ocx")
player.cdromCollection.item(0).Eject()
OK=MsgBox ("Close?", OK)
player.cdromCollection.item(0).Eject()
Else

End If
Note: Closing the CD tray only works for optical drives fitted with proper mechanisms that push it out completely. If you have to pull it out after it popped, then you need to manually close it (i.e: laptop optical drives).

Now just save the file under a custom name, with the .VBS extension.  

Open CD tray script

4 ~ Generating random numbers

Although the code is a bit lengthy here, it generates one or more random numbers of custom length. Paste this code into an empty Text Document:

code
intHighNumber = inputbox("Please enter the highest number.","Random Number Generator")
If TypeName(intHighNumber) = "Empty" Then
wscript.quit
end if
If Len(Trim(intHighNumber)) = 0 Then
altshutdown1 = MsgBox("Nothing Entered.",4096)
wscript.quit
end if
If not isnumeric (intHighNumber) then
msg2 = msgbox("Not a number.",4096)
wscript.quit
end if
intLowNumber = inputbox("Please enter the lowest number.","Random Number Generator")
If TypeName(intLowNumber) = "Empty" Then
wscript.quit
end if
If Len(Trim(intLowNumber)) = 0 Then
altshutdown1 = MsgBox("Nothing Entered.",4096)
wscript.quit
end if
If not isnumeric (intLowNumber) then
msg2 = msgbox("Not a number.",4096)
wscript.quit
end if
intNumbers = inputbox("Please enter the number of random numbers.","Random Number Generator")
If TypeName(intNumbers) = "Empty" Then
wscript.quit
end if
If Len(Trim(intNumbers)) = 0 Then
altshutdown1 = MsgBox("Nothing Entered.",4096)
wscript.quit
end if
If not isnumeric (intNumbers) then
msg2 = msgbox("Not a number.",4096)
wscript.quit
end if
For i = 1 to intNumbers
   Randomize
   intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
strnum = strnum& "   " & Cstr(intNumber)
next
x = msgbox(strnum,4096,"Random Number Generator")
Just like before, save the file with a custom name and .VBS extension.  
Random Numbers

5 ~ Dancing disco keyboard lights

This last trick doesn’t have any practicality at all, other than a few seconds of visual fun. It makes your Caps, Num, and Scroll lock LED lights to randomly toggle on and off. Paste this code in a blank Text Document:

code
Set wshShell =wscript.CreateObject("WScript.Shell")
 do
 wscript.sleep 100
 wshshell.sendkeys "{CAPSLOCK}"
 wshshell.sendkeys "{NUMLOCK}"
 wshshell.sendkeys "{SCROLLLOCK}"
 loop
The file needs to be saved with the .VBS extension with a name of your choice.

Note: Your computer becomes close to impossible to use in this state, with window focus quickly lost. To close it, terminate the wscript or Microsoft Windows Based Script Host entry in the Task Manager.  

Disco LED

A few last words

The list of things you can do in Notepad with scripts can go on and on forever, because it’s all about how you combine different functions. In fact, this is what programming is all about, and even if it seems time-consuming and difficult, just remember that every application you’re using is based on such a thing.

How to write and use scripts (8 Images)

Simple IRL script
Startup reminderMaking the reminder run with Windows
+5more