vb.net - Is there a way to get the input from a Load event handler (entered via inputBox) to be used Globally in the program? -
i creating form prompt user enter file name upon loading file. issue encounter variable use store input not recognized in 1 of procedures. code here shows current set up.
imports system.io public class frmemployee sub frmemployee_load(byval sender object, e system.eventargs) dim strfilename = inputbox("please name file save data to: ") end sub private sub btnclear_click(sender object, e eventargs) handles btnclear.click txtemail.clear() txtextension.clear() txtfirst.clear() txtlast.clear() txtmiddle.clear() txtnumber.clear() txtphone.clear() end sub private sub btnsave_click(sender object, e eventargs) handles btnsave.click dim inputfile new streamwriter(strfilename) if file.exists(strfilename) = true inputfile = file.createtext(strfilename) inputfile.write(txtemail.text) inputfile.write(txtextension.text) inputfile.write(txtfirst.text) inputfile.write(txtlast.text) inputfile.write(txtmiddle.text) inputfile.write(txtnumber.text) inputfile.write(txtphone.text) inputfile.write(cmbdepart.text) else messagebox.show("" & strfilename & "cannot created or found.") end if end sub private sub btnexit_click(sender object, e eventargs) handles btnexit.click me.close() end sub
end class
the load event handler want user input name of file.
you use my.settings
, load file string there , save it. forms can access that. when close the app set string.empty
if want be.
you taking advantage of class object fields capturing using either binaryformatter
or xmlserializer
store data. better databinding, creation , reconstruction using object.
my.settings.filename = inputbox("filename?") my.settings.save()
Comments
Post a Comment