请问dim xx as new 类 后

yyyrrr51 2009-07-02 10:38:44

dim xx(5) as new Bcc
dim aa(5) as new Bcc
...
...
set aa(0)=new xx(0) '将xx(1).bcc赋值给aa(1)
可是这一句为什么是错误呢?说缺少:语句结束!
...全文
74 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
神马都能聊 2009-07-02
  • 打赏
  • 举报
回复
楼主的问题应该用CopyMemory或Clone
jhone99 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yyyrrr51 的回复:]
google过了,好像似乎VB里没办法复制类实例的
[/Quote]

xx(0)付值的同时aa(0)也付值
chenyanm 2009-07-02
  • 打赏
  • 举报
回复
set aa(0)=xx(0)
把new去掉
yyyrrr51 2009-07-02
  • 打赏
  • 举报
回复
google过了,好像似乎VB里没办法复制类实例的
yyyrrr51 2009-07-02
  • 打赏
  • 举报
回复
但是set aa(0)=xx(0)后,xx(0)的值改变,以后的aa(0)的值也改变
我想将xx(0)的值复制到aa(0)中,而不是将aa(0)引用xx(0)
jhone99 2009-07-02
  • 打赏
  • 举报
回复
set aa(0)=xx(0)
mhm0517 2009-07-02
  • 打赏
  • 举报
回复
set aa(0)= xx(0) '将xx(1).bcc赋值给aa(1)

'New 表示建立一个实例化.此关键字后面一般根一个类.

而XX(0)就已是一个实类.此处是赋值.因此不要New
舉杯邀明月 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yyyrrr51 的回复:]
但是set aa(0)=xx(0)后,xx(0)的值改变,以后的aa(0)的值也改变
............
[/Quote]

你的意思似乎要任何时候: aa(0) ≡ xx(0)

那你用 aa(0) 之类的岂不是多此一举?
Tiger_Zhao 2009-07-02
  • 打赏
  • 举报
回复
需要类添加 Clone() 函数
set aa(0)= xx(0).Clone()
用VB.NET做的小游戏--打地鼠 Public Class Form1 Inherits System.Windows.Forms.Form Dim pic As New PictureBox Dim goal As Integer Dim i As Integer Dim j As Integer Dim xx1() As Integer = {135, 277, 417} Dim xx2() As Integer = {157, 367} Dim xx3() As Integer = {32, 251, 482} Dim timer As Double = 1 Dim count As Integer '计时器跳动次数 Dim ifclick As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Text = "小游戏" Me.Size = New Size(650, 465) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Interval = 600 Timer1.Enabled = True Button2.Visible = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If Button2.Text = "暂停" Then Button2.Text = "继续" Timer1.Enabled = False PictureBox1.Enabled = False ElseIf Button2.Text = "继续" Then Button2.Text = "暂停" Timer1.Enabled = True PictureBox1.Enabled = True End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ifclick = False PictureBox1.Enabled = True If timer = 0 Then Timer1.Enabled = False MsgBox("游戏结束,您的得分:" + goal.ToString) Button3.Visible = False Exit Sub End If addpic() timer = 10 - count * 0.5
一个可以显示历史的菜单 Option Explicit Dim main As New main_frm Public max_index As Integer Public myindex As Integer Private Sub close_Click() On Error Resume Next '循环语句 For Each main In Forms If main.MDIChild = True Then Unload main End If Next Dim FNum As Integer Dim strfilename As String Dim i As Integer FNum = FreeFile strfilename = App.Path & "\cdxx.ini" If Dir(strfilename) <> "" Then Kill strfilename Open strfilename For Output As #FNum For i = 1 To mnufilelist.Count - 1 Print #FNum, mnufilelist(i).Caption Next Close #FNum Exit Sub End Sub Private Sub MDIForm_Load() Dim file As Long Dim mystring As String Dim s As String Dim strfilename As String strfilename = App.Path & "\cdxx.ini" file = FreeFile() On Error Resume Next Open strfilename For Input As #file '打开文件菜单列表 Do While Not EOF(file) Line Input #file, mystring If mystring <> "" Then max_index = max_index + 1 Load mnufilelist(max_index) mnufilelist(max_index).Caption = mystring mnufilelist(max_index).Visible = True End If Loop Close #file '关闭文件菜单列表 End Sub Private Sub MDIForm_Unload(Cancel As Integer) close_Click End Sub Private Sub mnufilelist_Click(Index As Integer) If mnufilelist(Index).Caption <> "" Then Static i As Integer If i < 1 Then i = 1 main_frm.Visible = False Dim main As New main_frm main.Caption = mnufilelist(Index).Caption i = i + 1 main.Picture = LoadPicture(mnufilelist(Index).Caption) main.Show End If End Sub Private Sub open_Click() '打开带图形的窗体 CommonDialog1.Filter = "所有图形文件" & "|*.jpg; *.bmp ; *.ico ;*.gif;*.cur" CommonDialog1.ShowOpen Static i As Integer If i < 1 Then i = 1 main_frm.Visible = False Dim main As New main_frm main.Caption = CommonDialog1.FileName i = i + 1 main.Picture = LoadPicture(CommonDialog1.FileName) main.Show max_index = mnufilelist.Count Load mnufilelist(max_index) mnufilelist(max_index).Caption = CommonDialog1.FileName mnufilelist(max_index).Visible = True End Sub Private Sub exit_Click() close_Click End End Sub

7,785

社区成员

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

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