FastFieldSolvers Forum
FastFieldSolvers Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
 All Forums
 FastFieldSolvers
 FasterCap and FastCap2
 Callback in Excel Macro
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

IanRedman

2 Posts

Posted - Jan 26 2012 :  17:59:50  Show Profile  Reply with Quote
I've been playing about with fc_drive.xls and have discovered how to use Macros to pull the relevent capactiance data into excel so I can easily draw pretty graphs etc. However I'm new to macros and aren't sure how to use the call back feature (Which I assume will allow me to keep using excel whilst FasterCap is working).

Does anyone have a simple example I can see up get me started?

Thanks,

Ian

Enrico

550 Posts

Posted - Feb 07 2012 :  16:34:26  Show Profile  Reply with Quote
I think your request is not so standard, because you have to consider that being able to operate and modify an Excel sheet while a macro (Visual Basic application script) is running, and therefore potentially acting on the same sheet, is dangerous: what happens if both the you and the script are trying to modify the same cells?
In general, the result is not deterministic.

However, warned of the possible side effects, there is a simple way to achieve this result.

You don't need to use callbacks, since FasterCap and FastCap2 do not use callbacks to signal the end of their task. You have to poll the solver instead. You can, therefore, modify the core of the loop that waits for the solver to end its task, to allow the Windows OS to process other events. This can be done with the DoEvents function (you can check the Excel online help for an explanation on how this function works).

The modified code (taken from the FastCap2 Excel automation sample) is reported here below, where the changed part is highlighted in red.

Enrico



Sub FastCap_nonblocking()
' FastCap Automation example
' Enrico Di Lorenzo, 2004/04/15

Dim FastCap2
' Create FastCap object
Set FastCap2 = CreateObject("FastCap2.Document")

For i = 0 To 3
  ' Try to run FastCap
  ' Remark: the run path must be surrounded by quotas '"' to support
  ' also paths containing spaces (quotas in VisualBasic are escaped by
  ' doubling the symbol, i.e., "" )
  couldRun = FastCap2.Run("""" + ActiveWorkbook.Path + "\sphere" + CStr(i) + ".qui""")
  ' Wait for end of operation, using polling; could also use callback function
  startTime = Now
  Do While FastCap2.IsRunning = True
    DoEvents   'This will allow the OS to process events
  Loop
  ' retrieve capacitance matrix
  capacitance = FastCap2.GetCapacitance()
  Range("B" + CStr(i + 5)).Value = "Sphere" + CStr(i)
  Range("C" + CStr(i + 5)).Value = capacitance(0, 0)
Next

' Quit FastCap
FastCap2.Quit
' Destroy FastCap object
Set FastCap2 = Nothing

End Sub


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
FastFieldSolvers Forum © 2020 FastFieldSolvers S.R.L. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.06