Question

Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number....

Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number. Specific requirements: Use InputBox function to acquire the input for an arbitrary binary integer number; Convert the binary integer to its equivalent decimal number; Return the decimal number in a message box. Submit your (VBA code) Excel screen shoot.

Below functions may be useful in your VBA code:

Val( ): can convert a string-type number in ( ) to its numeric value;

Len( ): can count the length or how many characters in the string in ( );

Mid( , , ) : can select and pick up certain characters from a string.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Private Sub CommandButton1_Click()
'Define Variable to get the input binary
Dim Binary As String
'Read input binary number and assign to variable
Binary = TextBox1.Value
Dim index As Integer
'Loop thru all the digits of binary string and compute decimal
For index = 0 To Len(Binary) - 1
DecimalValue = CDec(DecimalValue) + Val(Mid(Binary, _
Len(Binary) - index, 1)) * 2 ^ index
Next
'Display in message box
MsgBox DecimalValue
End Sub

Add a comment
Know the answer?
Add Answer to:
Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using assembly 8086, Convert a binary string to decimal. Accept buffered user input in the form...

    using assembly 8086, Convert a binary string to decimal. Accept buffered user input in the form of a 16-bit binary string. Convert to signed integer and print to the screen. If the user enters less than 16 bits, or input illegal character return an error message and prompt for input again. Sample Execution: Enter a 16-bit binary number: 100111100101110 The decimal signed integer equivalent is -24996 Enter a binary number: 11001011100 Error! Please enter exactly 16-bits: 100111100101110 Enter a 16-bit...

  • using assembly 8086 , Convert a binary string to decimal. Accept buffered user input in the...

    using assembly 8086 , Convert a binary string to decimal. Accept buffered user input in the form of a 16-bit binary string. Convert to unsigned integer and print to the screen. if the user enters less than 16 bits, you may pad the binary number with zeros on the left. Sample Execution: Enter a 16-bit binary number: 1001111001011100 The decimal unsigned integer equivalent is 40540 Enter a 16-bit binary number: 01100 The decimal unsigned integer equivalent is 12

  • I need this problem to be solved in Excel VBA code. Need full code in VBA....

    I need this problem to be solved in Excel VBA code. Need full code in VBA. Please solve 1st Task : '5 or 0'. Please help me urgently with proper answer and coding solutions which I can run in Excel/vba. Thanks Course: Programming languages Second laboratory work File and string processing Create a program that processes text file according to task variant. Requirements: 1. Create text file (use notepad) with some lines of data according to task variant. 2. Ask...

  • The code is to convert the fractional part of a decimal number to its hexadecimal form....

    The code is to convert the fractional part of a decimal number to its hexadecimal form. Can you explain the code, for example ,why the fractional part need to multiply 16 instead of devise 16? FracNum DecNum-num int count, IntPart float FracPart; float temp temp-FracNum *16; FracPartstemp- (int) temp; //getting Fractional part from temp IntPart (int) temp; count-e ise while (FracPart >e && count<=6) //while fractional part e and count Less than or equal to 6 then //Now taking fractional...

  • 1. Implement an algorithm to convert binary number into an integer. Binary number is represented as...

    1. Implement an algorithm to convert binary number into an integer. Binary number is represented as a string. Ex. int n = to_int("01010"); int to_int(const std::string& b) { } 2. Implement an algorithm to convert a decimal number to binary. The return type is string which holds the binary number as string. std::string to_binary(int n) { } 3. Implement a function to check if the number is positive or negative. The function should return true if number is positive. bool...

  • C++ Convert a Number from Binary to Decimal using a stack: The language of a computer...

    C++ Convert a Number from Binary to Decimal using a stack: The language of a computer is a sequence of Os and 1s. The numbering system we use is called the decimal system, or base 10 system. The numbering system that the computer uses is called the binary system, or base 2 system. The purpose of this exercise is to write a function to convert a string representing a binary number from base 2 to base 10. To convert a...

  • a) The following program is supposed to convert a binary number to its decimal equivalent. Modify...

    a) The following program is supposed to convert a binary number to its decimal equivalent. Modify the program so that it does the job.(15 points) b) How would you create the executable file of the program (file name: b2d.c) in Linux? (5 points) #include <stdio.h> int main (void) int binary: printf("Enter a binary number:\n"); scanf("%d", &binary): int nofDigit = 0, remain = binary: while (remain > 0) - remain = remain/10; nofDigit++; int digit, dval = 0, bx = binary:...

  • Convert a decimal fractional number 34/5 to its binary equivalent using a program to  evaluate the bits...

    Convert a decimal fractional number 34/5 to its binary equivalent using a program to  evaluate the bits of the fractional part for at least upto the second repeating block. i have written some code in python however it is not getting an output at all, so either fixing the code or writing another one would be beyond helpful def binary(n,k): n = 8.6 k = 3 #'n' is the fractional number #'k' is the number of bits up to the loop...

  • In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of num...

    In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of number can be anything such that all digits are represented using 0 to 9 and A to Z. Value of A is 10, Value for B is 11 and so on. So, write a program to convert a number to decimal Example: Input number is given as string and the output is an integer. Input Output Input...

  • Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...

    Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT