明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1663|回复: 0

VB和VBA代码移植问题

[复制链接]
发表于 2005-8-22 10:43:00 | 显示全部楼层 |阅读模式

在VB中加一个flexgrid,text,label,combox控件 代码可以正常运行,但是当在VBA环境下运行以下代码的时候会提示错误,请大家帮我看看,看究竟是什么原因?


Option Explicit

Private Sub Combo1_Change()

End Sub

Private Sub Combo1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Combo1.Visible = False
MSFlexGrid1.SetFocus
End Sub

Private Sub Combo1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim i As Integer, bSame As Boolean
If KeyAscii = vbKeyEscape Then
    Combo1.Visible = False
    MSFlexGrid1.SetFocus
    Exit Sub
End If
If KeyAscii = vbKeyReturn Then
    MSFlexGrid1.text = Combo1.text
    Combo1.Visible = False
    MSFlexGrid1.SetFocus
    With Combo1
        bSame = False
        For i = 0 To .ListCount
            If .text = .List(i) Then bSame = True
        Next i
        If Not bSame Then .AddItem .text
    End With
End If

End Sub

Private Sub MSFlexGrid1_Click()
Dim c As Integer, r As Integer
With MSFlexGrid1
    c = .Col: r = .Row
    If r <= 2 Then
       
        Text1.Left = .Left + .ColPos(c)
        Text1.Top = .Top + .RowPos(r)
        Text1.width = .ColWidth(c)
        Text1.height = .RowHeight(r)
        Text1 = .text
        Text1.Visible = True
        Text1.SetFocus
    Else
        Combo1.Left = .Left + .ColPos(c)
        Combo1.Top = .Top + .RowPos(r)
        Combo1.width = .ColWidth(c)
        Combo1.text = .text
        Combo1.Visible = True
        Combo1.SetFocus
    End If
End With


End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
    Call MSFlexGrid1_Click
End If
End Sub

Private Sub Text1_Change()

End Sub

Private Sub Text1_Exit(ByVal Cancel As MSForms.ReturnBoolean)


MSFlexGrid1.SetFocus
Text1.Visible = False

End Sub

Private Sub Text1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyEscape Then
    Text1.Visible = False
    MSFlexGrid1.SetFocus
    Exit Sub
End If
If KeyAscii = vbKeyReturn Then
    MSFlexGrid1.text = Text1.text
    Text1.Visible = False
    MSFlexGrid1.SetFocus
End If
End Sub

Private Sub UserForm_Initialize()
Dim i As Integer
With MSFlexGrid1
    .Cols = 5
    .Rows = 5
    For i = 0 To 4
        .RowHeight(i) = 300
    Next i
End With
For i = 1 To 10
    Combo1.AddItem i
Next i
Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." & vbCr & _
                 "而第三、四行,会出现选择类表单(ComboBox)..." & vbCr & _
                 "输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," & vbCr & _
                 "而按下Esc键则取消输入..."
MSFlexGrid1.SetFocus
Combo1.Visible = False
Text1.Visible = False
End Sub

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 10:40 , Processed in 0.174680 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表