Results 1 to 2 of 2

Thread: Help with VBA please

  1. #1
    Join Date
    Jan 2010
    Beans
    137
    Distro
    Ubuntu 10.04 Lucid Lynx

    Question Help with VBA please

    Previously all of my questions about C++ have been answered very helpfully (@dwhitney67 & @MadCow108). Hopefully you guys know VBA as well

    For a project at my summer-internship I need to know how to split a 16b binary line into two arrays(or vectors?) of 4b and 12b, using VBA. I am not familiar with VBA and have trouble following the syntax at this point.

    (i.e.) 1111111111110000 >>(split into 2 arrays somehow)
    array1(12b) = 111111111111
    array2(4b) = 0000

    After this I will perform some simple binary calculations with the two pieces of information.

    If you could point out any VBA reference material as helpful as cplusplus.com and learncpp.com is, that would be appreciated!
    Let books be your dining table, and you shall be full of delights,
    Let them be your mattress, and you shall sleep restful nights.

  2. #2
    Join Date
    Nov 2008
    Location
    Colorado, US.
    Beans
    68
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Help with VBA please

    VBA isn't something that pertains to LINUX at all in my experience but I do use it at work.

    Take a number, n.
    Convert it to a hex string: h=hex(n)
    Note that this may require adding on the analysis package, at least for Excel, you don't say what application you're using.
    Now, here's a function I wrote to convert a hex string to a binary string:
    Code:
    Function h2b(hstr)
    'convert hex string to binary string
        cnvarr = Array("0000", "0001", "0010", "0011", "0100", 0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111")
        bstr = ""
        For i = 1 To Len(hstr)
            hdgt = Mid(hstr, i, 1)
            cix = CInt("&H" & hdgt)
            bstr = bstr & cnvarr(cix)
        Next
        h2b = bstr
    End Function
    But you didn't ask about any of that. You're starting with a 16-character binary string, s.

    The 1st 12 characters are left(s,12)
    The last 4 characters are right(s,4)
    To convert a string to an array or list, you have to loop through the string one character at a time:
    Code:
    for i = 1 to len(s)
        a(i)=mid(s,i,1)
    next
    where a was defined to be an array:dim a(len(s))

    I have to say, though, that VBA is a poor choice for this unless you need to work within an application. This sort of thing is just what Python was made for (the string is already a list).
    ____________
    Bob Rashkin

Tags for this Thread

Bookmarks

Posting Permissions

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