您的位置:程序门 -> vb -> vba



我是做delphi開發的。來問個vba的問題,怎麼把vb代碼放到office 的vba里執行?里面vb的代碼和需求!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


我是做delphi開發的。來問個vba的問題,怎麼把vb代碼放到office 的vba里執行?里面vb的代碼和需求![已结贴,结贴人:maming2003]
发表于:2007-12-24 14:34:30 楼主
我怎樣才可以把vb程式移植到office   vba(office控件中沒有timer控件﹐但我已經下載了一個)中﹐有一個紅色的對象不對﹐但我不知道該用什么
 
程序说明:   利用一个计时器、一个标签框和二个命令按钮制作一个动态秒表,如图1所示。单击“开始”命令按钮,秒表开始计时,单击“结束”命令按钮,秒表结束计时,并在标签框显示运行时间,如“运行了0小时2分10秒”。(假设对象的属性都在程序代码中设定)
 
 
程序代码如下:
       
vb.net code
dim x as long dim h as integer, m as integer, s as integer private sub form_load() form1.caption = "动态秒表(小时:分:秒)" command1.caption = "开始[&s]" command2.caption = "结束[&e]" label1.alignment = 2 '居中对齐 label1.caption = " 0: 0: 0" timer1.interval =1000 timer1.enabled = false x = 0 end sub private sub command1_click() timer1.enabled = true end sub private sub command2_click() timer1.enabled = false x =0 label1.caption = "运行了"+str(h)+"小时"+str(m)+""+str(s)+"" end sub private sub timer1_timer() x = x + 1 h = x \ 3600 m = (x mod 3600) \ 60 s =x mod 60 label1.caption = str(h) + ":" + str(m) + ":" + str(s) end sub
发表于:2007-12-24 19:30:531楼 得分:100
dim   x   as   long
dim   h   as   long,   m   as   long,   s   as   long

...................................

private   sub   timer1_timer()'每1秒钟触发一次
              dim   cjl   as   long
              x   =   x   +   1
              h=(x/3600)'取得小时                  
              cjl=(x   mod   3600)
              m=(cjl/60)'取得分钟                
              s=(cjl   mod   60)'取得秒种
              label1.caption   =   iif(len(trim(str(h))) <2,"0"&trim(str(h)),trim(str(h)))   +   ":"   +   iif(len(trim(str(m))) <2,"0"&trim(str(m)),trim(str(m)))   +   ":"   +   iif(len(trim(str(s))) <2,"0"&trim(str(s)),trim(str(s)))
end   sub
 
发表于:2007-12-25 16:42:422楼 得分:0
对不起楼主,今天下午发了之后,我总觉得有问题,上机一试,果然如此。得了分我也不踏实啊。正确的应该是:  
option       explicit  

dim       x       as       long  
dim       h       as       long,       m       as       long,       s       as       long  
private       sub       form_load()  
                        form1.startupposition       =       2  
                        form1.caption       =       "动态秒表(小时:分:秒)"  
                        command1.caption       =       "开始[&s]"  
                        command2.caption       =       "结束[&e]"  
                        label1.alignment       =       2                                                       '居中对齐  
                        label1.caption       =       "00:00:00"  
                        timer1.interval       =       1000  
                        timer1.enabled       =       false  
                        label1.backcolor       =       &h0&  
                        label1.forecolor       =       &hff00&  
                        label1.font.name       =       "arial       rounded       mt       bold"  
                        label1.alignment       =       2  
                        x       =       0  
end       sub  
private       sub       command1_click()  
                        timer1.enabled       =       true  
                        label1.font.size       =       24  
end       sub  
private       sub       command2_click()  
                        timer1.enabled       =       false  
                        label1.font.size       =       14  
                        x       =       0  
                        label1.caption       =       "运行了"       +       str(h)       +       "小时"       +       str(m)       +       "分"       +       str(s)       +       "秒"  
end       sub  
private       sub       timer1_timer()                                                   '每1秒钟触发一次  
                                dim       cjlh       as       long,       cjlm       as       long  
                                x       =       x       +       1  
                                cjlh       =       int(x       /       3600)  
                                h       =       cjlh       '取得小时  
                                cjlm       =       int((x       mod       3600)       /       60)       '关键在这里,用int取整,否则每30秒进1,有点奇怪  
                                m       =       cjlm       '取得分钟  
                                s       =       ((x       mod       3600)       mod       60)       '取得秒种  
                                label1.caption       =       iif(len(trim(str(h)))       <       2,       "0"       &       trim(str(h)),       trim(str(h)))       +       ":"       +       iif(len(trim(str(m)))       <       2,       "0"       &       trim(str(m)),       trim(str(m)))       +       ":"       +       iif(len(trim(str(s)))       <       2,       "0"       &       trim(str(s)),       trim(str(s)))  
end       sub  

我改进了一下,用了毫秒级,动得比较快,下载地址:http://download.csdn.net/source/316696


快速检索

最新资讯
热门点击