FastFieldSolvers Forum
FastFieldSolvers Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 FastFieldSolvers
 FasterCap and FastCap2
 Callback in Excel Macro

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Antispam question: What do MOONwalk and MOONdance have in common?
Answer:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON

 
   

T O P I C    R E V I E W
IanRedman Posted - Jan 26 2012 : 17:59:50
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
1   L A T E S T    R E P L I E S    (Newest First)
Enrico Posted - Feb 07 2012 : 16:34:26
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



FastFieldSolvers Forum © 2020 FastFieldSolvers S.R.L. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.06