lazy saunter

(personal learnings in computation)

Friday, February 02, 2007

how much VB do you know?

someone asked me how good i was at writing VB scripts this morning. at least one other person has wanted to give me a VB quiz to see how good a programmer i was. the fact is, i have never written a VB (visual basic) script in my life. one time i installed Visual Studio to try to play around with VB but i didnt understand what all the buttons did.

so it surprised me when someone wanted me to create a VB program whose icon you could click on and it would tell you what OS you are running and gave me a book and i had the program working in under an hour. if you google "visual basic tutorial" most of the sites say "step one- open up visual studio". well, i just wanted to write something in notepad and run it from the command line or run it by double clicking on its icon.

in the windows, there are registry keys which are where information such as the OS type are stored. you can see these by executing "regedit.exe" from the command line. the VB program looks at the registry key which corresponds to the OS type, gets it, and shows that value in a popup window.

as far as i can see, this only requires nine lines of code. i got most of this from a text book but i had to figure out which registry key to get and modify it appropriately. here's the code:

Option Explicit
On Error Resume Next
Dim objShell
Dim regVersionName
Dim ComputerName, VersionName

regVersionName = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName"

Set objShell = CreateObject("WScript.Shell")
VersionName = objShell.RegRead(regVersionName)

WScript.Echo VersionName & " is the OS version"

i am surprised VB is so easy after i thought it was so complicated when i first tried to use it.

1 Comments:

  • At 7:05 PM , Anonymous Anonymous said...

    Man, I wish that would happen to me with Japanese!

     

Post a Comment

Subscribe to Post Comments [Atom]

<< Home