Results 1 to 12 of 12

Thread: [RESOLVED] Outputting to a listbox

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Resolved [RESOLVED] Outputting to a listbox

    Hi Everyone,

    What am I doing wrong in this code?

    VB Code:
    1. lstDrive = lstDrive.AddItem & objDisk.DeviceID & vbNewLine

    It is giving me this error:

    Compile Error:
    Argument not optional


    I had this code outputting to a textbox using the code below. Now I would like it to go to a listbox instead.

    VB Code:
    1. lblID = lblID & " " & objDisk.DeviceID & vbNewLine
    Last edited by skakels; Apr 7th, 2006 at 11:42 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outputting to a listbox

    You don't need vbNewLine with a ListBox.

    Only one entry per line will ever be added.

    Also, you don't need the concantination. For your listbox, all you need is
    VB Code:
    1. lstDrive.AddItem objDisk.DeviceID

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    OK,

    I took out the "vbNewLine" and used the code below.

    VB Code:
    1. lstDrive = lstDrive.AddItem & objDisk.DeviceID

    It is still giving me the :

    Compile Error:
    Argument not optional

    Then it highlites ".AddItem"

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outputting to a listbox

    Quote Originally Posted by Hack
    Also, you don't need the concantination. For your listbox, all you need is
    VB Code:
    1. lstDrive.AddItem objDisk.DeviceID
    This was the rest of my last post.

  5. #5

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    ahhh, i c i c. It works now.

    Hack,

    I am trying to use a computer name (that was entered as data) from textbox "txtLookup", and I am trying to combine it from output from a listbox that gives a drive letter (example, C: ) how do I make it so that if I double click the "C:" inside of the listbox, it will open the machine's root of "C"?

    I have this so far:
    VB Code:
    1. Shell "explorer " & "\\" & txtLookup & "\C$", vbNormalFocus

    But how do I pull in the "C:"? I don't know how to get rid of the ":" after the C.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outputting to a listbox

    You are designating a drive and a folder, so you need the ":"

    You would also need the "\" so that your program knows that you are going after "c:\"

  7. #7

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    This is an example of the address that I will need:

    \\COMPUTERNAME\C$

    "COMPUTERNAME" is in the textbox "txtLookup"
    "C:" is in a listbox called "lstDrive"

    VB Code:
    1. Shell "explorer " & "\\" & txtLookup & "\C$", vbNormalFocus

    The above code outpute "\\COMPUTERNAME\C$"

    How do i strip the ":" away from the "C:" (located in the listbox), and have it go the address above?

    Could you please show me the code? Thank ya.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outputting to a listbox

    I'm a little confused. Do you need to replace the ":" with a "$" so that the end result is C$ instead of C:?

  9. #9

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    yes sir

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Outputting to a listbox

    Well, there is a couple of ways you can do it.

    Lets start with the textbox. You can replace the ":" with "$" in the textbox itself so C: never even gets to your Listbox, which, of the differenant ways, is the one I would recommend.
    VB Code:
    1. Private Sub txtLookUp_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = 58 Then KeyAscii = 36 'this will replace : with $ when you are typing
    3. End Sub

  11. #11

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    Hack,

    I don't think we're on the same page. My listbox displays drive letters (example, C:, D:, G: ). I want to be able to double click the drive letter, and launch an explorer window to that drive on the remote machine. I want to be able to do this by pulling the computer name (for the remote machine) from "txtLookup".

    I hope this helps you. I'm sorry I am making this confusing.
    Last edited by skakels; Apr 7th, 2006 at 12:58 PM.

  12. #12

    Thread Starter
    Registered User
    Join Date
    Apr 2006
    Posts
    139

    Re: Outputting to a listbox

    OK, I figured it out. I made the below code and it works well. The only problem is that I had to do it for every letter in the alphabet. If anyone has a shorter way to do it, hit me up. I'd like to see it. Thanks guys for all your help.

    VB Code:
    1. If lstDrive = "C:" Then
    2.         Shell "explorer " & "\\" & txtLookup & "\C$", vbNormalFocus
    3.     End If

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