请问VB中如何把一个数组直接赋给另一个数组?

jiangsu19747 2009-07-02 11:05:51
加精
比如 dim A() as integer, B() as integer
当A有了值后,怎么才能把A直接赋给B呢 ,我不想一个一个的循环赋值

另外还想问一下是否可以把一个记录集直接赋给另一个记录集?
dim RS1 AS new adodb.recordset
dim RS2 AS new adodb.recordset
可以直接 rs1=rs2吗?
...全文
6314 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
XuNuoChengZai 2012-07-23
  • 打赏
  • 举报
回复
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Dim bytes As Long
Dim intSrc(1 To 6000000) As Integer
Dim intDest(1 To 6000000) As Integer

bytes = (UBound(intSrc) - LBound(intSrc) + 1) * Len(intSrc(LBound(intSrc)))

CopyMemory intDest(LBound(intDest)), intSrc(LBound(intSrc)), bytes
End Sub


顶这个,学习了谢谢高手们
三断笛 2009-12-22
  • 打赏
  • 举报
回复
[Quote=引用 38 楼 m60a1 的回复:]
WINFORM程序VB比C#快???


LZ试过?》
[/Quote]
VB比Java快
terrywolf 2009-07-05
  • 打赏
  • 举报
回复
关注一下!
jiangsu19747 2009-07-04
  • 打赏
  • 举报
回复
呵呵,没试过,看网上一篇贴子里这么说的
m60a1 2009-07-04
  • 打赏
  • 举报
回复
WINFORM程序VB比C#快???


LZ试过?》
ltl164198 2009-07-04
  • 打赏
  • 举报
回复
数组是不可以赋值的,动态数组有是另外一回事,在c++里叫向量,已脱离了你的原意,如果非得到一的副本,同意上面的用 copymemery,但小数组不宜用之,消耗大
jiangsu19747 2009-07-04
  • 打赏
  • 举报
回复
谢谢大家的回复。这么多热心人,我还担心现在没什么人用VB了呢。前天另一公司老板跟我说事情,问我用什么编程,我知他们用C#,我说我们用VB呢,然后故意添了一句,WINFORM程序VB比C#快,生怕人家看不起。
舉杯邀明月 2009-07-03
  • 打赏
  • 举报
回复
对动态数组可以直接整体赋值。
david201314 2009-07-03
  • 打赏
  • 举报
回复
ding
shawls 2009-07-03
  • 打赏
  • 举报
回复
使用CopyMemory函数,将指向修改一下就可以。
东方之珠 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 of123 的回复:]
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Dim bytes As Long
Dim intSrc(1 To 6000000) As Integer
Dim intDest(1 To 6000000) As Integer

bytes = (UBound(intSrc) - LBound(intSrc) + 1) * Len(intSrc(LBound(intSrc)))

CopyMemory intDest(LBound(intDest)), intSrc(LBound(intSrc)), bytes
End Sub
[/Quote]

顶这个!
东方之珠 2009-07-03
  • 打赏
  • 举报
回复
只要获取数组的地址就可以了.
lllsui 2009-07-03
  • 打赏
  • 举报
回复
o
ndtafje 2009-07-03
  • 打赏
  • 举报
回复
gen jing
joy365leo 2009-07-03
  • 打赏
  • 举报
回复
upup
joy365leo 2009-07-03
  • 打赏
  • 举报
回复
thaknyou somuch
xslqingfeng 2009-07-03
  • 打赏
  • 举报
回复
UP
of123 2009-07-02
  • 打赏
  • 举报
回复
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Dim bytes As Long
Dim intSrc(1 To 6000000) As Integer
Dim intDest(1 To 6000000) As Integer

bytes = (UBound(intSrc) - LBound(intSrc) + 1) * Len(intSrc(LBound(intSrc)))

CopyMemory intDest(LBound(intDest)), intSrc(LBound(intSrc)), bytes
End Sub
白发程序猿 2009-07-02
  • 打赏
  • 举报
回复
数据集可以用clone方法
嗷嗷叫的老马 2009-07-02
  • 打赏
  • 举报
回复
数组可以直接赋值,不过目标数组必须是动态数组:

