Results 1 to 2 of 2

Thread: any one ready to solve digital to analog conversion

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Thumbs up

    Iam a nerd Vb programmer working in engineering field with Vb .I want to know how to do digital to analog conversion in Vb.I have asked the same question in my previous thread
    also,but i couldnot get a reply.I am looking out for some one who helps me to solve the problem.I will feed the digital data(binary number) in a textbox and want the analog equivalent(decimal eq of binary number) in another text box.I need the coding also because Iam new to this sort of programming.The program must be general for any binary number irrespective of the number of binary digits.

    The matter is very urgent.Kindly help me as soon as possible.I thank the person who helps me to solve it.

    Any one with soln can contact me at:[email protected]

  2. #2
    Guest
    Loop through the text box right to left, character by character.

    Delclare yourself a long or double variable.

    When you find a "1" in the text box, set the bit in the long variable that corresponds to the current position in the text box.

    eg:

    Text in text box is "10110"
    Code:
    Select Case lPos 'lPos is the current position, 1 being rightmost
    Case 1
        varLong = varLong Or 1
    Case 2
        varLong = varLong Or 2
    Case 3
        varLong = varLong Or 4
    Case 4
        varLong = varLong Or 8
    Case 5
        varLong = varLong Or 16
    Case n
        varLong = varLong Or (n^2)
    End Select
    
    txtDecimal.Text = Cstr(varLong)
    I've used a case to illustrate the technique, bu that is a bad way of doing it (cos you have no idea how long the binary string is. A better option is

    lChar = The char to dela with
    lPos = the curent position in the string
    Code:
    If lChar = "1" then
        varLong = varLong Or (lPos^2)
    End If
    That should work nicely (although I admit that I wrote that without testing it in VB)

    - gaffa


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width