![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 169
Rep Power: 1
![]() |
Data between Forms
Hi guys.
One of the biggest hick - ups for me was trying to access data between forms using getters and setters![]() I also had a bit of trouble with MessageBoxes and certain file streaming IO functions.I wrote a little application last night so that if I forget about one of these little issues, I can just go back and look again. It may also prove handy for some newcomers out there who would like to know more about these things, maybe it won't. The coding is definetely not top-notch, and the design sux, but here it is. Description: Application gets user information for a membership of some sort. It then istantiates that info to another form, where the user can save the data. (file will be written to default Debug folder.) The file can then be opened or deleted or edited and saved again. Probably not be a very practical example of where to use this type of stuff, but all comments will be appreciated. (That includes negative feedback, as that creates room for improvement) >BstrucT
__________________
The more the human race tries to change everything, when not needed, the less will they be able to change themselves when they need to. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: Data between Forms
2 issues :
csharp Syntax (Toggle Plain Text)
and the seccond : csharp Syntax (Toggle Plain Text)
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: Data between Forms
Issue #1 is not an issue, it's a preference.
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
Re: Data between Forms
Actually it's more about convention. If most of the people use a certain style - it's best to use that style.
For example - when I look at something like : _someName - I instantly assume it's a private variable. And so will most of .net programmers.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#5 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5
![]() |
Re: Data between Forms
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 169
Rep Power: 1
![]() |
Re: Data between Forms
Thanks for the tip xavier, I had a feeling the "_" wasn't a good idea, but wasn't sure how to write it. Much appreciated.
Oh my, I didn't even know there had to be a finally{} after the exception.So I understand that if the error is catched, the execution will jump to the finally{} statement? I see now that I am disposing of the writer incorrectly.@lectricpharaoh: I have to agree, looks kinda ugly and out of place. hehe, will refrain from doing that again.>BstrucT
__________________
The more the human race tries to change everything, when not needed, the less will they be able to change themselves when they need to. |
|
|
|
|
|
#7 | |
|
Professional Programmer
|
Re: Data between Forms
Quote:
. http://www.csharpfriends.com/Article...?articleID=128 here's an article .. you can go from there with help from google.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
|
#8 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5
![]() |
Re: Data between Forms
Quote:
finally block is usually to do cleanup. For example, say you want to open a file, read something, and then close the file. Loading configuration data at program start is a good example. Now, you wrap the read operation in a try block in case there's an I/O error or something, but whether or not an exception gets thrown, you still want to close the file, so you put that in the finally block.In other words, whenever you have code that grabs/allocates a resource, uses it, and then releases/deallocates that resource, you might want to use a finally statement. It depends on the situation, but this is the most common case.As for your original problem, yeah, just use properties. We don't call them 'getters' and 'setters' in C# most of the time, though (that's a term from languages like C++ and Java that don't support properties, so you need a method to do this if you want to maintain proper OO data hiding). What you can do is have one or more status properties on your secondary form(s) that you can check to determine whether other properties are valid. If you're opening a 'modal' dialog box- this is one that must be closed before you can interact with the main form, and is invoked with the ShowDialog() method- you can use the method's return value to determine status.As an example, take the OpenFileDialog class. You instantiate it, call the ShowDialog() method, and after it returns, you can check the result to determine if the user selected a file, or instead clicked 'cancel' or hit 'esc'. If the user did not cancel the dialog box, then you can check the FileName or FileNames property to determine what file(s) they want to open. Basically, the idea here is to ensure the 'data' property actually contains something valid. If you try to open the file when they didn't select one, you've got a problem, so check the status first. This holds true in dialog boxes you create too.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#9 | |
|
Hobbyist Programmer
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 169
Rep Power: 1
![]() |
Re: Data between Forms
Wow thanks man.
Quote:
![]() Thanks for the good advice. >BstrucT
__________________
The more the human race tries to change everything, when not needed, the less will they be able to change themselves when they need to. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question regarding data input into PHP/Mysql using something other than GET | davil | PHP | 6 | Nov 20th, 2007 8:06 AM |
| convert unarrenged .txt data to arrange .txt data | pastalover | Visual Basic | 2 | Jun 23rd, 2006 4:22 PM |
| Recommended Practice for returning data from function | Arla | C# | 1 | Aug 16th, 2005 12:21 PM |
| help with sockets, having a client recieve data as well as send. | cypherkronis | Python | 7 | Jul 1st, 2005 5:59 PM |
| Passing Data between open forms? | melbolt | Visual Basic .NET | 5 | May 24th, 2005 9:27 PM |