How to let the user select a file and then open let the program look i

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 5630 Views - Last Post: 03 October 2008 - 10:39 AM Rate Topic: -----

#1 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

How to let the user select a file and then open let the program look i

Post icon  Posted 30 September 2008 - 07:28 AM

Hi, i'm new @ vb.net :pirate:
and i can't find how to open a FolderBrowserDialog, :crazy: let the user select a portable device
and then check every time if THAT portable device the user has selected is still in the computer,
if not, then then the program runs another form

Sorry for my bad english i'm dutch

Is This A Good Question/Topic? 0
  • +

Replies To: How to let the user select a file and then open let the program look i

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How to let the user select a file and then open let the program look i

Posted 30 September 2008 - 08:48 AM

Use the ShowDialog function to display the dialog window.
' Display the openFile dialog.
Dim result As DialogResult = openFileDialog1.ShowDialog()


Post the code that you are attempting to use to verify that the drive exists and we will help you get it working.
Was This Post Helpful? 0
  • +
  • -

#3 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 30 September 2008 - 09:18 AM

View Postjayman9, on 30 Sep, 2008 - 08:48 AM, said:

Use the ShowDialog function to display the dialog window.
' Display the openFile dialog.
Dim result As DialogResult = openFileDialog1.ShowDialog()


Post the code that you are attempting to use to verify that the drive exists and we will help you get it working.

Ewm,
how to make a string of result?
i only get a "1"
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How to let the user select a file and then open let the program look i

Posted 30 September 2008 - 09:51 AM

Why do you need to make a string of result?
Was This Post Helpful? 0
  • +
  • -

#5 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 30 September 2008 - 12:19 PM

okok.,
look,
i want to let the program check
if the device is still inserted,
thats all,
but i can't make a script of it
and can't find it anywhere
can you help me?

this what i have now
Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim cola As String




		If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
			cola = FolderBrowserDialog1.SelectedPath

		Else
			'als niet op OK werd  geklikt
			'gebeurt er niets en dit wordt aan gebruiker
			'meegedeeld
			MessageBox.Show("You have to choose somthing, if you don't StickKey can't work!", "Fout", _
				MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			Me.Close()
		End If


	End Sub
	Private Sub 

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		'HERE HAS TO BE THE SCRIPT THAT CHECKS IF THE DEVICE IS STILL INSERTED,
		'or to say it in another way: a script how checks if the file/folder still can be found,

	End Sub
End Class



I'f tried to make let the program write a .bat file (with io.streamwriter)
then run the .bat file
that then the .bat file copy's programs to that folder,
but it all crashed
so can you write a code?
or someone else?
Was This Post Helpful? 0
  • +
  • -

#6 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 30 September 2008 - 11:14 PM

hello??
can anywhone help me???
Was This Post Helpful? 0
  • +
  • -

#7 AdamR  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 144
  • Joined: 23-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 06:46 AM

Japie, please, don't rush :) Patience Is A Virtue

Everyone here is helping in their free time, and sometimes people have more important things to do.

The following will help determine if a file or folder exists, so just have your project check to see whether the device directory is present, e.g f;/ or c:/ ....

Private Function DirExists() As Integer
Dim DirName as String
DirName ="Directory here"
Dim Dir as New DirectoryInfo(DirName)

Return If Not Dir Exists Then
MessageBox.Show("Device Not Present")
Else 
MessageBox.Show("Device Found")
End If
End Function



It will need adapting for your project.

DirName can always be set through an inputbox, if needed. You can also use Dir.LastAccessTime (Other Functions also available, such as .CreationTime) to show information about the directory.

E.G, My laptop pics up USB sticks a F:/, i would simply set DirName = "F:/" to see if there is anything present as F:/

Hope this helps :)

This post has been edited by AdamR: 01 October 2008 - 06:50 AM

Was This Post Helpful? 1
  • +
  • -

#8 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 10:19 AM

View PostAdamR, on 1 Oct, 2008 - 06:46 AM, said:

Japie, please, don't rush :) Patience Is A Virtue

Everyone here is helping in their free time, and sometimes people have more important things to do.

The following will help determine if a file or folder exists, so just have your project check to see whether the device directory is present, e.g f;/ or c:/ ....

