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:)

Odd or even and converting Decimal to binary, octal, or hexadecimal and back.
newuseroverhere
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. < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Public Function OddEven(num As Long) As String
If num Mod 2 = 0 Then
OddEven = "Even"
Else
OddEven = "Odd"
End If
End Function
[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)
Michael Feingold
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
Ljubica
l would love to get the code for converting from Binary, octal,decimal,hexadecimal and back if it is possible using VB
VishalR
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