AdorableVB
AdorableVB

Reputation: 1393

Masked TextBox doesn't recognize 10 as ten

For i As Integer = 0 To mtPig.Text
        MessageBox.Show(i)
    Next

I used a MaskedTextBox with a 2-digit mask.
If I put 10, it shows 0 and 1.
If I put 9, it shows 0-9.

Why doesn't it read the zero next to one? (10)
How can I make 10 read as ten?
UPDATE:
enter image description here

Upvotes: 1

Views: 126

Answers (4)

Jade
Jade

Reputation: 2992

Alright, the problem is your PrompChar:0, all 0s will be treated as prompt character and discarded from value.

To solve it, do either

  • change your PromptChar to _ (underscore)
  • or set the MaskedTextbox property named TextMaskFormat to IncludePrompt

GOOG Luck!!

Upvotes: 2

rayncorg
rayncorg

Reputation: 993

you must convert it to integer then try this...:

Cint(mtPig.Text) 

or

Convert.ToInt32(mtPig.Text)

Upvotes: 0

Enigmativity
Enigmativity

Reputation: 117084

Try this:

For i As Integer = 0 To Integer.Parse(mtPig.Text)
    MessageBox.Show(i)
Next

Upvotes: 2

TomTom
TomTom

Reputation: 62111

For loop doesn't recognize 10 as ten

No, For loop does not magically transform a string to an int.

Cast, convert, do it in code. But do not assume the compiler will magically do converts.

Upvotes: 1

Related Questions