Private Function DirExists() As Integer
Dim DirName as String
DirName ="Directory here"
Dim Dir as New DirectoryInfo(DirName)

Return If Not Dir Exists Then
MessageBox.Show("Device Not Present")
Else 
MessageBox.Show("Device Found")
End If
End Function



It will need adapting for your project.

DirName can always be set through an inputbox, if needed. You can also use Dir.LastAccessTime (Other Functions also available, such as .CreationTime) to show information about the directory.

E.G, My laptop pics up USB sticks a F:/, i would simply set DirName = "F:/" to see if there is anything present as F:/

Hope this helps :)

really thank you man,
if you need help
you always can send a pm to me,
i still have got some problems:
Error 2 'End If' must be preceded by a matching 'If'. Form1.vb 34 1 WindowsApplication1
Error 1 'ElseIf' must be preceded by a matching 'If' or 'ElseIf'. Form1.vb 32 1 WindowsApplication1

I've tried several things
(like doing what the errors say, changing ElseIf and all that kind of stuff)
but it did'nt worked
and, now i will have patience :P
Was This Post Helpful? 0
  • +
  • -

#9 AdamR  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 144
  • Joined: 23-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 10:42 AM

Hey, no problem

(It says this post was helpful under the posts, click them when people help you out, its a thanks :D)

Right, can you copy and paste the sub procedures where the errors are onto here and i'll take a look :)
Was This Post Helpful? 0
  • +
  • -

#10 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 11:14 AM

Fat sencteces, gives errors



Dim DirName As String
DirName = FolderBrowserDialog1.SelectedPath
Dim Dir As New IO.DirectoryInfo(DirName)

Return
MessageBox.Show("Device Not Present")
Else
MessageBox.Show("Device Found")
End If
Was This Post Helpful? 0
  • +
  • -

#11 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 11:25 AM

this to
Return If Not Dir Exists Then
Was This Post Helpful? 0
  • +
  • -

#12 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 12:25 PM

Instead of using a timer to check there is a built in class in .NET named IO.FileSystemWatcher that can raise an event when ever a directory is changed or a file inside the directory is changed.

Now I am not sure what happens if you remove a thumb drive, but might be worth playing with this object as it might provide you with some powerful options.
Was This Post Helpful? 0
  • +
  • -

#13 AdamR  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 144
  • Joined: 23-September 08

Re: How to let the user select a file and then open let the program look i

Posted 01 October 2008 - 12:31 PM

	Private Function DirExists() As Integer
		Dim DirName As String
		DirName = "c:\WINDOWS"
		Dim Dir As New DirectoryInfo(DirName)

		If Not DirExists Then
			MessageBox.Show("Device Found")
		Else
			MessageBox.Show("Device Not Found")
		End If
	End Function



Worked for me, although i think it would be a better approach to try out the system io watcher as magicmonkey said :)
Was This Post Helpful? 0
  • +
  • -

#14 japie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 08

Re: How to let the user select a file and then open let the program look i

Posted 02 October 2008 - 07:39 AM

View PostAdamR, on 1 Oct, 2008 - 12:31 PM, said:

	Private Function DirExists() As Integer
		Dim DirName As String
		DirName = "c:\WINDOWS"
		Dim Dir As New DirectoryInfo(DirName)

		If Not DirExists Then
			MessageBox.Show("Device Found")
		Else
			MessageBox.Show("Device Not Found")
		End If
	End Function



Worked for me, although i think it would be a better approach to try out the system io watcher as magicmonkey said :)

Yeah, it think i do the system io watcher
why?
System.StackOverflowException was unhandled
InnerException:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

I don't even know what that means,
so i'm going to try that
thank you guys!
Was This Post Helpful? 0
  • +
  • -

#15 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: How to let the user select a file and then open let the program look i

Posted 02 October 2008 - 09:18 AM

View Postjapie, on 2 Oct, 2008 - 09:39 AM, said:

Yeah, it think i do the system io watcher
why?
System.StackOverflowException was unhandled
InnerException:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

I don't even know what that means,
so i'm going to try that
thank you guys!


That means that your code went into an endless loop. you call one function that calls another function that calls the original function again is a typical example. When you run into this exception look at the Stack Trace window in Visual Studio and you can see how your code went into the endless loop.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2