There are some ways to create and access Unicode files using VBA. The most straightforward way is to use the Microsoft Scripting Runtime library. The two following ways may be used to open a file for write operations: 'the scripting lib way Dim fs As New FileSystemObject, txt As TextStream Dim pth As String : pth = "d:\data.txt" Set txt = fs.CreateTextFile(pth, True, True) ''alternative way to open the textfile 'Set txt = fs.OpenTextFile(pth, ForWriting, True, TristateTrue) 'to write simply write the following in Unicode txt.WriteLine "test text" If we want to avoid using the Microsoft Scripting Runtime, we may use the following code; we access the output file in binary mode and we manually convert text to Unicode: 'the manual way Open pth For Binary Access Write As #1 Dim buffer() as Byte : buffer = "test text" Put #1, , buffer Close #1
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...
Comments