Dive depth (ten meters, water temperature 0 ° C), time Beijing time zero.
"Sea Snake" is exclaimed.
I saw a black long sea snake in the depths of the sea, almost all people were in a daze. But the sea snake said a word that made us bold "" I am a famous VB string. If you continue to dive, you have to pass me. "
I habitually observed it, because I know that I want to defeat a opponent, I must know in depth.
So I wrote a small code to understand it.
Dim Str As String
Str = "Give ME A Beauty"
DIM L1 AS Long
DIM L2 AS Long
L1 = LEN (STR)
L2 = leNB (STR)
Debug.print L1, L2
This code is very good, fully compliant with my imagination, show 12, 24 in the immediate window,
GOOD, so I am going to print it with Textout in the window. As for why I have to have this function without other, do you manage? So I wrote down the following code.
Dim Str As String
Str = "Give ME A Beauty"
DIM L1 AS Long
DIM L2 AS Long
L1 = LEN (STR)
L2 = leNB (STR)
Debug.print L1, L2
Textout Me.HDC, 100, 100, STR, L1
Result I found no? It seems that the string length is wrong, think of it, the string in VB is BSTR type, then use L2 length, right, try it.
God, there is a book after the string, is God in implies me when I give me a beauty?
However, I think that God will promise me so soon, so it must be a problem with my code.
When I am thinking, all people are watching me. No way, too handsome.
So I quickly wrote the following code.
Private declare function lenansi lib "kernel32" Alias "Lstrlena" (Byval String1 AS String) AS Long
......
Dim Str As String
Str = "Give ME A Beauty"
DIM TRUELEN AS Long
Truelen = lenansi (STR)
Textout Me.hdc, 100, 100, Str, Truelen
When I quickly pressed F5, there was a response in the sky, and "Give ME A Beauty" has got the correct response.
At this time, I looked at this sea snake, and I was confident that it was very secret.
Have you seen a smile of a snake, it's a slowly swim.
"If you plan to pass my words, I also want to be too easy." Why is this sentence so familiar? Is it in the golden twelve palace?
"Give you a small test, you know vbnullstring and" "What is the difference?"
"Don't think that you are a sea snake, you are too simple." I have a young man with a very ugly, people are sent out (the seventh hand of the world), "You thought I didn't read the Marine Biological Guide." Object browser)
Const vbnullstring = "" "
Member of VBA.Constants
When an external process is called, the constant used when a non-zero value is required.
"Then what you mean is the same, then vbnullchar?" The sea snake didn't looked at the seventh handsome of the world. "Of course, it's the same, do you see VB's instructions?" The seventh hand of the world came out, but he felt that it was a bit wrong. But the VB object browser is indeed
Const vbnullchar = ""
Member of VBA.Constants
So what is the following code represents?
Sea snake gives its code
DIM S1 As String
DIM S2 AS STRING
DIM S3 AS STRING
S1 = VBNULLSTRING
S2 = VBNULLCHAR
S3 = ""
Debug.Print Strptr (S1), STRPTR (S2), STRPTR (S3)
Debug.print lenb (S1), LENB (S2), LENB (S3)
After the seventh hand of the world presses F5, he is surprised by the operation of the sea snake code.
0 1899284 1434596
0 2 0
Then say that VB's instructions and the sea snake must be wrong. Moreover, for the two values of S1 are zero, the pointer points to zero, the length is zero, it is not a zero value in a common sense.
The seventh hand of the world is turned to look at me.
"Kid, out of the wind, come, I will give you something"
"You want to defeat the sea snake, you must understand the structure of the sea snake."
VB's string is a standard BSTR string, such as "Hello" string it is like this.
A 0 0 0 'H' 0 'E' 0 'L' 0 'L' 0 'o' 0 0 0
It can be seen that the four bytes represent the actual length of the character string, which is a long value.
The last two bytes are end characters that represent zero values.
The intermediate ten bytes are just the content of the string.
If we use S1 = "Hello", S1 is pointing to.
"I originally thought that S1 is pointing to the first byte, but when I use the self-contained VB memory observation tool to see the byte value followed by StrPtr (S1), S1 is pointing to the fifth byte, also It is where our character string is really starting. "
"Everyone knows the structure of the sea snake, then why is it different from the three cases mentioned?" I was still in a daze.
"Yes, why?"
Ok, take out your oleView, open vb6.dll in file-> view type, you didn't see a very wonderful world, don't live, find the following
Modules-> Modules Constants
Open them, you will see the true definition of VB.
[HelpContext (0x0010AA32)] const LPSTR vbnullstring = "";
[HelpContext (0x0010AA32)] Const lpstr vbnullchar = "/ 0";
I saw no, vbnullstring points to an empty string, but this empty string is site. VBNullChar is a zero character (equivalent to the last character in the string in C). So what happened when we came to see the code of the sea snake?
S1 = VBNULLSTRING
When VB saw this, it clearly turns the value of S1 into zero
S2 = VBNULLCHAR
When VB saw this, it made a few actions, which allocated a BSTR string with SysallocStringlen in the stack, and then copied '/ 0' into this string.
S3 = "" Here VB has worked a lot, first, VB is compiled, "" as a constant, it must apply for this empty string to apply for a variable. When the EXE file is loaded, you have to set an address, although it does not mean anything.
Is a string such a 00 00 00 00 00 00, it requires 6 bytes (four headers and 2 tail bytes)
Then pass the address value of the fifth byte to S3 when you see this sentence.
So, although you just wrote a "", the result VB made a lot of work. Although there are not many bytes, but in a big project, everyone will write "", then it is also a very considerable overhead. So next time you absolutely don't use "", but you must use vbnullstring.
"You said, yes, sea snake", I looked at it scorn.
The sea snake saw that everyone suddenly realized, and then I made a laughter (the sea snake laughed?)
"Learn me, not really controlled me, many C's divers will dismissive vb, do you know why?"
"Slow, the string of VB is too slow" "Many divers have returned to answer this question.
"Oh, yes," The sea snake laughed, slowly swimped to the deep sea "I will back!"
Leave our group of diving people, everyone is thinking, do we really understand the sea snake, because the VB ocean legend is quite terrible, it will walk so easily, and it's said I will back what is this about?
But we will continue to dive ...
"Look, the coral reef" is exclaimed!