Results 1 to 3 of 3
  1. #1
    Join Date
    May 2007
    Posts
    4

    Unanswered: ListBox-If statements

    Hi
    M learning VB 6.0 on a working model...
    M doing an asignment that alocates rooms.
    In one of my forms i have a listbox that stores 12 countires names (lstCounty)
    I have a imgFlag control that is supposed to show the picture of the country in the list box.
    m doing an if statement on click of lstCountry but i get an error.
    the pics are stores in my c drive in Flags folder....
    my code is.....

    Private Sub lstCountry_Click()
    Open App.Path & "\Flags" For Input As #1
    If lstCountry.List(lstCountry.ListIndex) = "Fiji" Then
    imgFlag.Picture = "fiji.bmp"
    End If
    End Sub

    wen i run this gives a type mismatch error........

    Can anyone help...

  2. #2
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    re

    Code:
    Private Sub lstCountry_Click()
    Open App.Path & "\Flags" For Input As #1
    If lstCountry.List(lstCountry.ListIndex) = "Fiji" Then <--ERR in here
    imgFlag.Picture = "fiji.bmp"
    End If
    End Sub
    (lstCountry.ListIndex) is of a type number not text

    lstCountry.List(lstCountry.ListIndex).text= "Fiji" is what you want i think
    Greetz Marvels -^.^-
    Developments : VB4 Through .Net; Basic; DOS ; CNC ; Sinclair
    Databases : SQL Server Through 2005; Access 3 Through 2003 ; Oracle 8 & 9.i ;
    OS : Win 3.11 Through XP ; NortonComander ; DOS

  3. #3
    Join Date
    Jan 2008
    Posts
    19
    Marvel is right: ListIndex simply returns an integer (or long?) representing which item in the listbox is selected.

    A small addition: the way you are handling the situation now would mean that you have to write a If statement for each country you have. If you can freely choose the bitmap name, you could also make it dynamic by combining the text in the listbox with the bmp extension and directly use that to load the picture to the imgFlag. But keep in mind:

    A) Maybe the picture is not available...Then what?
    B) Is it possible to make a selection which returns an error?

    PS : What is ...
    Code:
    Open App.Path & "\Flags" For Input As #1
    ...Doing there?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •