Odd or even and converting Decimal to binary, octal, or hexadecimal and back.

how do I make an algorithm that asks the user to enter an integer number, then determine whether the number is odd or even. How would you write that in Visual Basic code?

Secondly I need to figure out how to convert a decimal number into binary, octal, or hexidecimal. It needs to ask the user to enter a decimal number and then ask if it needs to be converted to binary, octal, or hexidecimal. The Algorithm should ask until the option is legal.
Then I need to make an agorithm that converts binary, octal, or hexidecimal back to decimal. Once again, if it's an illegal then the algorithm will repeat the question over and over until there's a legal option. First the Algorithm should find out if the user wants to use binary, octal, or hexidecimal. Then ask user to enter decimal number (from number system)

Any help you can provide would be great!
Thanks:)

[880 byte] By [silver6] at [2008-3-7]
# 1
Hi,
Here's the response from the engineer who is helping out with this:

There are two questions. The first one is very clear. I can share him some sample code. But the second one is not very clearly. I do not know what he wants.

  1. To check the value is Odd or Event. We can have the code like this.

Public Function OddEven(num As Long) As String

If num Mod 2 = 0 Then

OddEven = "Even"

Else

OddEven = "Odd"

End If

End Function

  1. The second one is about a program. But he does not say how to use it. In his description, some UI is needed. So I can not determine how to write.

[I can not give a complete sample] code of the function. But he can use these feature to do it.

a) In VBA, we can add some form in our code. Some information can be input by the Form.

b) To convert to decimal to the string. We can use the function Hex, and Oct. They can convert decimal to Hex and Octal values.

Per the engineer's request, please provide more details around your second question so that he can provide a more detailed answer. I'll make sure it gets back to him.

thanks,
-brenda (ISV Buddy Team)

MSISVBuddyTeam at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2
Hi,

I'd like to know as well if there's a easy way in VBA to convert Hex and Oct values to Dec values.

Thank you.

Matthew

sybakc at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3

These should give you the results in Access VBA

Private Sub HexToDecimal()
Dim s, c As String
s = StrReverse(CStr(Me.txtHex.Value))
Const cHex = "0123456789ABCDEF"

Dim i As Integer
Dim decVal, intVal As Long
decVal = 0
For i = 1 To Len(s)
c = Mid(s, i, 1)
intVal = InStr(1, cHex, c) - 1
intVal = intVal * (16 ^ (i - 1))
decVal = decVal + intVal
Next i

Me.lblHDec.Caption = decVal

End Sub

Private Sub OctToDecimal()
Dim s, c As String
s = StrReverse(CStr(Me.txtOct.Value))

Dim i As Integer
Dim decVal, intVal As Long
decVal = 0
For i = 1 To Len(s)
intVal = CInt(Mid(s, i, 1))
intVal = intVal * (8 ^ (i - 1))
decVal = decVal + intVal
Next i

Me.lblODec.Caption = decVal

End Sub

unit107 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 4

l would love to get the code for converting from Binary, octal,decimal,hexadecimal and back if it is possible using VB

Lgee212 at 2007-9-9 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...