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

Posted 30 September 2008 - 07:28 AM

Hi, i'm new @ vb.net
and i can't find how to open a FolderBrowserDialog, 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

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

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?

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

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:/

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

Posted 01 October 2008 - 10:19 AM

AdamR, 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

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

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

Posted 02 October 2008 - 07:39 AM

AdamR, 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!

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

Posted 02 October 2008 - 09:18 AM

japie, 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.