国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

在VB組件中使用串緩沖 - 2

2024-07-21 02:15:42
字體:
來源:轉載
供稿:網友
lesson 2 : the vb component
--------------------------------------------------------------------------------

how2project4.vbp

the dobuffer() method
the dobuffer() method will be sent a string buffer (strbuffer), the value of the length of the string data
already placed within the buffer (lngbuffer), and the string to add to the buffer (addstring). these
arguments will be declared and sent from our methodname() method, which will be covered later in this
article.

private sub dobuffer(byref strbuffer as string, byref lngbuffer as long, byval addstring as string)



notice that the dobuffer() method is declared as a subroutine rather than a function. this is because it
doesn"t really return any data from the method itself. rather, it manipulates the data sent by reference
from the calling method.

two local variables need to be declared for internal use.

dim strhold as string
dim lngindex as long


now our first line of business will be to determine whether our buffer is large enough to hold the string
data we want to add to it. but before we do this, we want to check out whether our calling method sent a
null string or not.

if not trim$(addstring) = "" then



if the calling method sends a null string, we"ll quietly skip the concatenating process and avoid the
whole affair via this if-then statement. on the other hand, if the sent string holds characters, we"ll
need to check that the buffer is large enough to hold them. to do this the current length of the data in
the buffer is added to the length of the sent string and then the resulting sum is compared to the length
of the overall buffer size.

if lngbuffer + len(addstring) > len(strbuffer) then



if the buffer is large enough to fit the sent string, then the code discussed next will be skipped. this
will occur more often than not since we"ll set our string buffer to hold a large amount of data when we
declare it in the methodname() method. but lets assume that this isn"t the first time the dobuffer()
method was called and that the buffer is too small to add the sent string.

we first need to store the existing buffer data in a local string variable:

strhold = strbuffer


now we"ll go through a do-loop to exponentially increase a test of the size of the buffer. each time
through the loop a new buffer size is tested against the previous buffer size. once the stored buffer data
and the new string fit the buffer, the loop will be exited.


do
lngindex = lngindex + 1
if (len(strbuffer) + (65536 * lngindex)) >= (lngbuffer + len(addstring)) then

exit do
end if
loop


the 65536 size increase is arbitrary and you can set this number to what you think will be appropriate for
the total size of the string data you"re building.

the buffer can now be rebuilt to its new expanded size...

strbuffer = string$(len(strbuffer) & (65536 * lngindex), chr(0))



....and refilled with the stored string data that it previously held:

mid$(strbuffer, 1, lngbuffer) = strhold


notice that the string we want to add to the buffer hasn"t been added yet. we simply increased the size of
the buffer.

here"s the code that increases the buffer size if our sent string doesn"t fit into the buffer. it"s
repeated here so you can see it in one glance.

if lngbuffer + len(addstring) > len(strbuffer) then
strhold = strbuffer
do
lngindex = lngindex + 1
if (len(strbuffer) + (65536 * lngindex)) >= (lngbuffer + len(addstring)) then
exit do
end if
loop
strbuffer = string$(len(strbuffer) + (65536 * lngindex), chr(0))
mid$(strbuffer, 1, lngbuffer) = strhold
end if


once the buffering size has past our size test, or actually resized, we can add our sent string to the
data stored in the buffer.

mid$(strbuffer, lngbuffer + 1, len(addstring)) = addstring


now that the sent string (addstring) has been added to the buffer, we need to increase the lngbuffer
variable value to reflect the new length of the buffer"s string data stored in it.

lngbuffer = lngbuffer + len(addstring)


here"s a repeat of the code that adds the sent string to the buffer and increases the buffer data size



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 晋宁县| 尤溪县| 诏安县| 江阴市| 阳山县| 井研县| 诏安县| 丰宁| 普格县| 镇原县| 清流县| 荆门市| 新营市| 万州区| 九寨沟县| 家居| 宣威市| 海丰县| 偃师市| 丰镇市| 长武县| 荥经县| 青阳县| 昌邑市| 静海县| 甘肃省| 南投市| 静安区| 新巴尔虎右旗| 航空| 新昌县| 宿松县| 黔江区| 邵东县| 雅安市| 阜城县| 庆云县| 平罗县| 那坡县| 通山县| 盐山县|