Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

188 Part II Programming Fundamentals


combines a path, a file name, and the .ico extension to create four valid file names of
icons on your hard disk. In this example, you’re loading Face01 .ico, Face02 .ico, Face03.
ico, and Face04 .ico into the picture box. This statement works because several files in
the C:\Vb10sbs\Chap07 folder have the file name pattern Facexx .ico. By recognizing the
pattern, you can build a For... Next loop around the file names.

Note The message box function (MsgBox) is used primarily to slow the action down so
that you can see what’s happening in the For... Next loop. In a normal application, you
probably wouldn’t use such a function (but you’re welcome to).


  1. Click the Save All button on the Standard toolbar to save your changes. Specify the
    C:\Vb10sbs\Chap07 folder as the location.

  2. Click the Start Debugging button to run the program, and then click the Display Four
    Faces button.
    The For... Next loop loads the first face into the picture box and then displays this
    message box:


Note If Visual Basic displays an error message, ensure that your program code has no
typos and then verify that the icon files are in the path you specified in the program. If
you installed the Step by Step practice files in a folder other than the default folder, or if
you moved your icon files after installation, the path in the event procedure might not
be correct.
Free download pdf