Results 1 to 31 of 31

Thread: [RESOLVED] message box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Resolved [RESOLVED] message box

    At the moment I have a message box that you can type in a user name to get to a file in a folder (ex: C:\User.txt) (User being the username entered).

    How can I get the list box to list all the .txt files in the C:\ folder so the Username does not have to be typed and only has to be clicked and opened.
    Last edited by lilwupster; Mar 2nd, 2006 at 11:54 AM.

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: message box

    to view files inside a directory, use the filelistbox
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    I know that, but can I get that in a message box?

  4. #4
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: message box

    you mean you want to put a filelistbox in a message box?
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    yes, if possible

  6. #6
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: message box

    well you cant do that with a message box but it is posible, just create a customized form, design it to look like a message box. place the controls you want on it and show it in vbmodal mode

    VB Code:
    1. Form1.Show vbModal
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: message box

    Something like:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim strBuff As String
    5.  
    6.     strBuff = Dir$("C:\Temp\*.txt")
    7.    
    8.     If Len(strBuff) <> 0 Then
    9.  
    10.         Do
    11.             List1.AddItem strBuff
    12.             strBuff = Dir$
    13.         Loop Until Len(strBuff) = 0
    14.  
    15.     End If
    16.  
    17. End Sub
    18.  
    19. Private Sub List1_Click()
    20.     Shell ("NotePad.exe C:\Temp\" & List1.Text)
    21. End Sub

  8. #8
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: message box

    Wassup Bruce!

    Anyway, you can display the available options in your input box so they can know what they have available.
    VB Code:
    1. Dim TheList$
    2.  
    3.    For i = 0 To File1.ListCount - 1
    4.       TheList = TheList & File1.List(i) & VbCrLf
    5.    Next
    6.      
    7.          FileName = Inputbox("Which File would you like to open?" & Vbcrlf & TheList, "Type File Name.")
    Just a thought.

  9. #9
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: message box

    By message box, I assume you mean the dialog open box.
    Try this:

    VB Code:
    1. CommonDialog1.InitDir = "C:\"
    2. CommonDialog1.Filter = "User Files|*.txt|"
    3. CommonDialog1.ShowOpen
    You'll need to add the component "Microsoft common dialog 6.0"
    It'll open up a dialog box in the C:\ Directory, and only show text files + folders. If you want the filter to be more specific with the user files, you could change the extension of the userfiles to .User, or something similiar, and then edit
    CommonDialog1.Filter = "User Files|*.txt|" to be
    CommonDialog1.Filter = "User Files|*.User|"

    Hope this can help

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    thank you d3gerald and bruce fox both your ideas did work, the only problem i had with the file list box was that I couldn't figure out how to set it to a specific location. It would only go to vbs default location.

    Rob, sry but I do mean an actual message box, not the common dialog

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    bruce fox, is there a way to in asternative to opening the files, delete them?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    i have another question, why won't it save anymore. I have the file save when exiting vb (you can edit it when the program is running in the vbwindow) and I exit on form1 even though I open on form2...

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

    Re: message box

    Quote Originally Posted by lilwupster
    bruce fox, is there a way to in asternative to opening the files, delete them?
    Do you want to delete them or just empty them out?
    Quote Originally Posted by lilwupster
    i have another question, why won't it save anymore. I have the file save when exiting vb (you can edit it when the program is running in the vbwindow) and I exit on form1 even though I open on form2...
    Is the file save code in the unload event of your startup form?

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    I want to be able to delete a file I select from the listbox

    and no, the save code is in the unload event for my second form that is activated through the startup

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    I can work around the not saving part but I still need a way to delete

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

    Re: message box

    Quote Originally Posted by lilwupster
    I want to be able to delete a file I select from the listbox
    Will you be selecting one file at a time or multiple files?

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    one at a time

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

    Re: message box

    Quote Originally Posted by lilwupster
    one at a time
    Assuming the listbox entry contains both the full path and filename, try
    VB Code:
    1. Private Sub Command1_Click()
    2. Kill List1.List(List1.ListIndex)
    3. End Sub
    You should probably add some code to ensure something in the listbox is selected before issuing the Kill statement.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    It keeps saying file not found

    Dim FileDelete As Integer
    FileDelete = MsgBox("delete?", vbOKCancel)
    If FileDelete = 1 Then
    Kill List3.List(List3.ListIndex)
    MsgBox "Deleted"
    End If

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    o, i see i needed

    Kill "C:\" & List3.List(List3.ListIndex)

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

    Re: message box

    Quote Originally Posted by lilwupster
    o, i see i needed

    Kill "C:\" & List3.List(List3.ListIndex)
    Are you storing the file names without the path?

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    no, i do have the path

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

    Re: message box

    Quote Originally Posted by lilwupster
    no, i do have the path
    Then you shouldn't need to append the drive letter.

    Post a sample example of what might be in your listbox.

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    I have it save to
    "C:\" & User 'user being a string
    Then when I load the form I use what Bruce Fox had



    Dim strBuff As String

    strBuff = Dir$("C:\*.me")

    If Len(strBuff) <> 0 Then

    Do
    List3.AddItem strBuff
    strBuff = Dir$
    Loop Until Len(strBuff) = 0

    End If


    So then I can select 1 of the files listed and use



    Dim FileDelete As Integer
    FileDelete = MsgBox("Are you sure you want to delete" & List3.Text & "?", vbOKCancel)
    If FileDelete = 1 Then
    Kill "C:\" & List3.List(List3.ListIndex)
    List3.RemoveItem (List3.ListIndex)
    MsgBox " Deleted"
    End If

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

    Re: message box

    But, if you save it as c:\hack.txt then that will be in your listbox and you won't need to preface list3.list(list3.listindex) with c:\

    Does the item in your listbox appear as: c:\hack.txt?

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    no, just hack.txt

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

    Re: message box

    Quote Originally Posted by lilwupster
    no, just hack.txt
    Ah...are all of these files in the root folder of C:? Is this working then?[quote=lilwupster]Kill "C:\" & List3.List(List3.ListIndex)[/Highlight]

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    yes,

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

    Re: message box

    So, is this issue resolved, or do you still have questions on something?

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    129

    Re: message box

    it is resolved

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

    Re: message box

    Thanks. The easiest way to mark a thread resolved is to pull down the Thread Tools menu and click the Mark Thread Resolved button.

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