There is a great way to call the Fortran intrinsic libraries from Visual Basic, without wrapping them to dynamic libraries. I have the Digital Fortran installed on my computer, so I found out one of the running DLLs which is the dforrt.dll and that contains the Fortran intrinsic libraries (which are used by the Digital compiler). I simply opened the DLL with the Depends program and I found out the name of the functions that are declared in the DLL file. Knowing that the tangent function is declared as DTAN in Fortran, I found out some functions and declared them in a Visual Basic module file like this: Public Declare Function DTAN# Lib "dforrt.dll" Alias "_FXDTAN" (x#) Public Declare Function DTAN5# Lib "dforrt.dll" Alias "_FXIDTAN" (x#) And here is a sample call: Const PI As Double = 3.14159265358979 'the tangent of PI/4 will return 1.0 Debug.Print DTAN(PI / 4) Of course the tangent function is an intrinsic one in Visual Basic. H...
It seems that are not any CopyTo and Sort functions in the Dictionary class that resides in the Systems.Collection.Generic namespace. The OrderBy extension method used by Linq is not very practical to me, because it does not return a dictionary object. Here is my extension method CopyTo, applicable to generic Dictionary objects, allowing to define a part of the dictionary: public static void CopyTo<T, V>(this Dictionary<T, V> source, Dictionary<T, V> target) { if (target == null) target = new Dictionary<T, V>(); foreach (KeyValuePair<T, V> entry in source) target.Add(entry.Key, entry.Value); } public static void CopyTo<T, V>(this Dictionary<T, V> source, Dictionary<T, V> target, int start) { if (target == null) target = new Dictionary<T, V>(); int iEntry = 0; foreach (KeyValuePair<T, V> entry in source) { if (iEntry++ >= start) target.Add(entry.Key, entry.Value); } } public static void CopyTo<T, V>(this Dicti...
Automation can really gives us the tools to do something very fast. The following code shows how to export all the modules in the current workbook to a destination folder. Public Sub ExportAll(targetPath as String) Dim xlApp As Excel.Application Dim xlWb As Excel.Workbook Dim VBComp As VBIDE.VBComponent ' Load workbook Set xlApp = Application 'xlApp.Visible = False Set xlWb = ActiveWorkbook 'xlApp.Workbooks.Open(sWorkbook) ' Loop through all files (components) in the workbook For Each VBComp In xlWb.VBProject.VBComponents ' Export the file If VBComp.Type = vbext_ct_StdModule Then _ VBComp.Export targetPath & VBComp.Name & ".bas" Next VBComp End Sub Two possible issues must be solved to correctly run this code. The first is to allow the code to access the VBA Object model programmatically. This can be done by correctly setting this from the Trust Center (from Excel Options). The second is to reference the Microsoft Visua...
Comments