Solved

How to determine how many ODD and EVEN digits are in a number using VB6?

Posted on 2016-07-17
3
68 Views
Last Modified: 2016-07-18
How can one use VB6 to determine how many ODD and how many EVEN digits there are in a number?
Example----Label1 has the following number on it:
174638891  

..... 5 of the digits are ODD .... 4 of the digits are EVEN

Thanks.
0
Comment
Question by:jazjef
  • 2
3 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41716305
Dim intCount As Integer
Dim intIndex As Integer

For intIndex = 1 To Len(Label1.Caption)
    If Mid(Label1.Caption, intIndex, 1) Mod 2 = 0 Then
        intCount = intCount + 1
    End If
Next
MsgBox "There are " & intCount & " even numbers"
MsgBox "There are " & Len(Label1.Caption) - intCount & " odd numbers"

Open in new window

0
 
LVL 4

Author Closing Comment

by:jazjef
ID: 41717855
Thanks Martin .... works great.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41717886
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now