几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 09:10 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how do i slow a macro down

how do i slow a macro down
hello all.
i have a macro that loops through all the segments in a sketch using
intitemcount = 0
do while not strsegid(intitemcount) = ""
.................
loop
this works fine when i step the macro through using f8 but when i run the macro properly the macro alarms out with a "subscript out range" error. if i put a macro break in at "intitemcount = 0", then resume the macro, every thing works fine. it appears to me that the only explanation is vba is running too fast for solidworks to keep up (though i am sure that this is fanciful!). what can i do to get my macro running properly? is there a command in vba to force the process to wait for x milliseconds? has anyone come up against this before?
many thanks
bob
robert luck
production engineer ~ cam programmer
for icount = 1 to 1000
next icount
this doesn't have a specific time it takes to run this though, so it may not work as expected.
i haven't tried this, but found it through by googling "vba delay function"
method 2: use an api call to suspend the execution of word
use an api call to suspend the execution of word for a fixed amount of time. the kernel32 contains a function that pauses a program's execution for a specified amount of time, specified in milliseconds.
to use the function, it must first be declared in the general declarations section of the module in which it will be used:
declare sub sleep lib "kernel32" alias "sleep" (byval dwmilliseconds as long)
use the following syntax to call the sleep function:
sub sleep() sleep 1000 'implements a 1 second delay end sub
drc inc.
minneapolis, mn
.designreadycontrols.com
sw2007 sp5.0
core2 quad
3gb ram
xp pro sp2
ati firegl v3600
i think "subscript out of range" means that you are exceding the limits of the datatype of your variable.
are you sure you ever exit your loop? or try changing intitemcount to a long instead of an interger.
unless you step through your process 32k times you would never see this.
if im wrong here is a timer example
from the solidworks vba help:
timer function example
this example uses the timer function to pause the application. the example also uses doevents to yield to other processes during the pause.
dim pausetime, start, finish, totaltime
if (msgbox("press yes to pause for 5 seconds", 4)) = vbyes then
pausetime = 5 ' set duration.
start = timer ' set start time.
do while timer < start + pausetime
doevents ' yield to other processes.
loop
finish = timer ' set end time.
totaltime = finish - start ' calculate total time.
msgbox "paused for " & totaltime & " seconds"
else
end
end if
thank you for your guidance, i shall be trying the methods you descride over the weekend. i think dominic might be on the money though as after i posted my plea for help i tried erasing the array immediately before exiting the macro and so far it has worked (but i have only tested it about 10 times and with sketches up to 150 segments). but that raises another question in that do arrays exist in memory after a macro closes? i thought that for simple software like vba macros all objects created by the macro were destroyed on exit.
anyway, my thanks to you all again for helping an apprentice macro-maker.
bob luck
robert luck
production engineer ~ cam programmer
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】copy an existent sketch into a macro yang686526 SolidWorks二次开发 0 2009-04-12 08:31 PM


所有的时间均为北京时间。 现在的时间是 05:11 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多