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

推荐订阅源

Know Your Adversary
Know Your Adversary
D
Docker
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
V
V2EX
V
Visual Studio Blog
J
Java Code Geeks
博客园 - 【当耐特】
罗磊的独立博客
量子位
W
WeLiveSecurity
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
O
OpenAI News
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
S
Schneier on Security
博客园 - Franky
WordPress大学
WordPress大学
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
腾讯CDC
美团技术团队
博客园 - 叶小钗
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
S
Secure Thoughts
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
TaoSecurity Blog
TaoSecurity Blog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
D
DataBreaches.Net
Project Zero
Project Zero
S
SegmentFault 最新的问题
C
Cisco Blogs
H
Help Net Security
Google Online Security Blog
Google Online Security Blog
A
About on SuperTechFans
F
Fortinet All Blogs
博客园 - 司徒正美

博客园 - 学剑学诗两不成

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)  评论()    收藏  举报