http://www.m5home.com/blog/article.asp?id=262
加载更多回复(22)
Public Class Form1 Inherits System.Windows.Forms.Form Public Filename As String = "引用英汉词典.txt" '定义连接数据的文本TXT Public Myword(6500, 1) As String '定义二维数组 Public words As Integer = 0 '记录连接数据的文本TXT 单词个数  Private Sub Form1_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim main As String Dim chang As Integer ' 单词长度 Dim i As Integer = 0 '数组的开始位置 Dim n As String '读取相应的单词 Dim m As String '读取单词的文解释 Dim stringchang As Integer '计算单词后字符串的长度 TextBox1.Text = "" TextBox2.Text = "" FileOpen("英汉小辞典") :|bin:|引用英汉小辞典) '打开文件,相对路径 Do While Not EOF(1) main = LineInput(1) chang = InStr(main, " ") '查找空格的位子。 n = Microsoft.VisualBasic.Left(main, chang - 1) '截取空格字符:单词 Myword(i, 0) = n '保存新的单词 ListBox1.Items.Add(n) stringchang = Len(main) - chang m = Trim(Microsoft.VisualBasic.Right(main, stringchang)) '剩下的字符串赋给变量值m Myword(i, 1) = m '保存文的翻译(解释) i = i + 1 Loop words = i FileClose(1) End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Try TextBox1.Text = Myword(ListBox1.SelectedIndex, 0) TextBox2.Text = Trim(Myword(ListBox1.SelectedIndex, 1)) Catch ex As Exception Exit Sub End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer = -1 '以数组来进行起始查询 If TextBox1.Text = "" Then MessageBox.Show("不能输入空字符,请重新输入") TextBox2.Text = "" TextBox1.Focus() Exit Sub Else For i = i + 1 To words If LCase(TextBox1.Text) = LCase(Myword(i, 0)) Then TextBox2.Text = Trim(Myword(i, 1)) Exit Sub End If Next MessageBox.Show("不存在您所需要的单词,你需要添加一个新的") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer = 0 Dim k As Integer Dim EnterWords, ch As String AB: EnterWords = InputBox("请输入想要添加的单词", "添加一个新的单词") '先输入单词 If EnterWords = "" Then MessageBox.Show("必须要输入单词") GoTo AB End If AC: ch = InputBox("需要您输入文意思", "添加一个新的文意思") '输入文意思 If ch = "" Then MessageBox.Show("请输入文翻译") GoTo AC End If Do While LCase(Myword(i, 0)) < LCase(EnterWords) i = i + 1 If words = i Then '找完数据库再进行添加 Myword(i, 0) = EnterWords '把新添加的单词赋给I位置 Myword(i, 1) = ch '把新添加的单词(文意思)赋给I的位置 words = words + 1 FileOpen(1, Filename, OpenMode.Output) '打开一个文件 For i = 0 To words - 1 PrintLine(1, Myword(i, 0) & " " & Myword(i, 1)) Next ListBox1.Items.Clear() FileClose(1) '关闭文件 ListBox1.Items.Clear() Form1_load(sender, e) MessageBox.Show("添加成功") Exit Sub End If Loop If LCase(Myword(i, 0)) = LCase(EnterWords) Then MessageBox.Show("词库里已经存在这个单词了") Exit Sub Else For k = words To i + 1 Step -1 Myword(k + 1, 0) = Myword(k, 0) Myword(k + 1, 1) = Myword(k, 1) Next k Myword(i, 0) = EnterWords '把添加的单词赋给I的位置 Myword(i, 1) = ch '把添加的单词(文意思)赋给I的位置 words = words + 1 FileOpen(1, Filename, OpenMode.Output) '打开一个文件 For i = 0 To words - 1 PrintLine(1, Myword(i, 0) & " " & Myword(i, 1)) '数组里的单词写入文本文件(TXT) Next FileClose(1) '文件将会关闭 ListBox1.Items.Clear() Form1_load(sender, e) MessageBox.Show("添加成功") Exit Sub End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim ch As String Dim j As Integer If -1 = ListBox1.SelectedIndex Then MsgBox("请选择单词再进行修改") ListBox1.Focus() Exit Sub End If AD: ch = InputBox("请输入修改单词的文意思", "修改单词", Trim(Myword(ListBox1.SelectedIndex, 1))) If ch = "" Then MessageBox.Show("不能删除以前的文解释") GoTo AD End If Myword(ListBox1.SelectedIndex, 1) = ch FileOpen(1, Filename, OpenMode.Output) For j = 0 To words - 1 PrintLine(1, Myword(j, 0) & " " & Myword(j, 1)) Next FileClose(1) '文件关闭 ListBox1.Items.Clear() Form1_Load(sender, e) End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim i, j, k As Integer k = MsgBox("您确定是否删除吗?", MsgBoxStyle.YesNo) If 6 = k Then For i = ListBox1.SelectedIndex To words Myword(i, 0) = Myword(i + 1, 0) Myword(i, 1) = Myword(i + 1, 1) Next words = words - 1 FileOpen(1, Filename, OpenMode.Output) ' 打开文件 For j = 0 To words - 1 PrintLine(1, Myword(j, 0) & " " & Myword(j, 1)) Next FileClose(1) '文件关闭 MsgBox("单词已经删除了") ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) ListBox1.Refresh() TextBox1.Text = "" TextBox2.Text = "" Exit Sub Else Exit Sub End If End Sub End Class

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