Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Grabbing Data From Classes (http://www.go4expert.com/forums/grabbing-data-classes-t3932/)

x64 19Apr2007 06:15

Grabbing Data From Classes
 
/Puts noob hat on.

Alright, this is probably the biggest n00b question you will get from me. How can I grab and receive values from different classes? Honestly, I've never had to deal with classes until now. Here is my situation:

I have created and completed a Notepad clone, but with many more features. I'm just cleaning code and adding even more now that it doesn't need to be shown to a college. Anyways, I want to allow the user to define their default font, richtextbox background color, word wrap enabled/disabled, number of tabs, etc... So, I created "public partial class Options : Form" (Nice copy and paste feature.). Ok so in this partial class, whatever the heck that is, I have functions for each object in this form. For example, I have a maskedtextbox where the user will type in the number of maximum tabs that can be opened at once, I can put this into an int but then when I go back to my main application partial class I have no idea how to retrieve that int and use it to affect the maximum number of tabs that can be opened.

I would have searched Goggle and this form for the answer but I don't know what it's called.

Thanks

shabbir 19Apr2007 06:53

Re: Grabbing Data From Classes
 
First of all your options calls does not need to be deriving from the Form class because Options is not having a relationship with the Form.

Now getting to your Questions here is the best way to be doing that in your scenario.

1. You can have a property to whatever stored in the variable is exposed as public method.
2. Now have an Object of your Options class in the Form class where you want to create the tabs.
3. Access the property by the object.

Now your solution can be made more generic like
  • You can have some static property to get the data from the class.
  • You can have the singleton class of Options so you dont create nultiple objects of it every where.

x64 21Apr2007 07:26

Re: Grabbing Data From Classes
 
Sorry for a late response, I've been busy.

Alright. I think I am kind of confused and because of that I think I explained it wrong. Let me give it another shot, ok? If I remove the "Form" part of the class it doesn't work, as you see in the screen shot below it is a form called Options with options that the user will be able to define as defaults. Take the first text box for example, lets say the user types in 15 for the maximum number of tabs and I place that into an int i when the OK button is pushed. Now, how would I get that value int i into another Class : Form and apply that to make it limit the tabs to 15 for the tab control?

Sorry if this is confusing to you, I don't know how to explain it :confused:.

Thanks

P.S: Error while trying to attach the .jpeg image to the post on this board. I didn't post the image threw another site, I don't know if that counts as linking to another site.
Code:

Warning: move_uploaded_file(attachments/0fa2824bc662c6072d9e638e7e0f983f): failed to open stream: Permission denied in /includes/functions_file.php on line 274
 
Warning: move_uploaded_file(): Unable to move '/tmp/phprrPdDs' to 'attachments/0fa2824bc662c6072d9e638e7e0f983f' in /includes/functions_file.php on line 274
 
Warning: filesize(): Stat failed for attachments/0fa2824bc662c6072d9e638e7e0f983f (errno=2 - No such file or directory) in /includes/functions_file.php on line 286


shabbir 21Apr2007 09:26

Re: Grabbing Data From Classes
 
We have taken a note of the error and will post here when we fix the issue. The issue is with the file permission on the new server we have moved on.

Apart from that I think once you attach the query will become clear.

shabbir 21Apr2007 09:46

Re: Grabbing Data From Classes
 
The problem is solved and thanks for pointing that out. Now you can try explain with the screenshot.

x64 21Apr2007 09:50

Re: Grabbing Data From Classes
 
1 Attachment(s)
Quote:

Originally Posted by x64
Sorry for a late response, I've been busy.

Alright. I think I am kind of confused and because of that I think I explained it wrong. Let me give it another shot, ok? If I remove the "Form" part of the class it doesn't work, as you see in the screen shot below it is a form called Options with options that the user will be able to define as defaults. Take the first text box for example, lets say the user types in 15 for the maximum number of tabs and I place that into an int i when the OK button is pushed. Now, how would I get that value int i into another Class : Form and apply that to make it limit the tabs to 15 for the tab control?

Sorry if this is confusing to you, I don't know how to explain it :confused:.

Thanks

Alright, the screen shot should be attached.

shabbir 21Apr2007 10:30

Re: Grabbing Data From Classes
 
Still my answer remains the same but I will try to explain with respects.

15 is stored in the class variable int and not to a locale variable of the function in that class and now you can have my first option like

1. You can have a property to whatever stored in the variable is exposed as public method.
2. Now have an Object of your Options class in the Form class where you want to create the tabs.
3. Access the property by the object.

Now I will tell you the sample run.

Say we have some static members in the class called Options.
Code:

class Options
{
  static int i;
  // Add a property for i
}

Now have this class access and set when OK is pressed and get this i when you need it. You can now have as many options you like to be available to all the classes globally as the properties are static

x64 22Apr2007 07:21

Re: Grabbing Data From Classes
 
I'm very sorry. I understand what you are saying, I really do! But do you happen to have a tutorial on how to do this that you can recommend? When I try to code what you say to do I find myself not able to do it. I have never attempted/seen code to do this it's kind of like walking around a forest blind folded.

Sorry for the trouble, and thanks for all the help.

shabbir 22Apr2007 07:52

Re: Grabbing Data From Classes
 
Then you need to go the book way because what I am saying is basics of C#. Any reasonable book will do the trick for you.


All times are GMT +5.5. The time now is 05:53.