accessing control's value from a seperate class.
-
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
-
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
One whay is to make those values static. and then it will be shared among all instance of a form
-
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
-
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
It depends on the relationship between the class and the form with those controls. If the form instanciates the class then you can set properties in the class when the controls change. If the class instanciates the form then the class can read any custom public properties you create on the form, or better still, the form can raise custom events which the class can subscribe to. If they are only related by a common ancestor, the form can raise events that bubble up to the common ancestor, and that can in turn set a chain of property changes or method calls back down the line to the class.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value
private void EnableDisableSaveChanges(String txtboxName, String txtValue) { if (ckbxUniqueName.Checked == true) { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } } else { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } }
This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...
#region Validate if a change has occured to any of the fields on tab 1. //////////////////////////////////// private Boolean HastxtAppNameControlValueChanged() { if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "") { return false; } else { return true; } } private Boolean HastxtVerNumberControlValueChanged() { if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "") { return false; } else
-
Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value
private void EnableDisableSaveChanges(String txtboxName, String txtValue) { if (ckbxUniqueName.Checked == true) { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } } else { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } }
This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...
#region Validate if a change has occured to any of the fields on tab 1. //////////////////////////////////// private Boolean HastxtAppNameControlValueChanged() { if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "") { return false; } else { return true; } } private Boolean HastxtVerNumberControlValueChanged() { if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "") { return false; } else
If i change the methods to static functions I can no longer access the form controls. Please help. I believe at least a static function is what I want but I need to be able to access the forms controls values...)
-
If i change the methods to static functions I can no longer access the form controls. Please help. I believe at least a static function is what I want but I need to be able to access the forms controls values...)
You almost never want a static function when dealing with an instance, for obvious reasons. Strip out all that code and checking a million different properties/fields/controls/whatever - the same principle applies even if there is just one that needs to be checked. It will then be clearer to both us and you! Unless I missed it somewhere way off screen to the right with all the scrolling, I don't see the relationship between the classes - what instanciates what here?
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
You almost never want a static function when dealing with an instance, for obvious reasons. Strip out all that code and checking a million different properties/fields/controls/whatever - the same principle applies even if there is just one that needs to be checked. It will then be clearer to both us and you! Unless I missed it somewhere way off screen to the right with all the scrolling, I don't see the relationship between the classes - what instanciates what here?
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)Here is what I am trying to do... I want to be able to receive a response of true or false when these values change. The Unchanged... is the variable with the current value. without doing if (txtAppName.Text == UnchangedAppNameField) {something...} I want to have something that says if (btxtAppName) {somehting...} or say (This is the way I would like to do it.) if (SomeClass.AreThereAnyChanges) {something} My main problem is I do not know how to access the forms controls from the class.
-
Here is what I am trying to do... This is the code I want to call by 1 procedure retruning a bool value
private void EnableDisableSaveChanges(String txtboxName, String txtValue) { if (ckbxUniqueName.Checked == true) { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged & HasrbtnClientMachineControlValueChanged & HasrbtnClientUserControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } } else { if (HastxtAppNameControlValueChanged & HastxtVerNumberControlValueChanged & HastxtServerLocControlValueChanged & HastxtServerFileNameControlValueChanged & HastxtClientLocFileNameControlValueChanged & HastxtClientFileNameControlValueChanged & HasckbxMasterApplicationControlValueChanged & HasckbxCreateShortcutControlValueChanged & HasckbxUniqueNameControlValueChanged) { btnSaveChanges.Enabled = true; } else { btnSaveChanges.Enabled = false; } }
This is the code I want in a seperate class with a main procedure I can call to return a bool value which is above...
#region Validate if a change has occured to any of the fields on tab 1. //////////////////////////////////// private Boolean HastxtAppNameControlValueChanged() { if (txtAppName.Text == UnchangedAppNameField || txtAppName.Text == null || txtAppName.Text == "") { return false; } else { return true; } } private Boolean HastxtVerNumberControlValueChanged() { if (txtVerNumber.Text == UnchangedAppVersionField || txtVerNumber.Text == null || txtVerNumber.Text == "") { return false; } else
It is too late here for me to make any sense of your problem (my fault, not yours), but your code wouldbe a little shorter and therefore possibly easier to understand if you replace this (and all the ones like it):
private Boolean HasckbxMasterApplicationControlValueChanged() { if (ckbxMasterApplication.Checked == UnchangedMasterAppField) { return false; } else { return true; } }
with:
private Boolean HasckbxMasterApplicationControlValueChanged() { return !(ckbxMasterApplication.Checked == UnchangedMasterAppField); }
or, of course:
private Boolean HasckbxMasterApplicationControlValueChanged() { return (ckbxMasterApplication.Checked != UnchangedMasterAppField); }
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
ok I am a little confused. I have a control textbox and checkbox that I need to read from in a separate class. How do you do this. I just need to read the checked and text values into the class that is not the form.
I agree with Dave and Henry: - static won't help - more compact code could make it manageable. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.