| View previous topic :: View next topic |
| Author |
Message |
Luigi Grandmaster Cheater Supreme
Reputation: 1
Joined: 24 Mar 2008 Posts: 1082
|
Posted: Wed May 27, 2009 5:02 pm Post subject: [VB.NET] Performing an action after a file is found |
|
|
| Using an explorer form, I would want the user to locate an item, like blah.txt for example. After they locate it, I want it to perform an action that I specify. How would I perform this action?
|
|
| Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Wed May 27, 2009 5:41 pm Post subject: |
|
|
Add an open file dialogue (I'll call this OpenFileDialog1).
Add a button (I'll call this Button1).
Button1 Click: | Code: | | OpenFileDialog1.ShowDialog() |
OpenFileDialog1 FileOk: | Code: | Dim file As String = OpenFileDialog1.FileName
If Not System.IO.File.Exists(file) Then
MsgBox("404")
Else
'Continue here
End If |
|
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Wed May 27, 2009 11:08 pm Post subject: |
|
|
Don't create another event handler.
In the event handler that you want to open the dialog put:
| Code: | Dim openFileDialog1 As System.Windows.Forms.OpenFileDialog
openFileDialog1 = New System.Windows.Forms.OpenFileDialog()
If openFileDialog1.ShowDialog() = DialogResult.OK Then
'Code here
End If |
_________________
Last edited by yoyonerd on Thu May 28, 2009 10:38 am; edited 1 time in total |
|
| Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu May 28, 2009 6:48 am Post subject: |
|
|
| Doesn't doing that mean the programme will hang whilst the dialogue is open?
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu May 28, 2009 7:11 am Post subject: |
|
|
| shhac wrote: | | Doesn't doing that mean the programme will hang whilst the dialogue is open? |
No, it works. The declaration seems odd tho. Maby it is something vbish.
I would have solved it quite similar :
| Code: | 1: Dim ofd As New OpenFileDialog()
2: ofd.Filter = "|*.*"
3: If ofd.ShowDialog() = DialogResult.OK Then
4: MessageBox.Show("You have selected the follow file " + ofd.FileName)
5: End If
6:
7:
8: '=======================================================
9: 'Service provided by Telerik (www.telerik.com)
10: 'Conversion powered by NRefactory.
11: 'Built and maintained by Todd Anglin and Telerik
12: '======================================================= |
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
yoyonerd Grandmaster Cheater
Reputation: 0
Joined: 26 Apr 2008 Posts: 699 Location: -->formerly yoyonerd<--
|
Posted: Thu May 28, 2009 10:39 am Post subject: |
|
|
Lol, oops, I left traces of the filter in my code.
I never use VB >.> I had to try translating it from C#
_________________
|
|
| Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu May 28, 2009 11:43 am Post subject: |
|
|
I basically never do
New OpenFileDialog()
I just use VS and add one to my project. (only need one, can just change the filters etc if necessary)
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu May 28, 2009 3:44 pm Post subject: answered? |
|
|
did all this answer your question, Weibchen?
a little bit more advanced solution would be to work with tree- and listviews. But thats out of range in this case i gues. Just wanted to bring it up tho so that you know.
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
hehewaffles How do I cheat?
Reputation: 0
Joined: 23 Apr 2009 Posts: 5
|
Posted: Thu May 28, 2009 5:48 pm Post subject: |
|
|
| shhac wrote: | I basically never do
New OpenFileDialog()
I just use VS and add one to my project. (only need one, can just change the filters etc if necessary) |
But if you're like me, then you don't like cluttering up your designer window with that annoying bar at the bottom--especially when it's a large form. Why waste the space when you can just type it?
|
|
| Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu May 28, 2009 8:15 pm Post subject: |
|
|
| hehewaffles wrote: | | shhac wrote: | I basically never do
New OpenFileDialog()
I just use VS and add one to my project. (only need one, can just change the filters etc if necessary) |
But if you're like me, then you don't like cluttering up your designer window with that annoying bar at the bottom--especially when it's a large form. Why waste the space when you can just type it? | About most things I would agree about not liking clutter; but in this case I'm pretty sure its better memory usage to not keep creating/destroying these dialogues.
When was the last time you needed a screen-sized form?
|
|
| Back to top |
|
 |
hehewaffles How do I cheat?
Reputation: 0
Joined: 23 Apr 2009 Posts: 5
|
Posted: Thu May 28, 2009 8:34 pm Post subject: |
|
|
| shhac wrote: | | hehewaffles wrote: | | shhac wrote: | I basically never do
New OpenFileDialog()
I just use VS and add one to my project. (only need one, can just change the filters etc if necessary) |
But if you're like me, then you don't like cluttering up your designer window with that annoying bar at the bottom--especially when it's a large form. Why waste the space when you can just type it? | About most things I would agree about not liking clutter; but in this case I'm pretty sure its better memory usage to not keep creating/destroying these dialogues.
When was the last time you needed a screen-sized form? |
Right now, and my previous project, haha.
I doubt it really matters, though if it bugs you, I'd just keep a static variable, rather than having your form instantiate it for you, which is basically what it's doing behind the scenes.
|
|
| Back to top |
|
 |
|