Results 1 to 37 of 37

Thread: Listbox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    A combo box has a property of text, if you use this property whatever is slected in the combo box is equal to the text property. If you have a list box what is the equivalent for this? In other words if I fill a listbox and want to select sometyhing out of it what is the property for this?

  2. #2
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Talking Check it out

    This is how you select something in a listbox
    List1.Selected(Index) = True

    If you have five entries in the listbox, then Index should range from 0 to 4.

    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    If you are filling this list box in dynamically then how owuld you identify the item? I can't hard code the index number in because the list box is being filled in a runtime.

  4. #4
    Guest
    The Listbox has a .Text property for when something is selected.

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    If you are allowing multiple items to be selected (i.e. if the MultiSelect property is set to 1-Simple or 2-Extended)then you should probably use a formula similar to this....

    Code:
    
        Dim iCt As Integer
        
        For iCt = 0 To (List1.ListCount - 1)
        
            If List1.Selected(iCt) = True Then
            
                Debug.Print List1.List(iCt)
                
            End If
        
        Next iCt
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    When I use the text property and try and open the file selected it opens acrobat reader (I am using the shell command) and then it says cannot open file, file does not exist. I know that it does because I can go to the directory and find it.

    Here is the code

    If lstQuery.Text <> "" Then
    Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\") & lstQuery.Text, vbMaximizedFocus
    Else
    MsgBox "Please select a file from the list box", vbExclamation
    End If

    This list box gets filled in according to a query that I wrote.

  7. #7
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Don't use lstQuery.text, instead use lstQuery.list(iCt) to retieve the filename in your listbox.
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  8. #8
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Talking I got it...

    qoute:
    Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\") & lstQuery.Text, vbMaximizedFocus

    remove the second bracket, and place it after lstQuery.text like this:
    Shell ("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text), vbMaximizedFocus
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    How owuld I set the index argument to what ever is selected. In other words if I put this piece of code in it still wants a value for iCt. How do I tell it that iCt is equal to whatever is selected?

  10. #10
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Thumbs up I actually meant this

    Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  11. #11
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    If you want to return the current index of the listbox then use this

    Code:
       List1.List(List1.ListIndex)
    but I think that has the same effect as List1.Text??
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  12. #12
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    use lstQuery.List(lstQuery.ListIndex)
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  13. #13
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    'Make a loop like this one
    For Index = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(Index) = True Then
    Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
    Else
    MsgBox "Please select a file from the list box", vbExclamation
    End If
    next Index
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    List Files?????

  15. #15
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    by lstFiles, I really meant lstQuery... alright.
    Just one little tip...
    use the listIndex property, if your lstQuery is not set to multiline. Otherwise use the loop I'd given you, for multiline selections, it's more accurate.

    enjoy coding...
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Ok when I do this it works great, there is only one thing that is holding me back I believe. I still get a file not found error the problem is that it is not seeing the .pdf extension on the file name. Here is my code (rabih's actually)

    For index = 0 To lstQuery.ListCount - 1
    If lstQuery.Selected(index) = False Then
    Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text, vbMaximizedFocus
    Else
    MsgBox "Please select a file from the list box", vbExclamation
    End If
    Next index

    If I put a break point on the line

    Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efile's\" & lstQuery.Text,


    It will get the file selected at lstquery.text (if I put my mouse over that it has the correct file name in it). The problem is that the file does not have the .pdf extension, is there a way to tack that on automatically?

  17. #17
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Listen Brian:
    1. Are using a ListBox or a FileListBox ?
    If you're using a ListBox then how are you filling it? Show me your code...
    If you're using a fileListBox then file extensions, are automatically added to each file.
    If you haven't used FileListBoxes before... they are just like ListBoxes but mainly for displaying the contents of folders, eg: if you place a FileListBox on your form called File1 then add this to form_Load

    Private Sub form_Load()
    File1.Path = "G:\efile's\"
    End Sub

    then you'll see all the files in that directory complete with an extension.
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Sorry for my ignorance on the subject and I appreciate your patience. I am using a listbox. The following code is how I fill it (through a query with parameters that are passed through an input box).

    Dim strSql As String
    Dim strLName As String
    Dim rsdigiID As New ADODB.Recordset
    Dim condigiID As New ADODB.Command

    lstQuery.Clear
    dbConnect

    strLName = InputBox("Please enter the Last Name that you would like to search for")

    If strLName = "" Then
    MsgBox "Please enter a Last Name", vbOKOnly
    Exit Sub
    End If

    strLName = "select * from tbldigidoc where tbldigidoc.L_Name like '" & strLName & "'"
    With condigiID
    .ActiveConnection = cnndigi
    .CommandType = adCmdText
    .CommandText = strLName

    Set rsdigiID = .Execute()
    End With

    Do Until rsdigiID.EOF
    lstQuery.AddItem rsdigiID("Name_of_Document")
    rsdigiID.MoveNext
    Loop

    rsdigiID.Close
    Set rsdigiID = Nothing
    Set condigiID = Nothing

    What next?, Thanks a lot!

  19. #19
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    'Change this line, Hope this one works
    Do Until rsdigiID.EOF
    lstQuery.AddItem rsdigiID("Name_of_Document") & ".pdf"
    rsdigiID.MoveNext
    Loop

    Tell me what happens, Okay
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Well it worked and it didn't at the same time. When I placed that in there it did put a .pdf on the end of it but it still gives the message, filke not found. Ahhhhh! I going nuts with what should be a simple function, anyway any ideas?

  21. #21
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Brian...
    I'm going nuts too, and my TV got screwed up all of a sudden. If you feel like it, email me with your project files at my email address [email protected]... and I'll see that your code should hopefully run.
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  22. #22
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Listen Brian...
    Sometimes while you're coding, you run into dead ends. You face tiny problems that seem really silly and that could drive you mad. Those kind of situations, are solved with persistance and only persistance. Keep debugging, and use trial and error till you solve it. And when you do, you'd have learnt a valuable lesson.
    By the way, how old are you?
    I'll goto bed now, good luck.
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  23. #23
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi! Brainh, May be you can try to remove those single qoute in your directry name and use the Trim() function before you add any data into your listbox:

    Code:
    'Do use the With Statement, to speed up your performance too
    With rsdigiID 
        If .RecordCount <> 0 Then
           'To ensure all the data is sort accordingly   
           .MoveLast
           .MoveFirst      
           Do Until .EOF 
              'To ensure there is no leading/trailling space
              lstQuery.AddItem Trim(.Fields("Name_of_Document")) 
              .MoveNext 
           Loop 
        End If
    End With
    Code:
    Option Explicit
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_ERR = (-1)
    Private Const LB_GETCURSEL = &H188
    
    Private Sub Command1_Click()
    Dim Idx As Integer
    'Get the current list index
    Idx = SendMessage(lstQueryList.hwnd, LB_GETCURSEL, 0, 0)
    'If not error
    If Idx <> LB_ERR Then
        Shell "C:\Program Files\Adobe\Acrobat 4.0 Reader\AcroRd32.exe G:\efiles\" & lstQueryList.List(Idx), vbMaximizedFocus
    Else
        MsgBox "Please select a file from the list box", vbExclamation
    End If
    End Sub

  24. #24
    Addicted Member c@lle's Avatar
    Join Date
    Oct 1999
    Location
    Belgium
    Posts
    179
    hey, if you want you can use the following code. With this you can open the associated program (like doubleclicking on the file in the explorer)

    Code:
    'function to start file with associated program
     Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
     Dim lngResult As Long
     Dim sFile As String
        sFile = "c:\temp\test.pdf"
        'this will open acrobat reader
        lngResult = ShellExecute(hwnd, "Open", sFile, "", "", vbNormalFocus)

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Well I will try these different methods, I am on Pacific Time so I just got to work. Rabih I am 25, probably a little older than you expected. I am a network administrator (Netware 4.11) but have jumped into this VB project.

  26. #26
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Replace your cmdView_Click

    'I just added the trim function here, 'cause your DB may have the Name_Of_Document containing unnecessary spaces
    'tell me what happens
    Private Sub cmdView_Click()
    If lstQuery.List(lstQuery.ListIndex) <> "" Then
    Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe G:\efile's\" & Trim(lstQuery.List(lstQuery.ListIndex)), vbMaximizedFocus
    Else
    MsgBox "Please select a file from the list box", vbExclamation
    End If
    End Sub
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    You'll never guess what happened. It will open some files and not others. I went to confirm that a certain file was there and ried to open it and it opens Adobe Acrobat and then gives me the error message (Cannot open file, file does not exist). I try another one and it works fine... AHHHHHHHHHHHHHHHHHHH, am I going nuts? By the way how old are you?

  28. #28
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    I'm 23, just two years younger than you. I bet you thought I was 14 or something. You won't believe it, by some of the VB gurus on this forum, are this old. AAHHHHHHHHH, I'm ready to help you, tell me exactly what went wrong this time? Atleast, something worked right.. !
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    OK here goes:

    When I run one of the queries it fills the list box as it should. I then click on one of the names in the list box and click on the view button. Each time it will being up Adobe Reader as it should but sometimes it (Adobe) will say "There was an erro opening this document, this file does not exist", and about 50% of the timew it will actually open the file. I am verifying that the files exist and I have tried it with files created by different owners, the only thing else that I can thing of as far as file properties is size, I have also tried it with various dates. There is know sensible explanantion that I can come up with right now, thanks for all of your help.

  30. #30
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Could it be, that you're logged on as a user, and when you try to open files belonging to other users, that could be inaccessible to you.?
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    No because I have supervisor rigths to the root. I can opne any file in my container. I have tried opening various files, it doe snot matter how big or small, date created, owner, file name size, anything. I can't seem to pin point what is causing the inconsistency.

  32. #32
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Thumbs up

    You know what Brian? you're facing many problems, due to the way the Name_Of_Document field is storing document names. Even though we are trimming unnecessary spaces from Name_Of_Document... what if the filename actually contains a space just before the dot and the extension.

    To demonstrate this problem, this is an example:
    If you have a file called Pamela.pdf, that is stored in the Name_Of_Document field as Pamela .pdf - that's with a space- then we display the name in the lstQuery as Pamela.pdf 'cause we trimmed it. Now this works fine.

    But if you have a file called Pamela .pdf -with a space in it- then you display it in the lstQuery without the space as Pamela.pdf after being trimmed. So when you try to run it, it won't... 'cause it expects a file called Pamela .pdf. You get my point.

    So this problem as I said, is due to the way you stored the document names in the database under Name_Of_Document... You must check each filename and whehter it contains any Leading or tailing spaces in your directory and thier correspondent names in the database. You could also code a small program to do that trimming in the database for you.
    That's as much as my grey cells could do, Brian...
    Tell me what happens? alright
    Remember what I said about persistance... You need patience too.
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  33. #33
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Well...

    Brian, you had a lunch break.. or what?
    Keep me updated, will you ?
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Sorry, I have to take care of some user problems and on top of that my email portion of the application just stopped working. What a day. There is no reason for that part to stop functioning as I have not made any changes to the coding. Anyway, I will let you know as soon as I can about the other part I am just trying to catch my breath. If you have anymore suggestions I sure would appreciate them and thank you for your help thus far.

  35. #35
    Junior Member
    Join Date
    Nov 2000
    Posts
    21
    Wow, I finally connected.
    I know you're too busy Brian, take your time...
    I'm always there...
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Well you figured it out. It was a space problem. The DB had a space in the names and the files did also but when I trimmed the name at the list box it would cause an error because that was not the correct name anymore. I have manually changed all of the names that were like that to get rid of all spaces (there were only about 45 entries). I have also got it so it trims the name before renming it. I hopefully have got this one tasken care of. Thanks for all of your help, I could have not made it without you!

  37. #37
    Junior Member
    Join Date
    Nov 2000
    Posts
    21

    Wink

    I'm really happy Brain, that things are working out fine for you. W
    ish you all the best, in your coding...
    Cheers
    Rabih Waked
    Using Visual Basic 6 Enterprise Edition with SP4.
    The clock is ticking, the end of days
    A journey awaits...

Posting Permissions

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



Click Here to Expand Forum to Full Width