|
-
May 9th, 2013, 10:20 AM
#1
Thread Starter
Hyperactive Member
NooB Question
Hello all,
I'm teaching myself VB .NET and I am having a bit of an issue.
I have a Form with two buttons...
Button 1 is where I capture the path and file name using OpenFileDialog.
Button 2 is where I want to process the file I captured from button 1.
I do not seem to be able to pass the file name from button 1 to button 2.
is there an Easy way to do this?
Thanks in advance,
-NJ
-
May 9th, 2013, 10:30 AM
#2
Re: NooB Question
Well there is but why would you need to? Button1 opens the filedialog, you get the filename, so why not just process it as a continuation of that sub? Button 2 appears to have no raison d'etre (oooh, hark at me coming over all posh!)
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 9th, 2013, 10:32 AM
#3
Addicted Member
Re: NooB Question
You can assign the file path you got from the OFD to a string variable and then use that variable with button2.
edit: VS is taking foreverr to load, so this is freehand:
vb.net Code:
Public Class Form1 Dim filepath As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() filepath = OpenFileDialog1.FileName End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click MessageBox.Show(filepath) End Sub End Class
Last edited by MetalInquisitor; May 9th, 2013 at 10:37 AM.
-
May 9th, 2013, 10:42 AM
#4
Re: NooB Question
Yes, as long as the variable is NOT declared within one of the button click event handlers, then it is visible to the other click handler. The problem you may have been having is that you were holding the filename in a local variable within the click event handler, so the other click handler couldn't see it. This is called variable scoping, and is kind of important....but it's also a guess as to what you were doing on my part.
My usual boring signature: Nothing
 
-
May 9th, 2013, 12:14 PM
#5
Thread Starter
Hyperactive Member
Re: NooB Question
 Originally Posted by MetalInquisitor
You can assign the file path you got from the OFD to a string variable and then use that variable with button2.
edit: VS is taking foreverr to load, so this is freehand:
vb.net Code:
Public Class Form1
Dim filepath As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
filepath = OpenFileDialog1.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show(filepath)
End Sub
End Class
That did it! Thank you
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
|