Domanda

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

È stato utile?

Soluzione

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!!

Altri suggerimenti

Try this:

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

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.

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

Cint(mtPig.Text) 

or

Convert.ToInt32(mtPig.Text)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top