VB-Extras

Programming Extras

=1) How to link out to a web site= CreateObject("Wscript.Shell").Run "place url here in quotes"

Ex: CreateObject("Wscript.Shell").Run "www.youtube.com/watch?v=BCh4do5_Gv4" = = = = =2) Debugging: @http://www.cs.cofc.edu/~hci-group/VB50/HTML/debugging.html=

= ** 3) SOUNDS ** - Visual Basic can play sound files using a control you need to place in the tool box. (Tech needs to give students access to c:\program fileDevStudio) =

Play MP3:

1) Add a component to your toolbox & Place Object on form

· Go to your Project menu, Components, this will bring up a menu of checkboxes. · Go down to “WindowsMediaPlayer", and check it and click APPLY (ignore the error)  · Notice the new object in your toolbox - Blue Square with an Orange Play button.   · Click on this new object, and place it on the form.

2) Property to set the music file is URL. It can be added to property box to play automatically on form load or coded in Form_Load showing path of .mp3 file. Enable TRUE or FALSE can turn it on a specific times.

>>> Example: >>> WindowsMediaPlayer1.URL = "\\data\student\2012\kentn\0-zone.mp3"
 * WindowsMediaPlayer1.URL = "P:\HHS\Programming\Fall_2012\o-zone.mp3"
 * From your u: account, need:
 * WindowsMediaPlayer1.URL = "\\data\student\20xx\username\0-zone.mp3"

Play midi, wave or avi: 1) Add the Component MMControl1 same as the directions above.

2) The property needed is filename

3) Document for understanding the copyright rules for using music for educational projects: []

Students may use copyrighted songs if: 1) they have purchased it legally 2) They do not use more than 30 seconds or 10% of the song (which ever is less). Copyright free link but must be sited in the credits. []

If you need .mp3’s you can rip them from You Tube using

[|http://www.video2mp3.net/]

=3) Compiling Code= *Not available in Learning Edition

Right now, in order to run your program, you must be in the Visual Basic program. You can make your program an executable program (.exe). Visual Basic has a built in compiler to translate the program code into an exe file, which can run on any Windows95 or later operating system, if it has the right library file (MSVBVM50.dll). In this exercise, you will make your code executable, and learn how to add the necessary files to Win95 to make it run on any machine.

1) Open your program in Visual Basic

2) FILE - Make filename.exe (save to g:)

(This will make an executable of your program on your flash drive on any machine that already has the MSVBVM50.dll file in c:\windows\system directory)

Adding MSVBVM50.dll File

In your reading folder, I have added MSVBVM50.dll and MSVBVM50.exe. MSVBVM50.dll is the actual library file needed to run your code, but it may be too large to fit on your flash drive with your exe program. MSVBVM50.zip is the same file zipped. MSVBVM50.exe is the same file zipped and ready to be unzipped.

1) Copy MSVBVM50.exe to your flash drive 2) Bring flash with your program exe and MSVBVM50.exe to any machine 3) Double click on MSVBVM50.exe and save to c:\windows\system Double click on your program and it should run

=4) Extra buttons for message boxes:=

Dim response As Integer response = MsgBox("Text Here", vbYesNo, "title of msg box goes in here") If response = vbYes Then 'actions ElseIf response = vbNo Then 'actions End If

=5) Sequential Files= =A sequential file is a text file that holds data for your program. It’s advantage over just storing in variables is that you can update the data and not reset it every time the program runs. For example, in the ATM program, you could store the last balance and reuse that instead of setting it back when the program runs again.= =To Use:= =1. You must first create a file in NotePad and save it= Open Notepad (Start, All Programs, Notepad)

Enter a value or pin &balance (separate with comma)

Type 5000 or Type 1234, 5000 Save as user.txt (Text Only) I would suggest in c:\ as opposed to your U drive for now =2. In VB, code it to input the balance= =You need a codenumber (usually #1) to reference the file and you need to specify if you are opening it for input or output. To use for the ATM program:=

Open"c:\user.txt" For Input As #1 = = Input #1, b

or

Input#1, p, b = = Close #1 =3. Before you exit the program, code to overwrite the balance.=

Open "c:\user.txt" For Output As #1 = = Print#1, b or Print#1, p, b = = Close #1 End __ = = =Multiple Users= = = If you would like to have a file with many users, create the text file with one line per userand use a loop to get them all in. EOF means end of file and is an invisiblemarker for the computer. = = Open"f:\grade\account\user.txt" For Input As #1 = = Do while not EOF = = Input#1, p, b = =

= = 'check if match = = Ifp = 1234 then exit do = =

= = 'OR add to list box for processing later - need 2 ifpin & bal = = list1.additem b = = list2.additem b = = Loop = = Close #1 = =

= = = =