Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 55,303 times

Contents

Related Categories

Making a picture browser in VB 6 - Linking the controls

AliNizar

Linking the controls

The strategy taken here is, by clicking the drive box, directory box should get activated showing the contents of the selected drive, and as soon as directory box updates its contents, the file list box should also update the files list in synchronization.  

As you know well, what are ‘events’, the event we would like to trap here is the ‘change’ event of directory list box, and this is because, as soon as we change the directory in the box, this event is fired. And upon this event, we will look up at what the current drive is, and with this information we want some thing to be done and this something is the updating of directory list box.  

The property of drive box we will use in the ‘change’ event is named ‘drive’ that can return the current drive of the drive box, this will return the drive’s name in the following format:  

[drive letter] [:] [volume label]

For example: c: [primary hd]  

Where the selected drive is “C:” and what follows is the volume label of the drive, but there is a little problem here, the drive property’s returned value is not very friendly as far as making the path is concerned for the directory box. A path must be something like “c:\” not as in the format we are getting right now (i.e. with volume label and no trailing slash).  

Take a look at the following code:  

Left(Drive1.Drive, 2) + "\"  

This will, in effect, solve our problem. Don’t panic! It is simple than it is looking. Because we wanted only the first two characters from the returned property, not the part ahead of it which constitutes volume label, so what we have to do here is, to truncate the result of the property to two characters starting from the left. That we have achieved by:  

Left(Drive1.Drive, 2)  

This left is a function taking two arguments separated by a comma, the first argument is the source to be chopped from the left hand side, and the second is the number of characters to be retained in the string).  

The effect of Left(Drive1.Drive, 2) is to change c: [primary hd] to c: by keeping only the first two characters from the left and leaving the rest.The rest part ( + "\") adds the back slash to the string (we call the result of this particular property a ‘string’ as it constitutes alphabets and numeric results, more on this later).  

So the code has the overall effect of changing c: [primary hd] to c:\ and that’s what we wanted.  

But why we wanted it that way? Yes, because our next task needed it badly, the setting of path property of the drive list box. Remember, till now we have been only discussing the code, not entering it. Its time now to enter the some code in the change event of the directory list box, double click the directory list box to see the coding window, make sure you are in change event and add the line written in bold (the middle line of code), after that your coding pane will show:  

Private Sub Drive1_Change()
    Dir1.Path = Left(Drive1.Drive, 2)
End Sub

Its time now to tell the directory box what to do if user intervention changes it, the same event change will be trapped here, and upon that event taking place we want our file list box to display the files of the selected directory. Put the following code in the change event of the directory box, as usual, to open the coding pane, double click the directory box (or r-click on it, select View Code or from menu, View>Code). After adding the code, (you have to add the middle line, given in bold here) the code pane will look like this:  

Private Sub Dir1_Change()
   &nbspFile1.Path = Dir1.Path
End Sub

Comments

  • Re:

    Posted by aldutt01 on 30 Apr 2007

    I am really interested in your project. would you please mail the project  to  me.

    Thanking in anticipation.

    Anand Dutta
    aldutt01@gmail.com
    aldutt01@yahoo.com

  • VB Pic Preview

    Posted by twostars on 01 Jun 2005

    I am but a newbie to VB but I think you can only do text on dialog boxes.... if it were a picture on the form then I would do it the same as viewing it - only small....

  • Question

    Posted by mocolt on 28 Nov 2004

    I have a few problem with my VB and I'm hoping someone can help me.


    I want to add a Preview in a dlg box when a user is selecting an image. I have been searching for a code but it's so hard.
    ...

  • Picture Viwer

    Posted by PaulCyberHed on 19 Nov 2003

    Ellos

    i am making a picture view i have a list of file, o n a the F drive i need to change the driver letter?

    i also need to be able to view the pictures?

    Confus:p ed

  • Posted by CombatGold1 on 10 May 2003

    i've put up www.combatgold1.co.uk/VB for all my VB projects (with source files) - its not finished yet, but when i have time i'll finish it off