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

575 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
8085 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.

 
 
 
 

Get easy to use, easy to install Norton antivirus protection against advanced online threats (affiliate link).
s.joseph

575 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

575 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 »

New Air Traffic Management Platform and Resilient Buildings a Milestone for Airways
Posted 6-Dec-2023 05:00


Logitech G Launches New Flagship Console Wireless Gaming Headset Astro A50 X
Posted 5-Dec-2023 21:00


NordVPN Helps Users Protect Themselves From Vulnerable Apps
Posted 5-Dec-2023 14:27


First-of-its-Kind Flight Trials Integrate Uncrewed Aircraft Into Controlled Airspace
Posted 5-Dec-2023 13:59


Prodigi Technology Services Announces Strategic Acquisition of Conex
Posted 4-Dec-2023 09:33


Samsung Announces Galaxy AI
Posted 28-Nov-2023 14:48


Epson Launches EH-LS650 Ultra Short Throw Smart Streaming Laser Projector
Posted 28-Nov-2023 14:38


Fitbit Charge 6 Review
Posted 27-Nov-2023 16:21


Cisco Launches New Research Highlighting Gap in Preparedness for AI
Posted 23-Nov-2023 15:50


Seagate Takes Block Storage System to New Heights Reaching 2.5 PB
Posted 23-Nov-2023 15:45


Seagate Nytro 4350 NVMe SSD Delivers Consistent Application Performance and High QoS to Data Centers
Posted 23-Nov-2023 15:38


Amazon Fire TV Stick 4k Max (2nd Generation) Review
Posted 14-Nov-2023 16:17


Over half of New Zealand adults surveyed concerned about AI shopping scams
Posted 3-Nov-2023 10:42


Super Mario Bros. Wonder Launches on Nintendo Switch
Posted 24-Oct-2023 10:56


Google Releases Nest WiFi Pro in New Zealand
Posted 24-Oct-2023 10:18









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.







Lenovo