Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


s.joseph

586 posts

Ultimate Geek

Trusted

#41579 18-Sep-2009 21:23
Send private message

Help im real stuck! Im writing an assignment with 3 forms and want to access int rawScore and decimal averageScore from a seperate Form.

What do i type in the other form to call them?
Thanks.



 


public partial class NightClubForm : Form


{

int rawScore;
decimal averageScore; 

public NightClubForm()

{

InitializeComponent();



Create new topic
Ragnor
8188 posts

Uber Geek

Trusted

  #256927 18-Sep-2009 21:45
Send private message

Ideally you want to use some kind of  software design pattern like MVC or MVP but presuming you don't have much time and they haven't taught you any good practice like that....  check out this the codeproject article below for an example of using events and delegates to solve this kind problem.

http://www.codeproject.com/KB/cs/model_view_controller.aspx

Note the author calls his article an example of the MVC pattern but it's actually an example of a simpler design pattern called the Observer pattern.

s.joseph

586 posts

Ultimate Geek

Trusted

  #257040 19-Sep-2009 15:36
Send private message

im a novice at this, all i want to do is to use int rawScore which is given a value in form1 and then use it in form 2

dpw

dpw
843 posts

Ultimate Geek

ID Verified
Trusted

  #257071 19-Sep-2009 18:17
Send private message

s.joseph: im a novice at this, all i want to do is to use int rawScore which is given a value in form1 and then use it in form 2


Aye, I can well believe you're an absolute novice if you're asking this sort of question Laughing. While Visual Studio is a great tool which allows for rapid prototyping it is also a major pitfall - a lot of students these days are thought quick'n'dirty drag'n'drop "programming" and earn their "Object Oriented Programming" certificates that way. Your question absolutely begs even more questions, i.e. have you heard of the basic tennets of OO, and things you are able to do, such as encapsulation, etc?

The quickest and dirtiest way to answer your question is to declare those members public by simply adding that keyword in front of the property type, eg. "public int someIntOrOther;". You can then access this property from any instance of that form. This is assuming you know about the definition of an "object" being an "instance" of a "class"? Sorry, I have no idea how much of a novice you are. My suggestion is don't go straight to Windows Forms programming - play around with console apps and improve your OO skills first. Build a solid foundation and Windows Forms stuff will come easily - your questions such at this will be answered during your play with simple console apps.

This is just my view of course - this was how I learned, way back in the old C++ and Java days, getting my head around things after Pascal. You may have different learning preferences. Learn basic OO first, then figure out best practices, followed by patterns - or all together in the same time. If you're asking this sort of questions then reading about MVC, and trying to implement it, may not be the most fruitful learning exercise. Having said that, I have not read the article Ragnor mentioned - it may well be a well formed article guiding you from the basics of OO to patterns and best practices, in which case HOOORAH!




Android user, software developer, a semi-typical (not a gamer) geek, and a Bernese Mountain Dog nut!

http://savitarbernese.com | https://nz.linkedin.com/in/danywu




timestyles
424 posts

Ultimate Geek


  #257076 19-Sep-2009 19:06
Send private message

You can always ask on http://stackoverflow.com/

KKing
11 posts

Geek


  #257081 19-Sep-2009 19:36
Send private message

s.joseph: Help im real stuck! Im writing an assignment with 3 forms and want to access int rawScore and decimal averageScore from a seperate Form.


Hey, this assignment looks familiar to me!

If you are doing INFO 102 at VUW, then you do not need 3 forms. Use a message box to display rawScore and averageScore. Read the assignment carefully, look at the hints and ask question on the discussion board.

s.joseph

586 posts

Ultimate Geek

Trusted

  #257183 20-Sep-2009 12:43
Send private message

haha, oh. that makes sense.
Thanks man

BenRees
27 posts

Geek


  #258768 27-Sep-2009 20:17
Send private message

Hi there,

I always prefer simplicity, if at all possible no sense in over engineering if not necessary.
I would do something like this:

public partial class NightClubForm : Form {
int rawScore;
decimal averageScore;

public NightClubForm() {
InitializeComponent();
}

public int RawScore { get { return rawScore; } }
public decimal AverageScore { get { return averageScore; } }

// Your other form code
}

These can now be accessed by other areas of your code as follows:

var theAverageScore = form1.AverageScore;
var theRawScore = form1.RawScore;

Hope that helps mate
Cheers
Ben

Create new topic





News and reviews »

Synology DS925+ Review
Posted 23-Apr-2025 15:00


Synology Announces DiskStation DS925+ and DX525 Expansion Unit
Posted 23-Apr-2025 10:34


JBL Tour Pro 3 Review
Posted 22-Apr-2025 16:56


Samsung 9100 Pro NVMe SSD Review
Posted 11-Apr-2025 13:11


Motorola Announces New Mid-tier Phones moto g05 and g15
Posted 4-Apr-2025 00:00


SoftMaker Releases Free PDF editor FreePDF 2025
Posted 3-Apr-2025 15:26


Moto G85 5G Review
Posted 30-Mar-2025 11:53


Ring Launches New AI-Powered Smart Video Search
Posted 27-Mar-2025 16:30


OPPO RENO13 Series Launches in New Zealand
Posted 27-Mar-2025 05:00


Sony Electronics Announces the WF-C710N Truly Wireless Noise Cancelling Earbuds
Posted 26-Mar-2025 20:37


New Harman Kardon Portable Home Speakers Bring Performance and Looks Together
Posted 26-Mar-2025 20:30


Data Insight Launches The Data Academy
Posted 26-Mar-2025 20:21


Oclean AirPump A10 Portable Water Flosser Wins iF Design Award 2025
Posted 20-Mar-2025 12:05


OPPO Find X8 Pro Review
Posted 14-Mar-2025 14:59


Samsung Galaxy Ring Now Available in New Zealand
Posted 14-Mar-2025 13:52









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.







GoodSync is the easiest file sync and backup for Windows and Mac