<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Repeat function in AutoCAD VBA in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618548#M3078</link>
    <description>&lt;P&gt;Hi Mr.Yuan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using timer command but what it actually does is to count the amount of time that the user responded instead of counting how many seconds have passed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm looking for is something to this effect, if it's written in Windows batch file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;echo off&lt;/P&gt;&lt;P&gt;:loop&lt;/P&gt;&lt;P&gt;echo Hi, how are you?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;TIMEOUT /T 5 /NOBREAK&lt;BR /&gt;echo off&lt;BR /&gt;goto loop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The objective is to check with MySQL on a fixed interval to see if there are new jobs given in the database table (of course I don't mean "hi, how are you", but I intended to run accoreconsole /s abc.scr -en US).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you correct me if you see anything wrong in my understanding?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;KH&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 13:02:11 GMT</pubDate>
    <dc:creator>kh.teow</dc:creator>
    <dc:date>2021-09-13T13:02:11Z</dc:date>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618408#M3076</link>
      <description>&lt;DIV class="lia-message-subject lia-component-message-view-widget-subject"&gt;&lt;DIV class="MessageSubject"&gt;&lt;SPAN style="font-family: inherit; color: #3c3c3c;"&gt;Hi,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've written a VBA code to connect to MySQL to get information to do some calculation and drawing, and then export the results back to MySQL again.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I would like the code to run automatically on a fixed time interval without human intervention but was unsuccessful. I have tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Enabled the Microsoft Excel Object Library in Reference so that I could use the Excel command "&lt;SPAN&gt;Application.OnTime Now + TimeValue("00:00:01")" ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Using AutoCAD Core Console with a script file that include the commands -vbaload and -vbarun, but the command returned "Unknown command "-vbaload"". My intention is to use accoreconsole.exe to run the script file and use&amp;nbsp; a Windows batch file to run an infinity loop on the accoreconsole.exe every 5 minutes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any workable way out there which is easily implemented and maintained?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;KH Teow&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 13 Sep 2021 11:52:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618408#M3076</guid>
      <dc:creator>kh.teow</dc:creator>
      <dc:date>2021-09-13T11:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618518#M3077</link>
      <description>&lt;P&gt;Well, AutoCAD core console does not support VBA, so you cannot use it with VBA code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using another app's feature (Excel's Application.OnTime, as you mentioned) is bad idea, to say the least.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have to use VBA for certain reason, VBA has built-in function - Timer, which you use to record a time period elapsed and run particular code at certain interval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 12:44:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618518#M3077</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-09-13T12:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618548#M3078</link>
      <description>&lt;P&gt;Hi Mr.Yuan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using timer command but what it actually does is to count the amount of time that the user responded instead of counting how many seconds have passed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm looking for is something to this effect, if it's written in Windows batch file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;echo off&lt;/P&gt;&lt;P&gt;:loop&lt;/P&gt;&lt;P&gt;echo Hi, how are you?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;TIMEOUT /T 5 /NOBREAK&lt;BR /&gt;echo off&lt;BR /&gt;goto loop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The objective is to check with MySQL on a fixed interval to see if there are new jobs given in the database table (of course I don't mean "hi, how are you", but I intended to run accoreconsole /s abc.scr -en US).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you correct me if you see anything wrong in my understanding?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;KH&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 13:02:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618548#M3078</guid>
      <dc:creator>kh.teow</dc:creator>
      <dc:date>2021-09-13T13:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618756#M3079</link>
      <description>&lt;P&gt;Firstly, I do not know what you need AutoCAD to do, but assume it would process one or more drawings every time a new job item is detected in your database. I'd think using AutoCAD core console would be better choice with proper notification mechanism, likely a service time of app. But that would be out of topic of this forum and beyond the question you asked here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless what exactly your business process, VBA's Timer CAN provide a way to execute VBA code in a given interval. You just need a bit programming (we are programmer here, eh?). Following code shows how to do in VBA:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Option Explicit

Private Const PAUSE As Integer = 5 '' Seconds for Timer to pause
Private Const INTERVAL As Long = 20 '' 30 seconds

Private startTime As Date
Private start As Integer



Public Sub DoWork()
    
    Dim go As Boolean
    Dim currentTime As Date
    Dim timeDiff As Long
    
    startTime = Now
    
    Do
        go = True

        start = Timer
        Do While Timer &amp;lt; start + PAUSE
            DoEvents
        Loop

        currentTime = Now
        Debug.Print currentTime
        
        timeDiff = DateDiff("s", startTime, currentTime)
        Debug.Print timeDiff
        If timeDiff &amp;gt; INTERVAL Then
            '' This is where the work is done in every a while
            '' determined by const INTERVAL, I set it for 20 seconds
            '' you can set it to 3000 (5 min)
            go = DoSomething
            If go Then startTime = Now
        End If
    
    Loop While go
    
    MsgBox "Repeating work has been cancelled!"
    
End Sub

Private Function DoSomething() As Boolean
    
    Dim msg As String
    msg = "Do work here... done." &amp;amp; vbCr &amp;amp; vbCr &amp;amp; _
    "Do you want to it again?"
    
    If MsgBox(msg, vbYesNo + vbQuestion) = vbYes Then
        DoSomething = True
    Else
        DoSomething = False
    End If
    
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not think using VBA with its Timer is a very good solution to your&amp;nbsp; business need, but again, the code here is only meant to show how to use Timer to run a piece of code with given interval. Run the code and watch the immediate window for the output from Debug.Print, you can have clear sense how the code works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:19:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618756#M3079</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-09-13T14:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618824#M3080</link>
      <description>&lt;P&gt;Thanks Mr.Yuan for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:40:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10618824#M3080</guid>
      <dc:creator>kh.teow</dc:creator>
      <dc:date>2021-09-13T14:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat function in AutoCAD VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10621778#M3081</link>
      <description>&lt;P&gt;Hi Mr.Yuan,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To be honest, I'm not really a programmer but a mechanical engineer who has had a term of training in coding Turbo Pascel some 25 years back. The line that saved the day was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Private StartTime as date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;from here, I could just manipulate the time interval via the date function. Last time never paid attention to any date function as most of the coding was done for non-business related process, and date was rarely used as a reference. I know it must have looked stupid on my side to have missed out such a basic thing but then again, what can I say? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you help!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 15:30:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/re-repeat-function-in-autocad-vba/m-p/10621778#M3081</guid>
      <dc:creator>kh.teow</dc:creator>
      <dc:date>2021-09-14T15:30:52Z</dc:date>
    </item>
  </channel>
</rss>

