|
-
Aug 31st, 2000, 10:47 PM
#1
Thread Starter
Lively Member
how do I convert a octal value to a regual number?
I can do it the other way around but not that way. HELP!
Frankie Weindel
VB 6 Learning Edtion SP3
-
Sep 1st, 2000, 12:15 AM
#2
Lively Member
-
Sep 1st, 2000, 12:36 AM
#3
transcendental analytic
I think you mean decimal value
Code:
Function Base2Dec(val$, base%): Dim n%, a() As Byte
a = StrConv(UCase(val), vbFromUnicode)
For n = 1 To Len(val)
Base2Dec = CDec(Base2Dec + (a(n - 1) - 48 + 7 * (a(n - 1) > 64)) * base ^ (Len(val) - n))
Next n
End Function
Function Dec2Base$(val, base%): Dim n%, s
For n = 0 To 100
s = Int(val / base ^ n)
If s = 0 Then Exit For
s = s - Int(s / base) * base 's mod base
Dec2Base = Chr(s + 48 - 7 * (s > 9)) & Dec2Base
Next n
End Function
example:
Msgbox Base2Dec(1000,8)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 1st, 2000, 12:39 AM
#4
Take in your octal number as a string, for example:
Code:
strOctNum = InputBox("Enter an octal number:")
Append the string "&O" (that's the letter "O" there) to the octal number string and use that as the argument to the Val function, assigning the result of that function to an Integer (or Long):
Code:
intDecimalNumber = Val("&O" & strOctNum)
Msgbox "The decimal equivalent is: " & intDecimalNumber
"It's cold gin time again ..."
Check out my website here.
-
Sep 1st, 2000, 03:25 AM
#5
Frenzied Member
Neat method BruceG!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|