|
-
Mar 1st, 2006, 08:56 PM
#1
Thread Starter
Addicted Member
[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.
-
Mar 1st, 2006, 09:06 PM
#2
Frenzied Member
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
-
Mar 1st, 2006, 09:09 PM
#3
Thread Starter
Addicted Member
Re: message box
I know that, but can I get that in a message box?
-
Mar 1st, 2006, 09:13 PM
#4
Frenzied Member
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
-
Mar 1st, 2006, 09:36 PM
#5
Thread Starter
Addicted Member
-
Mar 1st, 2006, 09:42 PM
#6
Frenzied Member
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
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
-
Mar 1st, 2006, 09:50 PM
#7
Re: message box
Something like:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim strBuff As String
strBuff = Dir$("C:\Temp\*.txt")
If Len(strBuff) <> 0 Then
Do
List1.AddItem strBuff
strBuff = Dir$
Loop Until Len(strBuff) = 0
End If
End Sub
Private Sub List1_Click()
Shell ("NotePad.exe C:\Temp\" & List1.Text)
End Sub
-
Mar 2nd, 2006, 04:10 AM
#8
Frenzied Member
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:
Dim TheList$
For i = 0 To File1.ListCount - 1
TheList = TheList & File1.List(i) & VbCrLf
Next
FileName = Inputbox("Which File would you like to open?" & Vbcrlf & TheList, "Type File Name.")
Just a thought.
-
Mar 2nd, 2006, 05:42 AM
#9
Hyperactive Member
Re: message box
By message box, I assume you mean the dialog open box.
Try this:
VB Code:
CommonDialog1.InitDir = "C:\"
CommonDialog1.Filter = "User Files|*.txt|"
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
-
Mar 2nd, 2006, 09:20 AM
#10
Thread Starter
Addicted Member
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
-
Mar 2nd, 2006, 09:24 AM
#11
Thread Starter
Addicted Member
Re: message box
bruce fox, is there a way to in asternative to opening the files, delete them?
-
Mar 2nd, 2006, 09:40 AM
#12
Thread Starter
Addicted Member
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...
-
Mar 2nd, 2006, 09:45 AM
#13
Re: message box
 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?
 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?
-
Mar 2nd, 2006, 09:48 AM
#14
Thread Starter
Addicted Member
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
-
Mar 2nd, 2006, 10:19 AM
#15
Thread Starter
Addicted Member
Re: message box
I can work around the not saving part but I still need a way to delete
-
Mar 2nd, 2006, 10:23 AM
#16
Re: message box
 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?
-
Mar 2nd, 2006, 10:24 AM
#17
Thread Starter
Addicted Member
-
Mar 2nd, 2006, 10:29 AM
#18
Re: message box
 Originally Posted by lilwupster
one at a time
Assuming the listbox entry contains both the full path and filename, try
VB Code:
Private Sub Command1_Click()
Kill List1.List(List1.ListIndex)
End Sub
You should probably add some code to ensure something in the listbox is selected before issuing the Kill statement.
-
Mar 2nd, 2006, 10:41 AM
#19
Thread Starter
Addicted Member
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
-
Mar 2nd, 2006, 10:43 AM
#20
Thread Starter
Addicted Member
Re: message box
o, i see i needed
Kill "C:\" & List3.List(List3.ListIndex)
-
Mar 2nd, 2006, 10:44 AM
#21
Re: message box
 Originally Posted by lilwupster
o, i see i needed
Kill "C:\" & List3.List(List3.ListIndex)
Are you storing the file names without the path?
-
Mar 2nd, 2006, 10:45 AM
#22
Thread Starter
Addicted Member
-
Mar 2nd, 2006, 10:47 AM
#23
Re: message box
 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.
-
Mar 2nd, 2006, 10:50 AM
#24
Thread Starter
Addicted Member
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
-
Mar 2nd, 2006, 11:10 AM
#25
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?
-
Mar 2nd, 2006, 11:17 AM
#26
Thread Starter
Addicted Member
-
Mar 2nd, 2006, 11:41 AM
#27
Re: message box
 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]
-
Mar 2nd, 2006, 11:48 AM
#28
Thread Starter
Addicted Member
-
Mar 2nd, 2006, 11:49 AM
#29
Re: message box
So, is this issue resolved, or do you still have questions on something?
-
Mar 2nd, 2006, 11:54 AM
#30
Thread Starter
Addicted Member
-
Mar 2nd, 2006, 12:15 PM
#31
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|