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

推荐订阅源

博客园 - 三生石上(FineUI控件)
O
OpenAI News
WordPress大学
WordPress大学
P
Proofpoint News Feed
J
Java Code Geeks
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Register - Security
The Register - Security
Engineering at Meta
Engineering at Meta
H
Help Net Security
人人都是产品经理
人人都是产品经理
Vercel News
Vercel News
N
Netflix TechBlog - Medium
F
Full Disclosure
U
Unit 42
Latest news
Latest news
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
InfoQ
L
LINUX DO - 最新话题
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
小众软件
小众软件
I
Intezer
V
V2EX
S
SegmentFault 最新的问题
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
Security Archives - TechRepublic
Security Archives - TechRepublic
Recent Announcements
Recent Announcements
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Recorded Future
Recorded Future
博客园 - Franky
Project Zero
Project Zero
S
Securelist
Attack and Defense Labs
Attack and Defense Labs
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - 学剑学诗两不成

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