Does not contain a definition for 'value'?

Hi

My code below gives me errors saying

'System.Windows.Forms.TextBox' does not contain a definition for 'Value'      

(it highlights some of the .Value parts below)

it only does it for some of them though.
Not

this._oList.Add((int)_cMinLengthNumericUpDown.Value);
or
this._oList.Add((int)_cMaxLengthNumericUpDown.Value);

What says if something can have a value or not?

Thanks
PAul


namespace SchemaSetPlugin.Design
{
    public class StringDataTypeWizardPage : DataTypeWizardPage
    {
        public StringDataTypeWizardPage(NewDataTypeWizard oWizard)
            : base(oWizard)
        {
            InitializeComponent();
            UpdateDependencies();
            NewDataTypeWizard.UpdateCustomPageCanMoveNext();

            this._oList.Add(_cHasMinLengthCheckBox.Checked ? iTrue : iFalse);
            this._oList.Add((int)_cMinLengthNumericUpDown.Value);
            this._oList.Add(_cHasMaxLengthCheckBox.Checked ? iTrue : iFalse);
            this._oList.Add((int)_cMaxLengthNumericUpDown.Value);
            this._oList.Add((int)_cRegularExpressionTextBox.Value);
            this._oList.Add((int)_cAllowedCharactersTextBox.Value);
            this._oList.Add((int)_oFailureMessageTextBox.Value);
        }
paulwhelanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jase-CoderCommented:
The textbox doesnt not have a Value property or method. You must use .Text. If you want to know what members are available you can goto View >> Object Browser and look at the .net classes or use the msdn help.
paulwhelanAuthor Commented:
Ok I can use .text instead of .value.
Is this the same?
Also iTrue and iFalse are both underlined?
Any way to fix this?
Thanks
Paul
Jase-CoderCommented:
they maybe underlined because you might not have assigned a value to them
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Jase-CoderCommented:
I guess you were tying to use .Value to get/set the value in the text box. .Text does this so I guess, in essence they would be the same if the .Value method/property exisited.
paulwhelanAuthor Commented:
it says

Error      83      The name 'iTrue' does not exist in the current context

thanks
paul
Ready1Commented:
where have you declared iTrue and iFalse cos  i cannot see it anywhere.

REgards,
Ready1
paulwhelanAuthor Commented:
ok sorry i declared them and the error is gone

its just the .value bit.

is it ok to use .text instaed of .value?

thanks
paul
paulwhelanAuthor Commented:
The thing is I have a similar page with this code

this._oList.Add((int)_cMaximumNumericUpDown.Value);
            this._oList.Add((int)_oDigitsBeforeDPNumericUpDown.Value);
            this._oList.Add((int)_oDigitsAfterDPNumericUpDown.Value);

and that works fine?

Any ideas?
paulwhelanAuthor Commented:
The three that are giving me a problem now are

this._oList.Add((int)_cRegularExpressionTextBox.value);
            this._oList.Add((int)_cAllowedCharactersTextBox.value);
            this._oList.Add((int)_oFailureMessageTextBox.value);


theyre all declared as
privater textbox _cRegularExpressionTextBox;
etc
PeterFearnCommented:
Hi there,

You can't simply cast a string value to an int, as this won't work

int i = (int)"2";  // this will throw a compiler error

you need to do this

int i = Convert.ToInt32("2");  // this is fine

so for your example above you need to do this

this._oList.Add(Convert.ToInt32(_cRegularExpressionTextBox.Text));
this._oList.Add(Convert.ToInt32(_cAllowedCharactersTextBox.Text));
this._oList.Add(Convert.ToInt32(_oFailureMessageTextBox.Text));

alternatively it would be better to write a nice function

e.g.

private int GetValue(TextBox textBox)
{
    if (textBox == null)
        return 0;
    try
    {
        return Convert.ToInt32(textBox.Text);
    }
    catch
    {
        return 0;
    }
}

then you can do

_oList.Add(GetValue(_cRegularExpressionTextBox));
_oList.Add(GetValue(_cAllowedCharactersTextBox));
_oList.Add(GetValue(_oFailureMessageTextBox));

Note: I've made it so that the function returns zero if it can't get the number correctly, or if the text box doesn't exist - this may not be suitable.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paulwhelanAuthor Commented:
Thanks Peter
That worked a charm!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.