VB can also access memory

zhaozj2021-02-16  46

Some people say that VB cannot operate memory, the efficiency is low, I don't agree. VB and C are relatively low than of course efficiency, but if it is used, there is a lot of efficiency.

When developing Windows (Note, not driver) Of course, this is a big relationship with the user's skill. If the skill of C / C is very good, you can even use VB to implement the function of memory, because the long type can make a pointer.

I have been doing interfaces recently, a little study on VB, give an example. For example, 10 credit converted 2, use VB general use: public function O2B (Byval Long nvalue) AS STRING DIM NVALUECOPY AS Long Dim NTMP AS Byte 'Business Dim Sreturn AS String' Return Value Nvaluecopy = NVALUE

'Also use NValue - 2 ^ n method, there is not much to say

Do while nvaluecopy> 0 ntmp = nvaluecopy / 2 sreturn = cstr (nvaluecopy - ntmp / 2) & sreturn 'reverse accumulated nvaluecopy = NTMP loop O2B = SRETURN

END FUNCTION

And cooked people generally bits: public function O2B (Byref long nvalue) AS STRING DIM NBIT (0 to 7) as Byte 'The smallest unit is byte, pack DIM NBYTE (1 to 4) AS BYTE 'Decomposition Nvalue to Byte DIM NTMP AS BYTE DIM PVALUE AS LONG' Pointer DIM SRETURN AS STRING 'Return Value Dim i as Byte, J AS Byte

nbit (0) = 1 '00000001 nbit (1) = 2' 0000000010 nbit (2) = 4 '00000100 nbit (3) = 8' 00001000 nbit (4) = 16 '0000000 nbit (5) = 32' 00100000 NBIT ( 6) = 64 '01000000 nbit (7) = 128' 10000000 'Take the address of NVALUE PVALUE = Varptr (NValue)

'Win32 API, copy the 4 bytes of nvalue to NBYTE, Byref is equivalent to the pointer CopyMemory (Nbyte (1), byref pvalue, 4)

For i = 4 to 1 'low byte in front for j = 7 to 0' high start 'method one, subtraction NTMP = 0 if Nbyte (i)> nbit (j) Then nbyte = nbyte (i) - nbit (j) - NBIT (J ) NTMP = 1 'This binary is 1 end if sreturn = SRETURN & CSTR (NTMP)' Method 2 NTMP = 1 if (NOT (NBYTE (i) Imp nbit (j))) = Nbit (j), I didn't find the VB bit bit and function, only IMP ntmp ntmp ntmp= 0 end if sreturn = sreturn & cstr (ntmp) (NTMP) NEXT J, I

O2B = SRETURNEND FUNCTION

In the Internet cafe, there is no environment, write write, there is a mistake, please forgive, mainly thinking.

转载请注明原文地址:https://www.9cbs.com/read-27372.html

New Post(0)