Split Numeric and Convert to Binary

q582gmzhi

Registered User.
Local time
Today, 00:05
Joined
Dec 23, 2002
Messages
48
Hi,

I am working on sending data via a comm port using mscomm32 to some electronic display equipment.

The electronic equipment will mimic the data on the users form via electronic digits. The form will have at least 4 fields showing numeric data only.

i.e: 1st Field displays numeric data from 0 to 999 as shown below:

1st Field Data: 0-999
2nd Field Data: 0-9
3rd Field Data: 0-99
4th Field Data: 0-999

I need to send the electronics the data in binary format and include some address data also:

So for example I need to split the 1st Field Data data into 3 parts and add the address data to each part:

Using 1st field as an example and the figure 295

example after split:
Module1: 2
Module2: 9
Module3: 5

Then I have to convert the above into its binary format:

00000001:00000010
00000010:00001001
00000011:00000101

The electronic equipment is expecting to recieve for each module an address data followed by the data for that address.

Please can anyone advise or post an example of how to achieve the above goals.

I am not looking at pushing the data yet, I just want to get the format right for each field and its individual modules.

Thanks in advance

Daz.....
 
Here is some code to get you started.
Not quite sure how it will fit in with what you need but it will take a number and output it as a three module binary to the debug window.

Code:
Sub test()
Dim intOut As Integer
Dim strout As String
Dim j As Integer
Dim l As Long
intOut = 295
strout = Format(intOut, "000")
For j = 1 To 3
    l = j
    Debug.Print SetBinStr(l, Mid(strout, l, 1))
Next j
End Sub
Public Function DecimalToBinary(lng As Long) As String
Dim strTemp As String
    strTemp = Trim(Str(lng Mod 2))
    lng = lng \ 2
    Do While lng <> 0
        strTemp = Trim(Str(lng Mod 2)) & strTemp
        lng = lng \ 2
    Loop
    DecimalToBinary = strTemp
End Function
Function SetBinStr(intMod As Long, intDigit As Long) As String
SetBinStr = Format(DecimalToBinary(intMod), "00000000") & ":" & Format(DecimalToBinary(intDigit), "00000000")
End Function

Peter
 
Peter,

Many thanks for the posting I will work with it and hopefully get to where I need to be.

Thanks again

Daz...
 

Users who are viewing this thread

Back
Top Bottom