Last Number

  • Thread starter Thread starter Craig Brunton
  • Start date Start date
C

Craig Brunton

Hi all,

I have a text box in which the user will enter a 4 digit number.

What I want to do is look at the last digit to see if it is a zero.

Is this possible?

Thanks in advance

Craig Brunton
 
Hi,



Dim strNum As String = "2432450"

Dim intLast As Integer

Try

Dim strLast As String = strNum.Substring(strNum.Length - 1)

intLast = CType(strLast, Integer)

If intLast = 0 Then

MessageBox.Show("Last number is zero")

End If

Catch ex As Exception

End Try



Ken
 
Hi,



Dim strNum As String = "2432450"

Dim intLast As Integer

Try

Dim strLast As String = strNum.Substring(strNum.Length - 1)

intLast = CType(strLast, Integer)

If intLast = 0 Then

MessageBox.Show("Last number is zero")

End If

Catch ex As Exception

End Try

To my mind, the following is cleaner:

If txtDigits.Text.Trim.EndsWith("0") Then
MsgBox("It ends with zero!")
End If
 

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

Similar Threads

Forms 2
Program upgrades 3
Number Problem 2
Regex match help. match exactly 4 digit numbers 1
Combobox filtering 2
Windows 10 Activate windows now message 3
Masked Edit Box - What's the difference 3
Descending Numbers 11

Back
Top