永发信息网

VB 命令按钮问题

答案:2  悬赏:60  手机版
解决时间 2021-05-17 04:04

我用代码建立了一个命令按钮,然后在在命令按钮里写代码。但是命令按钮不起作用

代码如下:

Private Sub command1_Click()
'添加文本
txt_top = txt_top + 600
txt_left = 200
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 400, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
End Sub
Private Sub Form_Load()

With Me
    .Width = 15000
    .Height = 6000
End With
txt_i = 1
cmd_i = 1
lab_i = 1
txt_left = 200
txt_top = 500
'添加文本
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 400, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
'添加命令按钮
Call addcmd(Me, 500, txt_left, 700, 300, 0, "插入", CStr("command" & cmd_i))
Call addcmd(Me, 1100, txt_left, 700, 300, 0, "删除", CStr("command" & cmd_i))
'添加标签
txt_left = 200
Call addlab(Me, txt_top - 400, txt_left, 700, 500, 200, "边坡点名称", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left - 100, 500 + 600, 300, 200, "边坡点桩号", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "边坡点高程H", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "切线长T", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 500, 300, 200, "半径R", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 400, 300, 200, "矢距E", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "坡度I(%)", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 800, 300, 200, "坡度角", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500, 300, 200, "边坡角", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 800, 300, 200, "名称", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 600, 300, 200, "起点", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 600, 300, 200, "终点", CStr("label" & lab_i))

End Sub
模块:

Dim cmd As CommandButton
Public cmd_i As Integer
Function addcmd(c_frm As Form, c_top As Double, c_left As Double, c_width As Double, _
                c_height As Double, c_n As Single, c_caption, c_name As String)
Set cmd = c_frm.Controls.Add("vb.commandbutton", c_name)

With cmd
   .Top = c_top
   .Left = c_left
   .Width = c_width
   .Height = c_height
   .Caption = c_caption
   .Visible = True
End With
cmd_i = cmd_i + 1

End Function

最佳答案
command1_Click 与 Form_Load 是两个过程,要想在这两个过程里相同变量的值保持一致,你需要对这几个变量进行声明。由你的这个程序看来需要进行声明的变量有txt_top和txt_i,你可以在窗体代码窗口的“通用 声明”里输入:Dim txt_top As Double, txt_i 这样程序就会按你的思路运行了。
全部回答
命令按钮的哪个属性的值?caption 是上面的字,vlaue=1相当于按下,不知道你问题问什么。 
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
奇门忽略高好还是伤害高好呢?
英语改错和语文改错从什么方面入手,求点偏方
什么东西女人爱吃男人爱用
哪个网店有玩摇滚用的超大眼镜呢?
勒夫世界杯穿的针织衫详细情况是怎么样的,翻
潜江市潜江德坤物流地址在哪,我要去那里
为什么我的麦克风没声音,重装了系统也没用。
85龙龟体力成长问题
税率是什么,求财务销售利税率情况说明范本 5
财付通农行卡怎么开
龙沙区齐齐哈尔胤祥黄焖鸡米饭(南苑一中店)怎
3000左右的笔记本电脑那款好?
求天龙八部588财富卡!
为什么TA对我不理不睬的?
怎么才能让女友更高兴?
推荐资讯
描写燕子外形的句子
饮水机安全提示标语,求饮水机旁的卫生提示标
欧米茄好还是劳力士好,万国手表机芯好还是欧
为什么宽带老掉线啊
有没有人知道剑侠贰外传血人怎么用比较狠啊
为什么我的QQ牧场老是出现这个?
东莞水叮当水上乐园是不是倒闭了
飞信怎么激活啊,急
急求TXT版《皇图梦》的下载地址或者直接发给
常德至上海列车车次表
千里江陵什么意思
滨州哪个CF战队最牛
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?