how to check if textbox value is a multiple of a field in a database

I am using VB.Net 2005 SP1 Compact Framework 2.0 with MS SQL Server 2005 Compact.

I have a textbox called txtD that only accepts integers. I need to know how to compare that value to a value in field t_adc in tblTally and determine if txtD is a multiple of t_adc.

for example if t_adc = 3 then txtD would have to be 3, 6, 9, 12, 15 ...etc to be valid.
another example if t_adc = 2 then txtD would have to be 2, 4, 5, 8, 10...etc to be valid

How would I do that? See my code below to help me finish it off. I left a message where I need help.



        Dim ssceconn As New SqlCeConnection("Data Source = \Program Files\data\products.sdf"
        Dim readerCT As SqlCeDataReader
        Dim cmdCT As New SqlCeCommand("SELECT t_adc FROM  tblTally WHERE t_albl = 'Spec'", ssceconn)
        Dim dc As Integer
        readerCT = cmdCT.ExecuteReader

        While readerCT.Read
            dc = CInt(readerCT.Item("t_adc").ToString)
        End While

        ' Close the connection
        readerCT = Nothing

        ssceconn = Nothing

        If txtD.Text  is multiple of dc Then ' THIS IS WHERE I NEED HELP
            MsgBox("Valid  Entry.")
        End If

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.


if isnumeric(txtD.Text) and ((txtD.Text / dc) = (txtD.Text \ dc)) then 'valid entry

Experts Exchange Solution brought to you by ConnectWise

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
Hi PBLack,

Try this:

        If Val(txtD.Text) Mod 2 = 0 Then ' THIS IS WHERE I NEED HELP
            MsgBox("Valid  Entry.")
            MsgBox("inValid  Entry.")
        End If
Jorge PaulinoIT Pro/DeveloperCommented:

You can create a new ArrayList, then fill it in your loop (all the possible values for your combination) and then compare if it mach. Look this simple example:

Dim myArray As New ArrayList

' You loop with all possible values for your combination
While readerCT.Read
End While

' Compare
If myArray.Contains(txtD.Text) Then
End If

myArray = Nothing
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.