惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - 学剑学诗两不成

VB:如何实现在代码中弹出toolbar的ButtonMenu VB:如何发送WM_KEYDOWN和WM_KEYUP消息 利用IDocHostUIHandler接口屏蔽WebBrowser的弹出菜单 VB:如何改变ComboBox自身的高度 VB:如何设置Richtextbox的行间距 VB:如何允许/禁止RICHTEXTBOX中的OLE对象拉伸 一个很有用的自定义函数 - 学剑学诗两不成 - 博客园 VB:如何隐藏/显示treeview的ToolTips - 学剑学诗两不成 - 博客园 VB:如何启用/禁用本地连接 VB:如何选定文件或文件夹 - 学剑学诗两不成 - 博客园 一个远程调用api函数的模块(转贴) VB:如何用需要身份验证的SMTP邮件服务器发信 - 学剑学诗两不成 - 博客园 VB:如何监听打开的窗口和程序 VB:如何隐藏ListView的某一列 vb:如何禁止鼠标指针进入某个区域 如何使frame控件的caption居中显示 - 学剑学诗两不成 - 博客园 怎样去掉窗体上的图标 - 学剑学诗两不成 - 博客园 bug:在windows xp下用ImageList_GetImageCount返回值不正确(VB) - 学剑学诗两不成 - 博客园 VB中字符串数组快速复制的一种方法 - 学剑学诗两不成 - 博客园
VB中对string array快速插入、删除某个元素的办法 - 学剑学诗两不成 - 博客园
学剑学诗两不成 · 2006-01-09 · via 博客园 - 学剑学诗两不成

'作为测试,添加1个按钮,两个listbox
Private Declare Sub CopyMemory Lib "kernel32" Alias _
    "RtlMoveMemory" (dest As Any, source As Any, _
    ByVal numBytes As Long)

Sub InsertStringItem(strArr() As String, ByVal index As Long, _
        ByVal newItem As String)
    Dim lastItem As Long, saveAddr As Long
    lastItem = UBound(strArr)
    saveAddr = StrPtr(strArr(lastItem))
    CopyMemory ByVal VarPtr(strArr(index + 1)), ByVal _
        VarPtr(strArr(index)), (lastItem - index) * 4
    CopyMemory ByVal VarPtr(strArr(index)), saveAddr, 4
    strArr(index) = newItem
End Sub

Private Sub DeleteStringItem(strArr() As String, ByVal index As Long)
    Dim lastItem As Long, saveAddr As Long
    lastItem = UBound(strArr)
    saveAddr = StrPtr(strArr(index))
    CopyMemory ByVal VarPtr(strArr(index)), ByVal VarPtr(strArr(index + 1)), (lastItem - index) * 4
    CopyMemory ByVal VarPtr(strArr(lastItem)), saveAddr, 4
    strArr(lastItem) = vbNullString
End Sub


Private Sub Command1_Click()

    Dim a() As String
    ReDim a(5) '
    a(0) = "1 黄河远上"
    a(1) = "2 白云一片"
    a(2) = "3 孤城万仞山"
    a(3) = "4 羌笛何需怨"
    a(4) = "5 杨柳春风"
    a(5) = "6 不渡玉门关"
    '插入元素的时候先redim,再调用InsertStringIte
    ReDim Preserve a(UBound(a) + 1)
    InsertStringItem a, 1, "mc"
    '测试输出
    Dim i As Long
    For i = 0 To UBound(a)
        List1.AddItem "a(" + CStr(i) + ")=" + a(i)
    Next
    '删除元素的时候,先调用DeleteStringItem,再redim
    DeleteStringItem a, 2
    ReDim Preserve a(UBound(a) - 1)
     '测试输出
    For i = 0 To UBound(a)
        List2.AddItem "a(" + CStr(i) + ")=" + a(i)
    Next
End Sub

posted on 2006-01-09 14:48  学剑学诗两不成  阅读(3122)  评论()    收藏  举报