pythonexcelvbatype-conversion128-bit

VBA - 128Bit value to 128 checkboxes


I need a bit of help how to transfer some data from a Pythonscript into my VBA program. I have a system with 128 switches that can be on or off (1 or 0). In my python script I read the value of the individual switches, and I now wanna send that data back to my VBA program, where I have 128 check boxes that represent those switches.

My current progress is in python to bitshift those 128 numbers, and then use that 128bit integer to print back to VBA. Right now I use "print" in python and in VBA checks for the print in the shell - I then read out that data to a string.

Now my string will have the ASCII value of my switches (etc 170141183460469231733416685972794376193)

How do I convert this ASCII string into something usefull to click those checkboxes? I plan to use a loop than runs 128 times that then goes

Controls("CheckBox" & Counter).value = BINARYVALUE[Counter]

where counter is the loop counter, and the BINARYVALUE is where the 128bit binary value is stored

Thanks for the help!


Solution

  • It might be simpler just to build and pass a string of those bits, like:

    Switches = "11111111111111111111101111100000011111111000000000011111111100000011111111111111111111010101111111111111111110000001111111111111"
    

    Then you can just loop this:

    Me.Controls("CheckBox" & Counter).Value = CBool(Mid(Switches, Counter, 1))