Field Validation in VB2005 winforms

A

Alex

Hi,

I'm writing an app to test Enterprise Libraries in Visual Basic 2005,
and I have a question that hopefully someone has run across.

I'm passing text from my form to a class property setup as a Long, and
if I enter anything except a number it throws an InvalidCastException
trying to convert the String to a Long. I hoped I could fix this with
the Enterprise Library's Validation classes, and though they work if I
pass a number, the exception has already thrown by the time it gets to
the Ent Library classes.

Here's my code:

.... from cClass ...
<NotNullValidator()> _
<RangeValidator(1, RangeBoundaryType.Inclusive, 9999999999,
RangeBoundaryType.Inclusive, Ruleset:="RuleSetA",
MessageTemplate:="Loan ID must be 1 to 10 digits")> _
Property ID() As Long
Get
Return _ID
End Get
Set(ByVal value As Long)
_ID = value
End Set
End Property

.... from Form.vb ...
cClass .ID = txtID.Text

If I enter a text string "asdfasdfa" for example or "" in txtID.text,
it blows with the InvalidCastException . Entering a valid number
actually works and the Ent Libraries kick in, but i need to test the
string before that point.

Any suggestions?

Thanks --

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top