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.




560 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
8033 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.



560 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

832 posts

Ultimate Geek

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

424 posts

Ultimate Geek


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

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

12 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.



560 posts

Ultimate Geek

Trusted

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

haha, oh. that makes sense.
Thanks man

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



Twitter and LinkedIn »



Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Industry plan could create a billion dollar interactive games sector
Posted 19-Aug-2019 20:41


Personal cyber insurance a New Zealand first
Posted 19-Aug-2019 20:26


University of Waikato launches space for esports
Posted 19-Aug-2019 20:20


D-Link ANZ expands mydlink ecosystem with new mydlink Mini Wi-Fi Smart Plug
Posted 19-Aug-2019 20:14


Kiwi workers still falling victim to old cyber tricks
Posted 12-Aug-2019 20:47


Lightning Lab GovTech launches 2019 programme
Posted 12-Aug-2019 20:41


Epson launches portable laser projector
Posted 12-Aug-2019 20:27


Huawei launches new distributed HarmonyOS
Posted 12-Aug-2019 20:20


Lenovo introduces single-socket servers for edge and data-intensive workloads
Posted 9-Aug-2019 21:26


The Document Foundation announces LibreOffice 6.3
Posted 9-Aug-2019 16:57


Symantec sell enterprise security assets for US$ 10.7 billion to Broadcom
Posted 9-Aug-2019 16:43


Artificial tongue can distinguish whisky and identify counterfeits
Posted 8-Aug-2019 20:20


Toyota and Preferred Networks to develop service robots
Posted 8-Aug-2019 20:11


Vodafone introduces new Vodafone TV device
Posted 7-Aug-2019 17:16


Intel announces next-generation Intel Xeon Scalable processors with up to 56 cores
Posted 7-Aug-2019 15:41



Geekzone Live »

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


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



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.

Alternatively, you can receive a daily email with Geekzone updates.