+ /// Positions the position of the pointer to a specific location in the FileStream
+ ///
+ ///
+ ///
+ ///
+ public static long FSeek(ref FileStream oFileStream, int nBytesMoved)
+ {
+ return oFileStream.Seek(nBytesMoved,0);
+ }
+
+ ///
+ /// Positions the position of the pointer to a specific location in the FileStream.
+ /// This one receives a relative position as a third parameter
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static long FSeek(ref FileStream oFileStream, int nBytesMoved, int nRelativePosition)
+ {
+ if (nRelativePosition == 2)
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.End);
+ }
+ else if (nRelativePosition == 0)
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Begin);
+ }
+ else
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Current);
+ }
+ }
+
+ ///
+ /// Returns a string containing the last modification time for a file
+ ///
+ ///
+ ///
+ public static string FTime(string cFileName)
+ {
+ //Check if it exists
+ if(!System.IO.File.Exists(cFileName))
+ return "";
+
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the LastWriteTime farmatted as a string.
+ //Call the LastAccessTime to get the last read/write/copy time
+ return fi.LastWriteTime.ToShortTimeString();
+ }
+
+
+ ///
+ /// Receives a filename as a parameter and returns a fully qualified path for the filename/path.
+ /// (Please note that the last two parameters nMsDosPath and cFileName2 are not implemented.)
+ ///
+ /// Example:
+ /// FullPath("files.cs"); //returns "c:\projects\VisualFoxProCommands\bin\Debug\files.cs"
+ ///
+ ///
+ ///
+ ///
+ public static string FullPath(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the FullName property
+ return fi.FullName;
+ }
+
+ ///
+ /// Receives a FileStream and string as parameters and writes a string to a FileStream
+ ///
+ ///
+ ///
+ ///
+ public static int FWrite(ref FileStream oFileStream, string cString)
+ {
+ return VFPToolkit.files.FWrite(ref oFileStream, cString, cString.Length);
+ }
+ public static int FWrite(ref FileStream oFileStream, string cString, int nCharactersWritten)
+ {
+ int i;
+ //Move the position to the end of the file
+ //oFileStream.Position = oFileStream.Length;
+
+ if(cString.Length < nCharactersWritten)
+ nCharactersWritten = cString.Length;
+
+ //Convert the string into an array of bytes
+ byte[] aBytes = new byte[nCharactersWritten];
+ for (i= 0; i < nCharactersWritten ; i++)
+ {
+ aBytes[i] = (byte)cString[i];
+ }
+
+ //Call the write method of the FileStream
+ oFileStream.Write(aBytes, 0, nCharactersWritten);
+ return cString.Length;
+ }
+
+ ///
+ /// Returns the startup directory
+ ///
+ /// WinForms
+ ///
+ public static string Home()
+ {
+ return Application.StartupPath;
+ }
+
+
+ ///
+ /// Receives a path as a parameter and returns only the drive part
+ ///
+ /// Example:
+ /// JustPath("c:\\My Folders\\MyFile.txt"); //returns "c:"
+ ///
+ ///
+ ///
+ ///
+ public static string JustDrive(string cPath)
+ {
+ if(cPath.Trim().Length == 0)
+ return cPath.Trim();
+
+ string lcJustDrive = System.IO.Directory.GetDirectoryRoot(cPath);
+ lcJustDrive = strings.StrTran(lcJustDrive, "\\", "");
+ return lcJustDrive;
+ }
+
+ ///
+ /// Receives a FileName as a parameter and returns the extension of that file
+ ///
+ /// JustExt("c:\\My Folders\\MyFile.txt"); //returns ".txt"
+ ///
+ ///
+ ///
+ ///
+ public static string JustExt(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the extension of the file
+ return fi.Extension;
+ }
+
+ ///
+ /// Returns the only the file name with extension from a fully qualified path
+ ///
+ /// JustFName("c:\\My Folders\\MyFile.txt"); //returns "MyFile.txt"
+ ///
+ ///
+ ///
+ ///
+ public static string JustFName(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the file name
+ return fi.Name;
+ }
+
+ ///
+ /// Receives a path as a parameter and returns only the path part without the file name.
+ ///
+ /// Example:
+ /// JustPath("c:\\My Folders\\MyFile.txt"); //returns "c:\My Folders"
+ ///
+ ///
+ ///
+ ///
+ public static string JustPath(string cPath)
+ {
+ //Get the full path of this path
+ string lcPath = cPath.Trim();
+
+ //If the file contains a backslash then remove it and return the path onlyfile name get rid of it
+ if(lcPath.IndexOf('\\') == -1)
+ return "";
+ else
+ return lcPath.Substring(0, lcPath.LastIndexOf('\\'));
+ }
+
+ ///
+ /// Returns the file name part without extension from a Path\FileName.ext string
+ ///
+ /// JustStem("c:\\My Folders\\MyFile.txt"); //returns "MyFile"
+ ///
+ ///
+ ///
+ ///
+ public static string JustStem(string cPath)
+ {
+ //Get the name of the file
+ string lcFileName = JustFName(cPath.Trim());
+
+ //Remove the extension and return the string
+ if(lcFileName.IndexOf(".") == -1)
+ return lcFileName;
+ else
+ return lcFileName.Substring(0, lcFileName.LastIndexOf('.'));
+ }
+
+
+ ///
+ ///
+
+
+ //End of File Class
+ }
+
+}
diff --git a/VFPToolkitNET_CSharpNET_NetCore/Help.cs b/VFPToolkitNET_CSharpNET_NetCore/Help.cs
new file mode 100644
index 0000000..a4ba076
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_NetCore/Help.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Drawing.Printing;
+
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+
+ ///
+ /// Visual FoxPro Helper Functions
+ /// This class contains dummy helper functions that guides you in the right direction to achieve a desired functionality.
+ /// For example, if you need to call DoDefault(), the function will contains a sample code showing how this can be
+ /// achieved using the .NET Framework. The function itself returns nothing.
+ ///
+ public class help
+ {
+
+ ///
+ /// Use System.Windows.Forms.Application object to get a reference to the application
+ ///
+ public static void _Screen() {}
+
+ ///
+ /// The functionality of DoDefault() to call the parent class's default
+ /// behavior can be achieved by calling base.MethodName().
+ ///
+ ///
+ /// Here is an example:
+ /// Example: base.MethodName(Parameters);
+ ///
public static void DoDefault()
+ {
+ //This method only provides help
+ }
+
+ ///
+ /// The functionality of EditSource() can be achieved by writing a macro
+ /// for the IDE. A sample is included in example section.
+ ///
+ ///
+ /// Here is an example that opens up a document for editing inside the IDE.
+ /// 'Open a source code document for editing
+ /// Dim Cmd As Command
+ /// Dim Doc As Document
+ /// Dim TxtDoc As TextDocument
+ /// DTE.ItemOperations.OpenFile("FilePath\File Name")
+ ///
public static void EditSource()
+ {
+ //This method only provides help
+ }
+
+ ///
+ /// The functionality of IIF() can be achieved by using the ? : syntax as follows
+ ///
+ ///
+ /// MyValue = IIF(x=y, .T., .F.) && VFP
+ /// MyValue = x == y ? True : False //C# .NET
+ /// MyValue = Iif(x = y, True , False) 'VB .NET
+ ///
+ ///
+ public static void IIF()
+ {
+ //Dummy place holder method used for helping how an IIF can be achieved
+ //MyValue = IIF(x=y, .T., .F.) now becomes
+ //MyValue = x == y ? True : False
+ }
+
+ ///
+ /// An example of how the Do() functionality is achieved in .NET is included.
+ ///
+ ///
+ /// Do MyFile.exe can now be achieved using
+ /// Process.Start("MyFile.exe");
+ ///
+ public static void Do(){}
+
+ ///
+ /// There are couple of ways in which the functionality of NewObject()
+ /// is achieved in the .NET Framework. Please check the example section
+ /// for further details.
+ ///
+ ///
+ /// This functionality can be achieved couple of ways:
+ /// The first method is to create the object: Both a and b do the same job
+ /// a. MyCustomerForm oForm = new MyCustomerForm(); //Create a new object here
+ /// b. Application.Load(new MyCustomerForm());
+ /// c. Activator.CreateInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void NewObject(){}
+
+ ///
+ /// There are couple of ways in which the functionality of CreateObject()
+ /// is achieved in the .NET Framework. Please check the example section
+ /// for further details.
+ ///
+ ///
+ /// This functionality can be achieved couple of ways:
+ /// The first method is to create the object: Both a and b do the same job
+ /// a. MyCustomerForm oForm = new MyCustomerForm(); //Create a new object here
+ /// b. Application.Load(new MyCustomerForm());
+ /// c. Activator.CreateInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void CreateObject(){}
+
+ ///
+ /// Please refer further documentation in the .NET Framework on:
+ /// Activator.CreateInstance() and Activator.CreateComInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void CreateObjectEx(){}
+
+ ///
+ /// Please refer further documentation in the .NET Framework on
+ /// Activator.GetObject()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void GetObject(){}
+
+
+ ///
+ /// GetInterface() can be achieved by adding object references through
+ /// the "Add References" tab to achieve early binding. An example of how
+ /// an Excel object is accessed from .NET Framework is included in the example
+ /// section.
+ ///
+ ///
+ /// A Type has to be specified for all the objects in .NET so in order to get
+ /// early bound controls you could follow the following steps: The example
+ /// demonstrates how an Excel object is created in .NET
+ ///
+ /// 1. Right click on References and select "Add Reference"
+ /// 2. Select the "COM Components" tab
+ /// 3. Locate the "Microsoft Excel Object Library" and select it
+ /// 4. Add the following code
+ /// private Excel.Application oExcel = null;
+ /// oExcel = new Excel.Application();
+ /// oExcel.Visible = true;
+ ///
+ public static void GetInterface(){}
+
+
+ ///
+ ///
+
+
+
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_NetCore/Math.cs b/VFPToolkitNET_CSharpNET_NetCore/Math.cs
new file mode 100644
index 0000000..b7daec6
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_NetCore/Math.cs
@@ -0,0 +1,665 @@
+using System;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro Math Functions
+ /// This class contains all the math functions such as Cos(), Sin(), Tan(), Abs(), Mod(), Sqrt(),
+ /// Int(), Log(), Max(), Min() etc.
+ /// (Most of the math functions are decoraters that call the System.Math methods.)
+ ///
+ public class math
+ {
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static decimal Abs(decimal nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static double Abs(double nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static int Abs(int nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Cosine (Use Math.ACos() instead)
+ ///
+ ///
+ ///
+ public static double ACos(double nNumber)
+ {
+ return System.Math.Acos(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Cosine (Use Math.ACos() instead)
+ ///
+ ///
+ ///
+ public static double ACos(int nNumber)
+ {
+ return System.Math.Acos((double)nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Sin (Use Math.ASin() instead)
+ ///
+ ///
+ ///
+ public static double ASin(double nNumber)
+ {
+ return System.Math.Asin(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Sin (Use Math.ASin() instead)
+ ///
+ ///
+ ///
+ public static double ASin(int nNumber)
+ {
+ return System.Math.Asin((double)nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Tangent (Use Math.ATan() instead)
+ ///
+ ///
+ ///
+ public static double ATan(double nNumber)
+ {
+ return System.Math.Atan(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Tangent (Use Math.ATan() instead)
+ ///
+ ///
+ ///
+ public static double ATan(int nNumber)
+ {
+ return System.Math.Atan((double)nNumber);
+ }
+
+ ///
+ /// Returns an Atn2() from two coordinates (Use Math.Atn2() instead)
+ ///
+ ///
+ ///
+ public static double Atn2(double nYCoordinate, double nXCoordinate)
+ {
+ return System.Math.Atan2(nYCoordinate, nXCoordinate);
+ }
+
+ ///
+ /// Returns an ceiling value from a number (Use Math.Celing() instead)
+ ///
+ ///
+ ///
+ public static double Ceiling(double nNumber)
+ {
+ return System.Math.Ceiling(nNumber);
+ }
+
+ ///
+ /// Returns the Cosine of an angle(Use Math.Cos() instead)
+ ///
+ ///
+ ///
+ public static double Cos(double nNumber)
+ {
+ return System.Math.Cos(nNumber);
+ }
+
+ ///
+ /// Returns the Cosine of an angle (Use Math.Cos() instead)
+ ///
+ ///
+ ///
+ public static double Cos(int nNumber)
+ {
+ return System.Math.Cos((double)nNumber);
+ }
+
+ ///
+ /// Receives degrees as a parameter and converts it to radiants
+ ///
+ ///
+ ///
+ public static double DTOR(double nDegrees)
+ {
+ return ((nDegrees * System.Math.PI)/180);
+ }
+
+ ///
+ /// Returns a number raised to the specified power (Use Math.Exp() instead)
+ ///
+ ///
+ ///
+ public static double Exp(double nNumber)
+ {
+ return System.Math.Exp(nNumber);
+ }
+
+ ///
+ /// Returns an Floor value from a number (Use Math.Floor() instead)
+ ///
+ ///
+ ///
+ public static double Floor(double nNumber)
+ {
+ return System.Math.Floor(nNumber);
+ }
+
+ ///
+ /// Converts a double to an integer (Use (int)MyNumber instead)
+ ///
+ ///
+ ///
+ public static int Int(double nNumber)
+ {
+ return (int)nNumber;
+ }
+
+ ///
+ /// Converts a float to an integer (Use (int)MyNumber instead)
+ ///
+ ///
+ ///
+ public static int Int(float nNumber)
+ {
+ return (int)nNumber;
+ }
+
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(double nNumber)
+ {
+ return System.Math.Log(nNumber);
+ }
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(int nNumber)
+ {
+ return System.Math.Log((double)nNumber);
+ }
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(decimal nNumber)
+ {
+ return System.Math.Log((double)nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(double nNumber)
+ {
+ return System.Math.Log10(nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(int nNumber)
+ {
+ return System.Math.Log10((double)nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(decimal nNumber)
+ {
+ return System.Math.Log10((double)nNumber);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static double Max(double nVal1, double nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static decimal Max(decimal nVal1, decimal nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ public static int Max(int nVal1, int nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static float Max(float nVal1, float nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static double Min(double nVal1, double nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static decimal Min(decimal nVal1, decimal nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static int Min(int nVal1, int nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static float Min(float nVal1, float nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Returns the Mod of two numbers.
+ ///
+ ///
+ ///
+ ///
+ public static double Mod(double nDividend, double nDivisor)
+ {
+ return nDividend % nDivisor ;
+ }
+
+ ///
+ /// Converts a decimal value to double (use (double)MyDecimalValue instead)
+ ///
+ ///
+ ///
+ public static double MTON(decimal nMoney)
+ {
+ return (double)nMoney;
+ }
+
+ ///
+ /// Converts a double value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(double nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Converts a integer value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(int nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Converts a float value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(float nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Returns the value of PI (Use Math.PI instead)
+ ///
+ ///
+ public static double PI()
+ {
+ return System.Math.PI;
+ }
+
+ ///
+ /// Receives a seed as a parameter and returns a random number.
+ ///
+ ///
+ ///
+ public static double Random(int nSeed)
+ {
+ System.Random r = new System.Random(nSeed);
+ return r.Next();
+ }
+ public static double Random()
+ {
+ System.Random r = new System.Random();
+ return r.Next();
+ }
+
+ ///
+ /// Rounds a number and returns it back. (Use Math.Round() instead)
+ ///
+ ///
+ ///
+ public static decimal Round(decimal nNumber)
+ {
+ return System.Math.Round(nNumber);
+ }
+
+ ///
+ /// Rounds a number and returns it back. (Use Math.Round() instead)
+ ///
+ ///
+ ///
+ ///
+ public static double Round(double nNumber, int nDigits)
+ {
+ return System.Math.Round(nNumber, nDigits);
+ }
+
+ ///
+ /// Receives radiants as a parameter and converts it to degrees
+ ///
+ ///
+ ///
+ public static double RTOD(double nRadians)
+ {
+ return ((nRadians * 180)/System.Math.PI);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(decimal nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(double nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(int nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(float nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns the Sin of an angle (Use Math.Sin() instead)
+ ///
+ ///
+ ///
+ public static double Sin(double nNumber)
+ {
+ return System.Math.Sin(nNumber);
+ }
+
+ ///
+ /// Returns the Sin of an angle (Use Math.Sin() instead)
+ ///
+ ///
+ ///
+ public static double Sin(int nNumber)
+ {
+ return System.Math.Sin((double)nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ /// Console.WriteLine(Sqrt(4)); //Returns 2
+ /// Console.WriteLine(Sqrt(2 * Sqrt(2))); //Returns 1.6817928
+ ///
+ ///
+ ///
+ public static double Sqrt(double nNumber)
+ {
+ return System.Math.Sqrt(nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ ///
+ public static double Sqrt(decimal nNumber)
+ {
+ return System.Math.Sqrt((double)nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ ///
+ public static double Sqrt(int nNumber)
+ {
+ return System.Math.Sqrt((double)nNumber);
+ }
+
+ ///
+ /// Returns the Tangent of an angle (Use Math.Tan() instead)
+ ///
+ ///
+ ///
+ public static double Tan(double nNumber)
+ {
+ return System.Math.Tan(nNumber);
+ }
+
+ ///
+ /// Returns the Tangent of an angle (Use Math.Tan() instead)
+ ///
+ ///
+ ///
+ public static double Tan(int nNumber)
+ {
+ return System.Math.Tan((double)nNumber);
+ }
+
+
+ ///
+ /// Receives and integer expression and position as parameter and returns the
+ /// result of shifting the bits to the left for the specified number of positions
+ ///
+ ///
+ ///
+ ///
+ public static int BitLShift(int tnExpression, int tnPositions)
+ {
+ return tnExpression << tnPositions;
+ }
+
+ ///
+ /// Receives and integer expression and position as parameter and returns the
+ /// result of shifting the bits to the left for the specified number of positions
+ ///
+ ///
+ ///
+ ///
+ public static int BitRShift(int tnExpression, int tnPositions)
+ {
+ return tnExpression >> tnPositions;
+ }
+
+ ///
+ /// Receives two integers and returns the result of a bitwise and operation
+ ///
+ ///
+ ///
+ ///
+ public static int BitAnd(int tnExpression1, int tnExpression2)
+ {
+ return tnExpression1 & tnExpression2;
+ }
+
+ ///
+ /// Receives two integers and returns the result of a bitwise or operation
+ ///
+ ///
+ ///
+ ///
+ public static int BitOr(int tnExpression1, int tnExpression2)
+ {
+ return tnExpression1 | tnExpression2;
+ }
+
+ ///
+ /// Receives and integer and returns the negation
+ ///
+ ///
+ ///
+ public static int BitNot(int tnExpression)
+ {
+ return ~tnExpression;
+ }
+
+
+ ///
+ /// Receives an integer value and position as parameter and returns the
+ /// specified bit in that position.
+ ///
+ ///
+ ///
+ ///
+ public static bool BitTest(int tnExpression, int tnPosition)
+ {
+ //Create an array of integer
+ int[] aInt = {5};
+
+ //Create the BitArray so the bits are populated
+ System.Collections.BitArray ba = new System.Collections.BitArray(aInt);
+
+ //Return the appropriate position
+ return ba[0];
+ }
+
+
+ ///
+ ///
+
+ //public static void FV(decimal nPayment, decimal nInterestRate, int nPeriods)
+ //{
+ //return nPayment/(1+nInterestRate)^nPeriods;
+ //Microsoft.VisualBasic.VBCodeProvider.
+
+ //}
+
+ //The following three functions used for calculations are not implemented
+ //public static decimal FV(decimal nPayment, decimal nInterestRate, int nPeriods)
+ //public static decimal PV(decimal nPayment, decimal nInterestRate, int nTotalPayments)
+ //public static decimal Payment(decimal nPrincipal, decimal nInterestRate, int nPayments)
+
+ //End of Math class
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_NetCore/Strings.cs b/VFPToolkitNET_CSharpNET_NetCore/Strings.cs
new file mode 100644
index 0000000..9546126
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_NetCore/Strings.cs
@@ -0,0 +1,1238 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Globalization;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro String Functions
+ /// This class contains all the string manipulations functions. Some of the new
+ /// functions in VFP7 such as StrExtract(), GetWordCount(), GetWordNumber() have also
+ /// been implemented. Favourites such as FileToStr(), StrToFile(), Stuff(), Proper(),
+ /// StrTran(), At(), RAt(), Occurs() etc. are also included.
+ ///
+ /// Note:
+ /// One string function is not implemented
+ /// public static string StrConv(cExpression, nConversionSetting [, nLocaleID])
+ public class strings
+ {
+ ///
+ /// Removes leading and trailing spaces from cExpression
+ ///
+ ///
+ public static string AllTrim(string cExpression)
+ {
+ return cExpression.Trim();
+ }
+
+
+ ///
+ /// Receives a character as a parameter and returns its ANSI code
+ ///
+ /// Example
+ /// Asc('#'); //returns 35
+ ///
+ ///
+ ///
+ public static int Asc(char cCharacter)
+ {
+ return (int)cCharacter;
+ }
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// If found, returns the beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.At("D", "Joe Doe"); //returns 5
+ ///
+ ///
+ ///
+ ///
+ public static int At(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.IndexOf(cSearchFor) + 1;
+ }
+
+ ///
+ /// Receives two strings and an occurence position (1st, 2nd etc) as parameters and
+ /// searches for one string within another for that position.
+ /// If found, returns the beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.At("o", "Joe Doe", 1); //returns 2
+ /// VFPToolkit.strings.At("o", "Joe Doe", 2); //returns 6
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int At(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor, cSearchIn, nOccurence, 1);
+ }
+
+ /// Private Implementation: This is the actual implementation of the At() and RAt() functions.
+ /// Receives two strings, the expression in which search is performed and the expression to search for.
+ /// Also receives an occurence position and the mode (1 or 0) that specifies whether it is a search
+ /// from Left to Right (for At() function) or from Right to Left (for RAt() function)
+ private static int __at(string cSearchFor, string cSearchIn, int nOccurence, int nMode)
+ {
+ //In this case we actually have to locate the occurence
+ int i = 0;
+ int nOccured = 0;
+ int nPos = 0;
+ if (nMode == 1) {nPos = 0;}
+ else {nPos = cSearchIn.Length;}
+
+ //Loop through the string and get the position of the requiref occurence
+ for (i=1;i<=nOccurence;i++)
+ {
+ if(nMode == 1) {nPos = cSearchIn.IndexOf(cSearchFor,nPos);}
+ else {nPos = cSearchIn.LastIndexOf(cSearchFor,nPos);}
+
+ if (nPos < 0)
+ {
+ //This means that we did not find the item
+ break;
+ }
+ else
+ {
+ //Increment the occured counter based on the current mode we are in
+ nOccured++;
+
+ //Check if this is the occurence we are looking for
+ if (nOccured == nOccurence)
+ {
+ return nPos + 1;
+ }
+ else
+ {
+ if(nMode == 1) {nPos++;}
+ else {nPos--;}
+
+ }
+ }
+ }
+ //We never found our guy if we reached here
+ return 0;
+ }
+
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// This function ignores the case and if found, returns the beginning numeric position
+ /// otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtC("d", "Joe Doe"); //returns 5
+ ///
+ ///
+ ///
+ ///
+ public static int AtC(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.ToLower().IndexOf(cSearchFor.ToLower()) + 1;
+ }
+
+ ///
+ /// Receives two strings and an occurence position (1st, 2nd etc) as parameters and
+ /// searches for one string within another for that position. This function ignores the
+ /// case of both the strings and if found, returns the beginning numeric position
+ /// otherwise returns 0.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtC("d", "Joe Doe", 1); //returns 5
+ /// VFPToolkit.strings.AtC("O", "Joe Doe", 2); //returns 6
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtC(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor.ToLower(), cSearchIn.ToLower(), nOccurence, 1);
+ }
+
+ ///
+ /// Receives an integer ANSI code and returns a character associated with it
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Chr(35); //returns '#'
+ ///
+ ///
+ ///
+ public static char Chr(int nAnsiCode)
+ {
+ return (char)nAnsiCode;
+ }
+
+ ///
+ /// Replaces each character in a character expression that matches a character
+ /// in a second character expression with the corresponding character in a
+ /// third character expression
+ ///
+ ///
+ /// Console.WriteLine(ChrTran("ABCDEF", "ACE", "XYZ")); //Displays XBYDZF
+ /// Console.WriteLine(ChrTran("ABCD", "ABC", "YZ")); //Displays YZD
+ /// Console.WriteLine(ChrTran("ABCDEF", "ACE", "XYZQRST")); //Displays XBYDZF
+ ///
+ ///
+ ///
+ ///
+ public static string ChrTran(string cSearchIn, string cSearchFor, string cReplaceWith)
+ {
+ string lcRetVal = cSearchIn;
+ string cReplaceChar;
+ for(int i=0; i< cSearchFor.Length; i++)
+ {
+ if(cReplaceWith.Length <= i)
+ cReplaceChar = "";
+ else
+ cReplaceChar = cReplaceWith[i].ToString();
+
+ lcRetVal = StrTran(lcRetVal, cSearchFor[i].ToString(), cReplaceChar);
+ }
+ return lcRetVal;
+ }
+
+
+ ///
+ /// Converts character type data to binary type character string. Just a place
+ /// holder function as this becomes irrelevent now.
+ ///
+ ///
+ public static string CreateBinary(string cExpression)
+ {
+ //This decorator simply returns the expression back
+ //This is because we used this function to converts VFP strings to binary type
+ //character string so they could be passed to an ActiveX control or
+ //automation object. In the .NET Framework this becomes irrelevent
+ return cExpression;
+ }
+
+ ///
+ /// Receives a file name as a parameter and returns the contents of that file
+ /// as a string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.FileToStr("c:\\My Folders\\MyFile.txt"); //returns the contents of the file
+ ///
+ ///
+ ///
+ public static string FileToStr(string cFileName)
+ {
+ //Create a StreamReader and open the file
+ StreamReader oReader = System.IO.File.OpenText(cFileName);
+
+ //Read all the contents of the file in a string
+ string lcString = oReader.ReadToEnd();
+
+ //Close the StreamReader and return the string
+ oReader.Close();
+ return lcString;
+ }
+
+ ///
+ /// Receives a string as a parameter and counts the number of words in that string
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe is a good man";
+ /// VFPToolkit.strings.GetWordCount(lcString); //returns 6
+ ///
+ ///
+ ///
+ public static long GetWordCount(string cString)
+ {
+ int i = 0 ;
+ long nLength = cString.Length;
+ long nWordCount = 0;
+
+ //Begin by checking for the first word
+ if (!Char.IsWhiteSpace(cString[0]))
+ {
+ nWordCount ++;
+ }
+
+ //Now look for white spaces and count each word
+ for ( i=0 ; i < nLength ; i++ )
+ {
+ //Check for a space to begin counting a word
+ if (Char.IsWhiteSpace(cString[i]))
+ {
+ //We think we encountered a word
+ //Remove any following white spaces if any after this word
+ do
+ {
+ //Check if we have reached the limit and if so then exit the loop
+ i ++ ;
+ if (i >= nLength) {break;}
+ if (!Char.IsWhiteSpace(cString[i]))
+ {
+ nWordCount++;
+ break;
+ }
+ } while (true);
+
+ }
+
+ }
+ return nWordCount;
+ }
+
+ ///
+ /// Based on the position specified, returns a word from a string
+ /// Receives a string as a parameter and counts the number of words in that string
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe is a good man";
+ /// VFPToolkit.strings.GetWordNumber(lcString, 5); //returns "good"
+ ///
+ ///
+ ///
+ ///
+ public static string GetWordNumb(string cString, int nWordPosition)
+ {
+ int nBeginPos = VFPToolkit.strings.At(" ",cString,nWordPosition - 1);
+ int nEndPos = VFPToolkit.strings.At(" ",cString, nWordPosition);
+ return VFPToolkit.strings.SubStr(cString, nBeginPos + 1, nEndPos -1 - nBeginPos);
+ }
+
+
+ ///
+ /// Returns a bool indicating if the first character in a string is an alphabet or not
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsAlpha("Joe Doe"); //returns true
+ ///
+ /// Tip: This method uses Char.IsAlpha(char) to check if it is an alphabet or not.
+ /// In order to check if the first character is a digit use Char.IsDigit(char)
+ ///
+ ///
+ ///
+ public static bool IsAlpha(string cExpression)
+ {
+ //Check if the first character is a letter
+ return Char.IsLetter(cExpression[0]);
+ }
+
+ ///
+ /// Checks if the first character of a string is a lowercase char and if so then returns true
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsLower("MyName"); //returns false
+ /// VFPToolkit.strings.IsLower("mYnAme"); //returns true
+ ///
+ ///
+ ///
+ public static bool IsLower(string cExpression)
+ {
+ try
+ {
+ //Get the first character in the string
+ string lcString = cExpression.Substring(0,1);
+
+ //Return a bool indicating if the char is an lowercase or not
+ return lcString == lcString.ToLower() ;
+ }
+ catch
+ {
+ //In case of an error return false
+ return false;
+ }
+ }
+
+ ///
+ /// Checks if the first character of a string is an uppercase and if so then returns true
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsUpper("MyName"); //returns true
+ /// VFPToolkit.strings.IsUpper("mYnAme"); //returns false
+ ///
+ ///
+ ///
+ public static bool IsUpper(string cExpression)
+ {
+ try
+ {
+ //Get the first character in the string
+ string lcString = cExpression.Substring(0,1);
+
+ //Return a bool indicating if the char is an uppercase or not
+ return lcString == lcString.ToUpper() ;
+ }
+ catch
+ {
+ //In case of an error return false
+ return false;
+ }
+ }
+
+ ///
+ /// Receives a string and the number of characters as parameters and returns the
+ /// specified number of leftmost characters of that string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Left("Joe Doe", 3); //returns "Joe"
+ ///
+ ///
+ ///
+ ///
+ public static string Left(string cExpression, int nDigits)
+ {
+ return cExpression.Substring(0, nDigits);
+ }
+
+ ///
+ /// Receives a string as a parameter and returns the length of the string
+ ///
+ /// Example:
+ /// string MyString = "Hi there";
+ /// VFPToolkit.strings.Len(MyString); //returns 8
+ ///
+ ///
+ ///
+ public static int Len(string cExpression)
+ {
+ return cExpression.Length;
+ }
+
+ ///
+ /// Receives a string as a parameter and converts it to lowercase
+ ///
+ ///
+ public static string Lower(string cExpression)
+ {
+ //Call the ToLower() method of the string object
+ return cExpression.ToLower() ;
+ }
+
+ ///
+ /// Removes the leading spaces in cExpression
+ ///
+ ///
+ public static string LTrim(string cExpression)
+ {
+ //Hint: Pass null as the first parameter to remove white spaces
+ return cExpression.TrimStart(null);
+ }
+
+ ///
+ /// Returns the number of occurences of a character within a string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Occurs('o', "Joe Doe"); //returns 2
+ ///
+ /// Tip: If we have a string say lcString, then lcString[3] gives us the 3rd character in the string
+ ///
+ ///
+ ///
+ ///
+ public static int Occurs(char tcChar, string cExpression)
+ {
+ int i, nOccured = 0;
+
+ //Loop through the string
+ for (i = 0; i < cExpression.Length ; i++ )
+ {
+ //Check if each expression is equal to the one we want to check against
+ if (cExpression[i] == tcChar)
+ {
+ //if so increment the counter
+ nOccured++ ;
+ }
+ }
+ return nOccured;
+ }
+ ///
+ /// Returns the number of occurences of one string within another string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Occurs("oe", "Joe Doe"); //returns 2
+ /// VFPToolkit.strings.Occurs("Joe", "Joe Doe"); //returns 1
+ ///
+ /// Tip: String.IndexOf() searches the string (starting from left) for another character or string expression
+ ///
+ ///
+ ///
+ ///
+ public static int Occurs(string cString, string cExpression)
+ {
+ int nPos = 0;
+ int nOccured = 0;
+ do
+ {
+ //Look for the search string in the expression
+ nPos = cExpression.IndexOf(cString,nPos);
+
+ if (nPos < 0)
+ {
+ //This means that we did not find the item
+ break;
+ }
+ else
+ {
+ //Increment the occured counter based on the current mode we are in
+ nOccured++;
+ nPos++;
+ }
+ } while (true);
+
+ //Return the number of occurences
+ return nOccured;
+ }
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the both sides of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns " Joe Doe "
+ ///
+ ///
+ ///
+ ///
+ public static string PadC(string cExpression, int nResultSize)
+ {
+ //Determine the number of padding characters
+ int nPaddTotal = nResultSize - cExpression.Length;
+ int lnHalfLength = (int)(nPaddTotal/2);
+
+ string lcString = PadL(cExpression, cExpression.Length + lnHalfLength);
+ return lcString.PadRight(nResultSize);
+ }
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on both sides of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "xJoe Doexx"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string PadC(string cExpression, int nResultSize, char cPaddingChar)
+ {
+ //Determine the number of padding characters
+ int nPaddTotal = nResultSize - cExpression.Length;
+ int lnHalfLength =(int)(nPaddTotal/2);
+
+ string lcString = PadL(cExpression, cExpression.Length + lnHalfLength,cPaddingChar);
+ return lcString.PadRight(nResultSize, cPaddingChar);
+ }
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the left of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns " Joe Doe"
+ ///
+ ///
+ ///
+ ///
+ public static string PadL(string cExpression, int nResultSize)
+ {return cExpression.PadLeft(nResultSize);}
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on the left of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "xxxJoe Doe"
+ ///
+ /// Tip: Use single quote to create a character type data and double quotes for strings
+ ///
+ ///
+ public static string PadL(string cExpression, int nResultSize, char cPaddingChar)
+ {return cExpression.PadLeft(nResultSize, cPaddingChar);}
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the right of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns "Joe Doe "
+ ///
+ ///
+ ///
+ ///
+ public static string PadR(string cExpression, int nResultSize)
+ {return cExpression.PadRight(nResultSize);}
+
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on the right of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "Joe Doexxx"
+ ///
+ /// Tip: Use single quote to create a character type data and double quotes for strings
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string PadR(string cExpression, int nResultSize, char cPaddingChar)
+ {return cExpression.PadRight(nResultSize, cPaddingChar);}
+
+ ///
+ /// Receives a string as a parameter and returns the string in Proper format (makes each letter after a space capital)
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Proper("joe doe is a good man"); //returns "Joe Doe Is A Good Man"
+ ///
+ ///
+ ///
+ /// ToDo: Split the string instead and you do not have to worry about comparing each char
+ public static string Proper(string cString)
+ {
+
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cString);
+
+ int i,j = 0 ;
+ int nLength = cString.Length ;
+
+ for ( i = 0 ; i < nLength; i++)
+ {
+ //look for a blank space and once found make the next character to uppercase
+ if ((i== 0) || (char.IsWhiteSpace(cString[i])))
+ {
+ //Handle the first character differently
+ if( i==0 ) {j=i;}
+ else {j=i+1;}
+
+ //Make the next character uppercase and update the stringBuilder
+ sb.Remove(j, 1);
+ sb.Insert(j, Char.ToUpper(cString[j]));
+ }
+ }
+ return sb.ToString();
+ }
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// The search is performed starting from Right to Left and if found, returns the
+ /// beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAt("o", "Joe Doe"); //returns 6
+ ///
+ ///
+ ///
+ ///
+ public static int RAt(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.LastIndexOf(cSearchFor) + 1;
+ }
+
+ ///
+ /// Receives two strings as parameters and an occurence position as parameters.
+ /// The function searches for one string within another and the search is performed
+ /// starting from Right to Left and if found, returns the beginning numeric position
+ /// otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAt("o", "Joe Doe", 1); //returns 6
+ /// VFPToolkit.strings.RAt("o", "Joe Doe", 2); //returns 2
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int RAt(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor, cSearchIn, nOccurence, 0);
+ }
+
+ ///
+ /// Receives a string expression and a numeric value indicating number of time
+ /// and replicates that string for the specified number of times.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Replicate("Joe", 5); //returns JoeJoeJoeJoeJoe
+ ///
+ /// Tip: Use a StringBuilder when lengthy string manipulations are required.
+ ///
+ ///
+ ///
+ ///
+ public static string Replicate(string cExpression, int nTimes)
+ {
+ //Create a stringBuilder
+ StringBuilder sb = new StringBuilder();
+
+ //Insert the expression into the StringBuilder for nTimes
+ sb.Insert(0,cExpression,nTimes);
+
+ //Convert it to a string and return it back
+ return sb.ToString();
+ }
+
+ ///
+ /// Receives a string and the number of characters as parameters and returns the
+ /// specified number of rightmost characters of that string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Right("Joe Doe", 3); //returns "Doe"
+ ///
+ ///
+ ///
+ ///
+ public static string Right(string cExpression, int nDigits)
+ {
+ return cExpression.Substring(cExpression.Length - nDigits);
+ }
+
+ ///
+ /// Removes the trailing spaces in cExpression
+ ///
+ ///
+ /// VfpToolkit.strings.RTrim("VFPToolkitNET "); //returns "VFPToolkitNET"
+ ///
+ ///
+ public static string RTrim(string cExpression)
+ {
+ //Hint: Pass null as the first parameter to remove white spaces
+ return cExpression.TrimEnd(null);
+ }
+
+ ///
+ /// Receives an integer as a parameter and returns an empty string of that length
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Space(20); //returns a string with 20 spaces
+ ///
+ ///
+ ///
+ public static string Space(int nSpaces)
+ {
+ //Create a new string and return those many spaces in it
+ char val = ' ';
+ return new string(val,nSpaces);
+ }
+
+ ///
+ /// Receives an integer/decimal/double as a parameter and converts it to a string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Str(135); //returns "135"
+ ///
+ ///
+ ///
+ public static string Str(int nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+ ///
+ /// Overloaded method for receiving a parameter of type double
+ ///
+ ///
+ public static string Str(double nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+ ///
+ /// Overloaded method for receiving a parameter of type decimal
+ ///
+ ///
+ public static string Str(decimal nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters. Receives a beginning occurence
+ /// to begin the extraction from and also receives a flag (0/1) where 1 indicates
+ /// that the search should be case insensitive.
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ", 1, 0); //returns "eDo"
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim, int nBeginOccurence, int nFlags)
+ {
+ string cstring = cSearchExpression;
+ string cb = cBeginDelim;
+ string ce = cEndDelim;
+ string lcRetVal = "";
+
+ //Check for case-sensitive or insensitive search
+ if (nFlags == 1)
+ {
+ cstring = cstring.ToLower();
+ cb = cb.ToLower();
+ ce = ce.ToLower();
+ }
+
+ //Lookup the position in the string
+ int nbpos = At(cb, cstring, nBeginOccurence) + cb.Length - 1;
+ int nepos = cstring.IndexOf(ce, nbpos + 1);
+
+ //Extract the part of the strign if we get it right
+ if (nepos > nbpos)
+ {
+ lcRetVal = cSearchExpression.Substring(nbpos , nepos - nbpos);
+ }
+
+ return lcRetVal;
+ }
+
+ ///
+ /// Receives a string and a delimiter as parameters and returns a string starting
+ /// from the position after the delimiter
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o"); //returns "eDoeJoeDoe"
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim)
+ {
+ int nbpos = At(cBeginDelim, cSearchExpression);
+ return cSearchExpression.Substring(nbpos + cBeginDelim.Length - 1);
+ }
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ"); //returns "eDo"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim)
+ {
+ return StrExtract(cSearchExpression, cBeginDelim, cEndDelim, 1, 0);
+ }
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters. It also receives a beginning occurence
+ /// to begin the extraction from.
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ", 2); //returns ""
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim, int nBeginOccurence)
+ {
+ return StrExtract(cSearchExpression, cBeginDelim, cEndDelim, nBeginOccurence, 0);
+ }
+
+ ///
+ /// Receives a string and a file name as parameters and writes the contents of the
+ /// string to that file
+ ///
+ /// Example:
+ /// string lcString = "This is the line we want to insert in our file.";
+ /// VFPToolkit.strings.StrToFile(lcString, "c:\\My Folders\\MyFile.txt");
+ ///
+ ///
+ ///
+ ///
+ public static void StrToFile(string cExpression, string cFileName)
+ {
+ //Check if the sepcified file exists
+ if (System.IO.File.Exists(cFileName) == true)
+ {
+ //If so then Erase the file first as in this case we are overwriting
+ System.IO.File.Delete(cFileName);
+ }
+
+ //Create the file if it does not exist and open it
+ FileStream oFs = new FileStream(cFileName,FileMode.CreateNew,FileAccess.ReadWrite);
+
+ //Create a writer for the file
+ StreamWriter oWriter = new StreamWriter(oFs);
+
+ //Write the contents
+ oWriter.Write(cExpression);
+ oWriter.Flush();
+ oWriter.Close();
+
+ oFs.Close();
+ }
+ ///
+ /// Receives a string and a file name as parameters and writes the contents of the
+ /// string to that file. Receives an additional parameter specifying whether the
+ /// contents should be appended at the end of the file
+ ///
+ /// Example:
+ /// string lcString = "This is the line we want to insert in our file.";
+ /// VFPToolkit.strings.StrToFile(lcString, "c:\\My Folders\\MyFile.txt");
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void StrToFile(string cExpression, string cFileName, bool lAdditive)
+ {
+ //Create the file if it does not exist and open it
+ FileStream oFs = new FileStream(cFileName,FileMode.OpenOrCreate,FileAccess.ReadWrite);
+
+ //Create a writer for the file
+ StreamWriter oWriter = new StreamWriter(oFs);
+
+ //Set the pointer to the end of file
+ oWriter.BaseStream.Seek(0, SeekOrigin.End);
+
+ //Write the contents
+ oWriter.Write(cExpression);
+ oWriter.Flush();
+ oWriter.Close();
+ oFs.Close();
+ }
+
+ ///
+ /// Searches one string into another string and replaces all occurences with
+ /// a blank character.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o"); //returns "J e D e" :)
+ ///
+ ///
+ ///
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //Call the Replace() method of the StringBuilder
+ return sb.Replace(cSearchFor," ").ToString();
+ }
+
+ ///
+ /// Searches one string into another string and replaces all occurences with
+ /// a third string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o", "ak"); //returns "Jake Dake"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor, string cReplaceWith)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //There is a bug in the replace method of the StringBuilder
+ sb.Replace(cSearchFor, cReplaceWith);
+
+ //Call the Replace() method of the StringBuilder and specify the string to replace with
+ return sb.Replace(cSearchFor, cReplaceWith).ToString();
+ }
+
+ /// Searches one string into another string and replaces each occurences with
+ /// a third string. The fourth parameter specifies the starting occurence and the
+ /// number of times it should be replaced
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o", "ak", 2, 1); //returns "Joe Dake"
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor, string cReplaceWith, int nStartoccurence, int nCount)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //There is a bug in the replace method of the StringBuilder
+ sb.Replace(cSearchFor, cReplaceWith);
+
+ //Call the Replace() method of the StringBuilder specifying the replace with string, occurence and count
+ return sb.Replace(cSearchFor, cReplaceWith, nStartoccurence, nCount).ToString();
+ }
+
+
+ ///
+ /// Receives a string (cExpression) as a parameter and replaces a specified number
+ /// of characters in that string (nCharactersReplaced) from a specified location
+ /// (nStartReplacement) with a specified string (cReplacement)
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe";
+ /// string lcReplace = "Foo ";
+ /// VFPToolkit.strings.Stuff(lcString, 5, 0, lcReplace); //returns "Joe Foo Doe";
+ /// VFPToolkit.strings.Stuff(lcString, 5, 3, lcReplace); //returns "Joe Foo ";
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string Stuff(string cExpression, int nStartReplacement, int nCharactersReplaced, string cReplacement)
+ {
+ //Create a stringbuilder to work with the string
+ StringBuilder sb = new StringBuilder(cExpression);
+
+ if(nCharactersReplaced + nStartReplacement -1 >= cExpression.Length)
+ nCharactersReplaced = cExpression.Length - nStartReplacement + 1;
+
+
+ //First remove the characters specified in nCharacterReplaced
+ if (nCharactersReplaced != 0)
+ {
+ sb.Remove(nStartReplacement - 1, nCharactersReplaced);
+ }
+
+ //Now Add the new string at the right location
+ //sb.Insert(0,cExpression,nTimes);
+ sb.Insert(nStartReplacement - 1,cReplacement);
+ return sb.ToString();
+ }
+
+
+ ///
+ /// Receives a string as a parameter and returns a part of the string based on the parameters specified.
+ ///
+ /// string lcName = "Joe Doe";
+ /// SubStr(lcName, 1, 3); //returns "Joe"
+ /// SubStr(lcName, 5); //returns Doe
+ ///
+ ///
+ ///
+ ///
+ public static string SubStr(string cExpression, int nStartPosition)
+ {
+ return cExpression.Substring(nStartPosition-1);
+ }
+
+ ///
+ /// Overloaded method for SubStr() that receives starting position and length
+ ///
+ ///
+ ///
+ ///
+ public static string SubStr(string cExpression, int nStartPosition, int nLength)
+ {
+ nStartPosition--;
+ if((nLength + nStartPosition) > cExpression.Length)
+ return cExpression.Substring(nStartPosition);
+ else
+ return cExpression.Substring(nStartPosition,nLength);
+ }
+
+ ///
+ /// Removes leading and trailing spaces from cExpression
+ ///
+ ///
+ public static string Trim(string cExpression)
+ {
+ return cExpression.Trim();
+ }
+
+
+ ///
+ /// Receives a string as a parameter and converts it to uppercase
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Upper("MyName"); //returns "MYNAME"
+ ///
+ ///
+ ///
+ public static string Upper(string cExpression)
+ {
+ //Call the ToUpper() method of the string object
+ return cExpression.ToUpper();
+ }
+
+
+ ///
+ /// Receives a string and converts it to an integer
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Val("1325"); //returns 1325
+ ///
+ ///
+ ///
+ public static int Val(string cExpression)
+ {
+ //Remove all the spaces and commas from the string
+ //Get the integer portion of the string
+ return Int32.Parse(cExpression, NumberStyles.Any);
+ }
+
+
+ ///
+ /// Receives a string and converts it to an integer
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtLine("Is", "Is Life Beautiful? \r\n It sure is"); //returns 1
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ string lcString ;
+ int nPosition;
+ int nCount = 0;
+
+ try
+ {
+ nPosition = VFPToolkit.strings.At(tcSearchExpression, tcExpressionSearched);
+ if (nPosition > 0)
+ {
+ lcString = VFPToolkit.strings.SubStr(tcExpressionSearched , 1, nPosition -1);
+ nCount = VFPToolkit.strings.Occurs(@"\r", lcString) + 1;
+ }
+ }
+ catch
+ {
+ nCount = 0;
+ }
+
+ return nCount;
+ }
+
+ ///
+ /// Receives a search expression and string to search as parameters and returns an integer specifying
+ /// the line where it was found. This function starts it search from the end of the string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAtLine("sure", "Is Life Beautiful? \r\n It sure is") 'returns 2
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int RAtLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ string lcString ;
+ int nPosition;
+ int nCount = 0;
+
+ try
+ {
+ nPosition = VFPToolkit.strings.RAt(tcSearchExpression, tcExpressionSearched);
+ if (nPosition > 0)
+ {
+ lcString = VFPToolkit.strings.SubStr(tcExpressionSearched , 1, nPosition -1);
+ nCount = VFPToolkit.strings.Occurs(@"\r", lcString) + 1;
+ }
+ }
+ catch
+ {
+ nCount = 0;
+ }
+
+ return nCount;
+ }
+
+ ///
+ /// Returns the line number of the first occurence of a string expression within
+ /// another string expression without regard to case (upper or lower)
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtCLine("Is Life Beautiful? \r\n It sure is", "Is"); //returns 1
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtCLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ return AtLine(tcSearchExpression.ToLower(), tcExpressionSearched.ToLower());
+ }
+
+ ///
+ /// Receives a string as a parameter and returns a bool indicating if the left most
+ /// character in the string is a valid digit.
+ ///
+ /// Example:
+ /// if(VFPToolkit.strings.IsDigit("1Kamal")){...} //returns true
+ ///
+ ///
+ ///
+ ///
+ public static bool IsDigit(string tcString)
+ {
+ //get the first character in the string
+ char c = tcString[0];
+ return Char.IsDigit(c);
+ }
+
+ ///
+ /// Returns the number of lines in a string
+ ///
+ /// Example:
+ /// int lnLines = VFPToolkit.strings.MemLines(lcMyLongString);
+ ///
+ ///
+ ///
+ ///
+ public static int MemLines(string tcString)
+ {
+ if(tcString.Trim().Length == 0)
+ return 0;
+ else
+ return VFPToolkit.strings.Occurs("\\r", tcString) + 1;
+ }
+
+ ///
+ /// Receives a string and a line number as parameters and returns the
+ /// specified line in that string
+ ///
+ /// Example:
+ /// string lcCity = VFPToolkit.strings.MLine(tcAddress, 2); // Not that you would want to do something like this but you could ;)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string MLine(string tcString, int tnLineNo)
+ {
+ string[] aLines = tcString.Split('\r');
+ string lcRetVal = "";
+ try
+ {
+ lcRetVal = aLines[tnLineNo -1];
+ }
+ catch
+ {
+ //Ignore the exception as MLINE always returns a value
+ }
+
+ return lcRetVal;
+ }
+
+
+
+ ///
+ ///
+
+
+ //End of stringsclass
+ }
+ //End of vfp namespace
+}
diff --git a/VFPToolkitNET_CSharpNET_NetCore/VFPToolkitNET_CSharpNET_NetCore.csproj b/VFPToolkitNET_CSharpNET_NetCore/VFPToolkitNET_CSharpNET_NetCore.csproj
new file mode 100644
index 0000000..bec96ca
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_NetCore/VFPToolkitNET_CSharpNET_NetCore.csproj
@@ -0,0 +1,49 @@
+
+
+
+ net5.0-windows
+ true
+
+
+ false
+
+
+
+
+
+
+
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+
+
diff --git a/VFPToolkitNET_CSharpNET_NetCore/VfpData.cs b/VFPToolkitNET_CSharpNET_NetCore/VfpData.cs
new file mode 100644
index 0000000..77dfcba
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_NetCore/VfpData.cs
@@ -0,0 +1,703 @@
+using System;
+using System.Data;
+using System.Data.OleDb;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Summary description for vfpData.
+ ///
+ public class vfpData
+ {
+ private static string _Order = "";
+ private static bool _Found = false;
+ private static string _Filter = "";
+
+ //Create this one as a property so we can trap for errors in get
+ public static System.Data.DataView oView ;
+
+ ///
+ /// Returns the number of records in the DataView.
+ /// If you have a filter condition on the DataView then the number of records returned is after
+ /// applying the filters.
+ ///
+ ///
+ /// vfpData.RecCount(oView);
+ ///
+ ///
+ ///
+ public static int RecCount(System.Data.DataView toView)
+ {
+ return toView.Count;
+ }
+ public static int RecCount(){return RecCount(vfpData.oView);}
+
+ ///
+ /// Returns a string that specifies the current filter condition
+ ///
+ ///
+ /// vfpData.Filter(oView);
+ ///
+ ///
+ ///
+ public static string Filter(System.Data.DataView toView)
+ {
+ return toView.RowFilter;
+ }
+ public static string Filter(){return Filter(vfpData.oView);}
+
+ ///
+ /// Receives a Field Position and DataView as parameters and returns the field name
+ /// otherwise returns a blank
+ ///
+ ///
+ /// string MyField = vfpData.Field(5, oView);
+ ///
+ ///
+ ///
+ ///
+ public static string Field(int nPosition, System.Data.DataView toView)
+ {
+ string lcRetVal = "";
+ try
+ {
+ //Handle the position as the columns are zero based
+ lcRetVal = toView.Table.Columns[nPosition - 1].ColumnName;
+ }
+ catch
+ {
+ //Ignore the catch so a blank string is returned
+ }
+ return lcRetVal;
+ }
+ public static string Field(int nPosition){return Field(nPosition, vfpData.oView);}
+
+ ///
+ /// Receives a DataView as a parameter and returns the number of columns in that view
+ ///
+ ///
+ /// int nTotalFields = vfpData.FCount(oView);
+ ///
+ ///
+ ///
+ public static int FCount(System.Data.DataView toView)
+ {
+ //Note that this is NOT a zero based value in the Columns collection
+ return toView.Table.Columns.Count;
+ }
+ public static int FCount(){return FCount(vfpData.oView);}
+
+
+ ///
+ /// Receives a field name and DataRow as parameters and returns the value in string format.
+ /// If you want to convert your values into specific datatypes then cast
+ /// the return value. example: int iid = (int)oRow["iid"];
+ ///
+ ///
+ /// // You may also use oRow["cname"] directly
+ /// string cCustomer = CurVal("cname", oRow);
+ ///
+ ///
+ ///
+ ///
+ public static string CurVal(string tcField, System.Data.DataRow toRow)
+ {
+ return toRow[tcField].ToString();
+ }
+
+ ///
+ /// Returns the current order used to perform searches on the DataView
+ ///
+ ///
+ /// string CurrentOrder = vfpData.Order(oView);
+ ///
+ ///
+ ///
+ public static string Order(System.Data.DataView toView)
+ {
+ return toView.Sort;
+ }
+ public static string Order(){return Order(vfpData.oView);}
+
+ ///
+ /// Receives a string value and a DataView as parameters and searches the
+ /// DataView for that string using the current sort order. Unlike VFP,
+ /// this function does not change the position of the record but returns
+ /// the record number if a seek is successful. The function returns a -1
+ /// if the seek is unsuccessful
+ ///
+ ///
+ ///
+ ///
+ public static int Seek(string tcString, System.Data.DataView toView)
+ {
+ int nFound = 0;
+ nFound = toView.Find(tcString);
+
+ //If we seek is successful, update the Found flag and return the position
+ if(nFound != -1){vfpData._Found = true;}
+ return nFound;
+ }
+ public static int Seek(string tcString){return Seek(tcString, vfpData.oView);}
+
+
+ ///
+ /// Receives a ReturnField, SearchExpression and field to be searched a as parameters. The function
+ /// looks up a value and returns the value of the ReturnField on a successful
+ /// search. The function maintains the last Order() of the view.
+ /// Please note that unlike the VFP Lookup() command this one receives the ReturnField and SearchField as strings.
+ ///
+ ///
+ /// string cCustomer = vfpData.Lookup("cname", "60", "iid", oView)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string Lookup(string tcReturnField, string tcSearchExpression, string tcSearchedField, System.Data.DataView toView)
+ {
+ string cRetVal = "";
+
+ //Capture the current order
+ string cOrder = vfpData.Order(toView);
+
+ try
+ {
+ //Set the order to the search order
+ vfpData.SetOrderTo(tcSearchedField, toView);
+
+ int nFoundRec = vfpData.Seek(tcSearchExpression, toView);
+
+ //If we find a record then get the return value
+ if(nFoundRec != -1)
+ {
+ cRetVal = toView.Table.Rows[nFoundRec][tcReturnField].ToString();
+ vfpData._Found = true;
+ }
+ }
+ finally
+ {
+ //Cleanup to reset the old order
+ toView.Sort = cOrder;
+ }
+ return cRetVal;
+ }
+ public static string Lookup(string tcReturnField, string tcSearchExpression, string tcSearchedField){return vfpData.Lookup(tcReturnField, tcSearchExpression, tcSearchedField, vfpData.oView);}
+
+ ///
+ /// Receives the current position and DataView as parameters and returns a boolean specifying
+ /// if it is the last record
+ ///
+ ///
+ /// bool lEnd = vfpData.EOF(nCounter, oView);
+ ///
+ ///
+ ///
+ ///
+ public static bool EOF(int nRowNumber, System.Data.DataView toView)
+ {
+ //Handle zero based row position
+ return (nRowNumber == toView.Count);
+ }
+ public static bool EOF(int nRowNumber){ return EOF(nRowNumber, vfpData.oView);}
+
+ ///
+ /// Receives the current position and DataView as parameters and returns a boolean specifying
+ /// if it is the first record
+ ///
+ ///
+ /// bool lEnd = vfpData.EOF(nCounter, oView);
+ ///
+ ///
+ ///
+ ///
+ public static bool BOF(int nRowNumber, System.Data.DataView toView)
+ {
+ return (nRowNumber == 0);
+ }
+ public static bool BOF(int nRowNumber){ return BOF(nRowNumber, vfpData.oView);}
+
+
+ ///
+ /// Returns the alias that is specified in vfpData.oView property
+ ///
+ ///
+ public static string Alias()
+ {
+ string cRetVal = "";
+
+ if(vfpData.oView.GetType().ToString() == "System.Data.DataView")
+ {
+ cRetVal = vfpData.oView.Table.TableName;
+ }
+
+ return cRetVal;
+ }
+
+ ///
+ /// Receives a DataView as a parameter and returns if the current order
+ /// in the DataView is descending
+ ///
+ ///
+ /// bool IsDescending = vfpData.Descending(oView);
+ ///
+ ///
+ ///
+ public static bool Descending(System.Data.DataView toView)
+ {
+ string cCurrentOrder = toView.Sort;
+ return (cCurrentOrder.ToUpper().IndexOf(" DESC",0) > 0);
+ }
+ public static bool Descending(){return vfpData.Descending(vfpData.oView);}
+
+ ///
+ /// As ADO.NET does not support current position of cursors.
+ /// This functions performs the same action as that of a seek
+ ///
+ ///
+ ///
+ ///
+ public static int IndexSeek(string tcExpression, System.Data.DataView toView)
+ {
+ return vfpData.Seek(tcExpression, toView);
+ }
+ public static int IndexSeek(string tcExpression) {return vfpData.IndexSeek(tcExpression, vfpData.oView);}
+
+
+ ///
+ /// Receives a DataView as a parameter and specifies that for all the operations
+ /// that follow this will now be the default DataView
+ ///
+ ///
+ /// vfpData.Select(oView);
+ ///
+ ///
+ public static void Select(System.Data.DataView toView)
+ {
+ vfpData.oView = toView;
+ }
+
+ ///
+ /// Receives a DataView as a parameter and specifies if it is in read-only mode or not
+ ///
+ ///
+ ///
+ public static bool IsReadOnly(System.Data.DataView toView)
+ {
+ return toView.Table.Rows.IsReadOnly;
+ }
+ public static bool IsReadOnly(){return IsReadOnly(vfpData.oView);}
+
+
+ ///
+ /// Receives a record number and DataView as parameters and specifies if that
+ /// record is marked as deleted in the DataView
+ ///
+ ///
+ ///
+ ///
+ public static bool Deleted(int nRecNo, System.Data.DataView toView)
+ {
+ bool llRetVal = false;
+
+ //Store the current state of filter
+ DataViewRowState loCurrentState = toView.RowStateFilter;
+
+ toView.RowStateFilter = System.Data.DataViewRowState.Deleted;
+ llRetVal = (toView.Table.Rows[nRecNo].RowState.ToString() == "Deleted");
+
+ //reset to original state of filter
+ toView.RowStateFilter = loCurrentState;
+ return llRetVal;
+ }
+ public static bool Deleted(int nRecNo){return Deleted(nRecNo, vfpData.oView);}
+
+
+ ///
+ /// Receives a Filter expression and a DataView as parameters and applies that filter to the DataView
+ ///
+ ///
+ /// vfpData.SetFilterTo("cname like 'R%'", oView);
+ ///
+ ///
+ ///
+ public static void SetFilterTo(string tcFilterExpression, System.Data.DataView toView)
+ {
+ toView.RowFilter = tcFilterExpression;
+ vfpData._Filter = tcFilterExpression;
+ }
+ public static void SetFilterTo(string tcFilterExpression){ SetFilterTo(tcFilterExpression, vfpData.oView);}
+
+ ///
+ /// Receives a field name as a parameter and updates the order of sort in the DataView
+ ///
+ ///
+ ///
+ public static void SetOrderTo(string tcFieldName, System.Data.DataView toView)
+ {
+ toView.Sort = tcFieldName;
+ vfpData._Order = tcFieldName;
+ }
+ public static void SetOrderTo(string tcFieldName){SetOrderTo(tcFieldName, vfpData.oView);}
+
+ ///
+ /// Returns the number of records in the DataView. If a filter condition is passed
+ /// as a parameter, the function returns the count for that condition
+ ///
+ ///
+ ///
+ public static int Count(string tcFilterCondition, System.Data.DataView toView)
+ {
+ int nRetVal = 0;
+
+ //Store the current filter condition
+ string cCurrentFilter = toView.RowFilter;
+
+ toView.RowFilter = tcFilterCondition;
+ nRetVal = toView.Count;
+ toView.RowFilter = cCurrentFilter;
+
+ return nRetVal;
+ }
+ public static int Count(string tcFilterCondition){return Count(tcFilterCondition, vfpData.oView);}
+ public static int Count(System.Data.DataView toView){return toView.Count;}
+ public static int Count(){return vfpData.oView.Count;}
+
+
+ ///
+ /// Receives a DataView as a parameter and inserts an empty new record at the end
+ ///
+ ///
+ /// vfpData.AppendBlank(oView);
+ ///
+ ///
+ public static DataRow AppendBlank(System.Data.DataView toView)
+ {
+ DataRowView drv = toView.AddNew();
+ return drv.Row;
+ }
+ public static DataRow AppendBlank(){return AppendBlank(vfpData.oView); }
+
+ ///
+ /// Receives a DataView as a parameter and displays it in a Browse Form
+ ///
+ /// WinForms
+ ///
+ /// vfpData.Browse(oView);
+ ///
+ ///
+ public static void Browse(System.Data.DataView toView)
+ {
+ //Create a new form
+ BrowseForm oForm = new BrowseForm();
+ oForm.SetData(toView);
+ oForm.Show();
+ }
+ public static void Browse(){Browse(vfpData.oView);}
+
+
+ ///
+ /// Receives a record number and DataView as parameters and deletes that
+ /// record
+ ///
+ ///
+ ///
+ public static void Delete(int nRecNo, System.Data.DataView toView)
+ {
+ toView.Delete(nRecNo);
+ }
+ public static void Delete(int nRecNo){Delete(nRecNo, vfpData.oView);}
+
+ ///
+ /// Recalls all the changes made to the data. If a record is deleted then it
+ /// undeletes the record.
+ ///
+ ///
+ ///
+ public static void Recall(int nRecNo, System.Data.DataView toView)
+ {
+ toView.Table.Rows[nRecNo].RejectChanges();
+ }
+ public static void Recall(int nRecNo){Recall(nRecNo, vfpData.oView);}
+
+ ///
+ /// Returns a bool indicating the status of the last search/seek operation
+ ///
+ ///
+ public static bool Found()
+ {
+ return vfpData._Found;
+ }
+
+ ///
+ /// Receives a command type as a parameter and returns the current status
+ /// of SetFilter(), SetOrder() etc
+ ///
+ ///
+ ///
+ public static string Set(string tcCommandType)
+ {
+ switch(tcCommandType.ToUpper())
+ {
+ case "ORDER":
+ return vfpData._Order;
+ case "FILTER":
+ return vfpData._Filter;
+ }
+ return "";
+ }
+
+ ///
+ /// Receives a filter expression as a parameter and deletes all the records
+ /// for that filter condition
+ ///
+ ///
+ /// DeleteFor("cname like 'A*'");
+ ///
+ ///
+ ///
+ public static void DeleteFor(string cExpression, System.Data.DataView toView)
+ {
+ string lcOldFilter = Set("Filter");
+
+ //Update the Filter condition
+ SetFilterTo(cExpression);
+
+ //Loop through each record and delete it
+ foreach(System.Data.DataRow r in toView.Table.Rows)
+ {
+ r.Delete();
+ }
+
+ //Reset the filter condition
+ SetFilterTo(lcOldFilter);
+ }
+ public static void DeleteFor(string cExpression){DeleteFor(cExpression, vfpData.oView);}
+
+ ///
+ /// Deletes all the records in the DataView
+ ///
+ ///
+ /// DeleteAll(toView);
+ ///
+ ///
+ public static void DeleteAll(System.Data.DataView toView)
+ {
+ //Forward the call to delete for with a blank filter condition
+ vfpData.DeleteFor("");
+ }
+ public static void DeleteAll()
+ {
+ DeleteAll(vfpData.oView);
+ }
+
+ ///
+ /// Receives a DataSet and file name as a parameter and saves the xml of the
+ /// DataSet to a file. Returns the number of bytes copied.
+ ///
+ ///
+ /// CursorToXML(ds, "c:\MyData.xml")
+ ///
+ ///
+ ///
+ public static int CursorToXML(DataSet toDataSet, string tcFileName)
+ {
+ // The GetXml() method of the DataSet returns an XML string
+ // Call the Toolkit StrToFile() method to save this as a file
+ string lcXML = toDataSet.GetXml();
+ VFPToolkit.strings.StrToFile(lcXML, tcFileName);
+ return lcXML.Length;
+ }
+
+ ///
+ /// Receives an XML file and DataSet name as parameters and creates a DataSet
+ /// Instead of returning the number of records this one returns the DataSet
+ ///
+ ///
+ /// XMLtoCursor("c:\MyData.xml", "MyDataSet")
+ ///
+ ///
+ ///
+ public static DataSet XMLToCursor(string tcFileName, string tcDataSet)
+ {
+ DataSet ds = new DataSet(tcDataSet);
+ ds.ReadXml(tcFileName);
+ return ds;
+ }
+
+ ///
+ /// Receives a connection string as a parameter and establishes a connection to
+ /// the backend. Returns a connection object back
+ ///
+ ///
+ /// //Establish a connection and a command
+ /// string lcConnectionString;
+ /// string lcSQL;
+ /// OleDbConnection oConn;
+ ///
+ /// //Get the connection string and sql statement
+ /// lcConnectionString = "Provider=vfpoledb.1;Data Source='C:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc';password='';user id=''";
+ /// lcSQL = "Select * from customer";
+ ///
+ /// //Connect to the Database, execute the query and disconnect
+ /// //SqlConnect(), SqlExecute(), SqlDisconnect()
+ /// oConn = SqlConnect(lcConnectionString);
+ /// goView = SqlExecute(oConn, lcSQL, "CustomerList");
+ /// SqlDisConnect(oConn);
+ ///
+ /// //Select the default cursor and browse it
+ /// VFPToolkit.vfpData.Select(goView);
+ /// Browse();
+ ///
+ ///
+ ///
+ public static OleDbConnection SqlConnect(string tcConnectionString)
+ {
+ return new OleDbConnection(tcConnectionString);
+ }
+
+ ///
+ /// Receives a connection string as a parameter and establishes a connection to
+ /// the backend. Returns a connection object back
+ ///
+ ///
+ /// //Establish a connection and a command
+ /// string lcConnectionString;
+ /// string lcSQL;
+ /// OleDbConnection oConn;
+ ///
+ /// //Get the connection string and sql statement
+ /// lcConnectionString = "Provider=vfpoledb.1;Data Source='C:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc';password='';user id=''";
+ /// lcSQL = "Select * from customer";
+ ///
+ /// //Connect to the Database, execute the query and disconnect
+ /// //SqlConnect(), SqlExecute(), SqlDisconnect()
+ /// oConn = SqlConnect(lcConnectionString);
+ /// goView = SqlExecute(oConn, lcSQL, "CustomerList");
+ /// SqlDisConnect(oConn);
+ ///
+ /// //Select the default cursor and browse it
+ /// VFPToolkit.vfpData.Select(goView);
+ /// Browse();
+ ///
+ ///
+ ///
+ public static OleDbConnection SqlStringConnect(string tcConnectionString)
+ {
+ return SqlConnect(tcConnectionString);
+ }
+
+ ///
+ /// Receives a OleDbConnection object as a parameter and closes it
+ ///
+ ///
+ /// //Establish a connection and a command
+ /// string lcConnectionString;
+ /// string lcSQL;
+ /// OleDbConnection oConn;
+ ///
+ /// //Get the connection string and sql statement
+ /// lcConnectionString = "Provider=vfpoledb.1;Data Source='C:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc';password='';user id=''";
+ /// lcSQL = "Select * from customer";
+ ///
+ /// //Connect to the Database, execute the query and disconnect
+ /// //SqlConnect(), SqlExecute(), SqlDisconnect()
+ /// oConn = SqlConnect(lcConnectionString);
+ /// goView = SqlExecute(oConn, lcSQL, "CustomerList");
+ /// SqlDisConnect(oConn);
+ ///
+ /// //Select the default cursor and browse it
+ /// VFPToolkit.vfpData.Select(goView);
+ /// Browse();
+ ///
+ ///
+ public static void SqlDisConnect(OleDbConnection toConn)
+ {
+ toConn.Close();
+ }
+
+ ///
+ /// Receives an OleDbConnection and SQL string as parameters and executes the query
+ ///
+ ///
+ /// //Establish a connection and a command
+ /// string lcConnectionString;
+ /// string lcSQL;
+ /// OleDbConnection oConn;
+ ///
+ /// //Get the connection string and sql statement
+ /// lcConnectionString = "Provider=vfpoledb.1;Data Source='C:\\Program Files\\Microsoft Visual FoxPro 7\\Samples\\Data\\testdata.dbc';password='';user id=''";
+ /// lcSQL = "Select * from customer";
+ ///
+ /// //Connect to the Database, execute the query and disconnect
+ /// //SqlConnect(), SqlExecute(), SqlDisconnect()
+ /// oConn = SqlConnect(lcConnectionString);
+ /// goView = SqlExecute(oConn, lcSQL, "CustomerList");
+ /// SqlDisConnect(oConn);
+ ///
+ /// //Select the default cursor and browse it
+ /// VFPToolkit.vfpData.Select(goView);
+ /// Browse();
+ ///
+ ///
+ ///
+ ///
+ public static DataView SqlExecute(OleDbConnection toConn, String tcSQL)
+ {
+ return SqlExecute(toConn, tcSQL, "Query");
+ }
+
+ ///
+ /// Receives an OleDbConnection, an OleDbCommand and default view's name as parameters and executes the sql
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static DataView SqlExecute(OleDbConnection toConn, string tcSQL, string tcAlias)
+ {
+ OleDbCommand oCommand = new OleDbCommand(tcSQL, toConn);
+ return SqlExecute(toConn, oCommand, tcAlias);
+ }
+
+
+ ///
+ /// Receives an OleDbConnection and an OleDbCommand as parameters and executes the command
+ ///
+ ///
+ ///
+ ///
+ public static DataView SqlExecute(OleDbConnection toConn, OleDbCommand toCommand)
+ {
+ return SqlExecute(toConn, toCommand, "Query");
+ }
+
+ ///
+ /// Receives an OleDbConnection, an OleDbCommand and default view's name as parameters and executes the command
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static DataView SqlExecute(OleDbConnection toConn, OleDbCommand toCommand, string tcAlias)
+ {
+ ///Open the connection and create a new DataAdapter
+ toConn.Open();
+ OleDbDataAdapter da = new OleDbDataAdapter(toCommand);
+
+ //Create a blank DataSet and fill the DataSet with the data
+ DataSet ds = new DataSet();
+ da.Fill(ds, tcAlias);
+
+ //Return the DataView
+ return ds.Tables[0].DefaultView;
+ }
+
+ ///
+ ///
+
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.csproj b/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.csproj
index d13f285..8dfa29f 100644
--- a/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.csproj
+++ b/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.csproj
@@ -20,10 +20,11 @@
- v2.0
+ v4.8
0.0
+
bin\Debug\
@@ -42,6 +43,7 @@
4
full
prompt
+ false
bin\Release\
@@ -60,6 +62,7 @@
4
none
prompt
+ false
diff --git a/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.sln b/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.sln
index e497a23..f484c7b 100644
--- a/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.sln
+++ b/VFPToolkitNET_CSharpNET_Source/VFPToolkitNET_CSharpNET_Source.sln
@@ -1,9 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28307.489
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VFPToolkitNET_CSharpNET_Source", "VFPToolkitNET_CSharpNET_Source.csproj", "{CA9F2B40-9CBD-488B-90BC-99296FBEDD07}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VFPToolkitNET_CSharpNET_Standard", "..\VFPToolkitNET_CSharpNET_Standard\VFPToolkitNET_CSharpNET_Standard.csproj", "{35639CE0-EDDF-4FE5-9530-4C851EC9F0E3}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VFPToolkitNET_CSharpNET_NetCore", "..\VFPToolkitNET_CSharpNET_NetCore\VFPToolkitNET_CSharpNET_NetCore.csproj", "{E2D0F8BA-1FDC-4596-9922-F2BEF9069FC0}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -14,6 +18,14 @@ Global
{CA9F2B40-9CBD-488B-90BC-99296FBEDD07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA9F2B40-9CBD-488B-90BC-99296FBEDD07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA9F2B40-9CBD-488B-90BC-99296FBEDD07}.Release|Any CPU.Build.0 = Release|Any CPU
+ {35639CE0-EDDF-4FE5-9530-4C851EC9F0E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {35639CE0-EDDF-4FE5-9530-4C851EC9F0E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {35639CE0-EDDF-4FE5-9530-4C851EC9F0E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {35639CE0-EDDF-4FE5-9530-4C851EC9F0E3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E2D0F8BA-1FDC-4596-9922-F2BEF9069FC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E2D0F8BA-1FDC-4596-9922-F2BEF9069FC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E2D0F8BA-1FDC-4596-9922-F2BEF9069FC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E2D0F8BA-1FDC-4596-9922-F2BEF9069FC0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/VFPToolkitNET_CSharpNET_Standard/Arrays.cs b/VFPToolkitNET_CSharpNET_Standard/Arrays.cs
new file mode 100644
index 0000000..e2b1f79
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Arrays.cs
@@ -0,0 +1,449 @@
+using System;
+using System.IO;
+using System.Drawing;
+using System.Drawing.Text;
+using System.Drawing.Printing;
+using System.Collections;
+using System.Diagnostics;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro Array Functions
+ /// This class contains all the functions that allow us to work with arrays such as ALen(), ASort(), ACopy(), AScan() etc.
+ /// It also contains functions that return arrays such as ADir(), APrinter() and AFonts().
+ ///
+ public class arrays
+ {
+ ///
+ /// Inserts an element into a one-dimensional array, or a row or column into a two-dimensional array
+ ///
+ public static void AIns(ref Array aArray, int nElementNumber)
+ {
+ //In this case we add a row to the array
+ Array retarr = Array.CreateInstance(typeof(String),aArray.Length + 1);
+
+ int i,j = 0 ;
+ for (i = 0; i < aArray.Length ; i++)
+ {
+ if (i == nElementNumber)
+ {
+ retarr.SetValue("",j);
+ j++;
+ }
+ retarr.SetValue(aArray.GetValue(i),j);
+ j++;
+ }
+
+ aArray = retarr;
+ }
+
+ ///
+ /// Returns the number of elements, rows, or columns in an array.
+ ///
+ /// Example:
+ /// //Create an array and fill it up with data
+ /// Array MyArr = Array.CreateInstance(typeof(String), 4);
+ /// MyArr.SetValue("YAG", 0); //Note that this is zero based
+ /// MyArr.SetValue("Kamal", 1);
+ /// MyArr.SetValue("Rick", 2);
+ /// MyArr.SetValue("Matt", 3);
+ ///
+ /// //Now Get the Length
+ /// VFPToolkit.arrays.ALen(MyArr); //returns 4
+ ///
+ ///
+ public static int ALen(System.Array aArray)
+ {
+ return aArray.Length;
+ }
+ ///
+ /// Returns the number of elements, rows, or columns in an array. Implements the optional
+ /// parameter for number of rows for columns
+ ///
+ /// Example:
+ /// VFPToolkit.arrays.ALen(MyArr, 1);
+ ///
+ ///
+ public static int ALen(System.Array aArray, int nArrayAttribute)
+ {
+ //switch based on the value of nArrayAttribute
+ switch (nArrayAttribute)
+ {
+ case 1:
+ {
+ //Return the number of rows in the array
+ //return (aArray.Length / aArray.Rank);
+ return aArray.GetUpperBound(0) + 1;
+ }
+ case 2:
+ {
+ //Return the number of columns
+ return aArray.Rank;
+ }
+ default:
+ {
+ return aArray.Length;
+ }
+ }
+ }
+
+ ///
+ /// Sorts elements in an array in ascending or descending order
+ ///
+ /// Example:
+ /// //Pass the array by reference and the method sorts the contents of the array
+ /// VFPToolkit.arrays.ASort(ref MyArr);
+ ///
+ ///
+ public static void ASort(ref Array aArray)
+ {
+ Array.Sort(aArray);
+ }
+
+ ///
+ /// Receives two arrays as parameters by reference and copies the contents from one array to another array.
+ ///
+ /// Example:
+ /// VFPToolkit.arrays.Acopy(ref MySourceArr, ref MyDestinationArr);
+ ///
+ ///
+ public static int ACopy(ref Array aSource, ref Array aDestination)
+ {
+ //Check if the destination array is null and if so then initialize it
+ if(aDestination == null)
+ aDestination = Array.CreateInstance(typeof(System.Object), 1);
+
+ //Check the length of the destination and if the source length is
+ //greater than the destination then ititialize it
+ if(aSource.Length > aDestination.Length)
+ aDestination = Array.CreateInstance(typeof(System.Object), aSource.Length);
+
+ //Now copy the array
+ Array.Copy(aSource, aDestination, aSource.GetUpperBound(0) + 1);
+
+ //Return the length
+ return aDestination.Length;
+ }
+ ///
+ /// Receives two arrays as parameters by reference and copies the contents from one array to another array.
+ /// The nFirstElement specifies which should be the first element in the source array to begin the copying process.
+ ///
+ /// Example:
+ /// VFPToolkit.arrays.Acopy(ref MySourceArr, ref MyDestinationArr, 2); //Begins copying from 2nd position in source array
+ ///
+ ///
+ public static int ACopy(ref Array aSource, ref Array aDestination, int nFirstSourceElement)
+ {
+ //Check if the destination array is null and if so then initialize it
+ if(aDestination == null)
+ aDestination = Array.CreateInstance(typeof(System.Object), 1);
+
+ //Check the length of the destination and if the source length is
+ //greater than the destination then ititialize it
+ if(aSource.Length - nFirstSourceElement > aDestination.Length)
+ aDestination = Array.CreateInstance(typeof(System.Object), aSource.Length - (nFirstSourceElement-1));
+
+ Array.Copy(aSource,nFirstSourceElement - 1,aDestination,0,aSource.GetUpperBound(0) + 2 - nFirstSourceElement);
+ return aDestination.Length;
+ }
+ ///
+ /// Receives two arrays as parameters by reference and copies the contents from one array to another array.
+ /// The nFirstElement specifies which should be the first element in the source array to begin the copying process.
+ /// The nNumbeOfSourceElement specifies how many items from the source array should be copied.
+ ///
+ /// Example:
+ /// //Begins copying from 2nd position in source array and copies on 3 items from that position onwards
+ /// VFPToolkit.arrays.Acopy(ref MySourceArr, ref MyDestinationArr, 2, 3);
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int ACopy(ref Array aSource, ref Array aDestination, int nFirstSourceElement, int nNumberOfSourceElements)
+ {
+ //Check if the destination array is null and if so then initialize it
+ if(aDestination == null)
+ aDestination = Array.CreateInstance(typeof(System.Object), 1);
+
+ //Check the length of the destination and if the source length is
+ //greater than the destination then ititialize it
+ if(nNumberOfSourceElements > aDestination.Length)
+ aDestination = Array.CreateInstance(typeof(System.Object), nNumberOfSourceElements);
+
+ Array.Copy(aSource,nFirstSourceElement - 1,aDestination, 0, nNumberOfSourceElements);
+ return aDestination.Length;
+ }
+ ///
+ /// Receives two arrays as parameters by reference and copies the contents from one array to another array.
+ /// The nFirstElement specifies which should be the first element in the source array to begin the copying process.
+ /// The nNumbeOfSourceElement specifies how many items from the source array should be copied.
+ /// The nFirstDestElement specifies the position in the destination array to begin the updating process.
+ ///
+ /// Example:
+ /// //Begins copying from 2nd position in source array and copies on 3 items from that position onwards.
+ /// //Does not touch the 1st items in the destination array and starts from 2nd position
+ /// VFPToolkit.arrays.Acopy(ref MySourceArr, ref MyDestinationArr, 2, 3, 2);
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int ACopy(ref Array aSource, ref Array aDestination, int nFirstSourceElement, int nNumberOfSourceElements, int nFirstDestElement)
+ {
+ //Check if the destination array is null and if so then initialize it
+ if(aDestination == null)
+ aDestination = Array.CreateInstance(typeof(System.Object), 1);
+
+ //Check the length of the destination and if the source length is
+ //greater than the destination then ititialize it
+ if(nNumberOfSourceElements + nFirstDestElement + 1> aDestination.Length)
+ aDestination = Array.CreateInstance(typeof(System.Object), nNumberOfSourceElements + nFirstDestElement);
+
+ Array.Copy(aSource,nFirstSourceElement - 1,aDestination,nFirstDestElement - 1,nNumberOfSourceElements);
+ return aDestination.Length;
+ }
+
+ ///
+ /// Deletes an element from a one-dimensional array, or a row or column from a two-dimensional array.
+ /// (Currently this does not implement the third parameter to remove an entire column.)
+ ///
+ /// Example:
+ /// VFPToolkit.arrays.ADel(ref myArr, 2);
+ ///
+ ///
+ public static bool ADel(ref Array aArray, int nElementNumber)
+ {
+ //Forward the call passing the default parameter
+ return ADel(ref aArray, nElementNumber, 1);
+ }
+
+ public static bool ADel(ref Array aArray, int nElementNumber, int nRemoveColumn)
+ {
+ bool llRetVal = false;
+ try
+ {
+ //Check if we have to delete a column or a row
+ //VFP has the third parameter as 2. It does not makes sense,
+ //should have been a binary value
+ if(nRemoveColumn != 2)
+ {
+ //Delete the item from the array and update the content of that element with bool false
+ Array.Clear(aArray,nElementNumber,1);
+ aArray.SetValue(llRetVal, nElementNumber);
+ llRetVal = true;
+ }
+ else
+ {
+ //Delete a column
+ int nColumn = nElementNumber - 1;
+ // We actually don't change the length of the array
+ int nTotalColumns = aArray.Rank;
+
+ //Begin the move
+ for(int i=nColumn; i<= nTotalColumns ; i++)
+ {
+ for(int j=0; j< aArray.GetLength(0)-1; j++)
+ {
+ aArray.SetValue(aArray.GetValue(i+1, j), i, j);
+ aArray.SetValue("", i+1, j);
+ }
+ }
+ }
+ }
+ catch
+ {
+ //Something went wrong
+ llRetVal = false;
+ }
+
+ return llRetVal;
+ }
+
+ ///
+ /// Searches for an item in the array and returns the position of that item
+ /// Please note that AScan() returns a zero based value
+ ///
+ /// Example:
+ /// VFPToolkit.arrays.Ascan(ref MyArr, "Rick");
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AScan(ref Array aArray, object toObject)
+ {
+ return Array.IndexOf(aArray, toObject);
+ }
+
+ public static int AScan(ref Array aArray, object toObject, int nStartElement)
+ {
+ return Array.IndexOf(aArray, toObject, nStartElement);
+ }
+
+ public static int AScan(ref Array aArray, object toObject, int nStartElement, int nElementSearched)
+ {
+ int i;
+ bool llFound = false;
+
+ //Compare the items manually
+ for (i=nStartElement; i < nStartElement + nElementSearched ; i++) //Length is 1 based so only < sign
+ {
+ if(aArray.GetValue(i) == toObject)
+ {
+ llFound = true;
+ break;
+ }
+ }
+ return llFound == true ? i : -1;
+ }
+
+ ///
+ /// Copies each line in a character expression or memo field to a corresponding row in an array.
+ /// ALines() also returns a zero based length of the array.
+ ///
+ /// Example:
+ /// //Get the contents of a file into a string
+ /// string cString = VFPToolkit.strings.FileToStr("c:\\MyFile.txt");
+ ///
+ /// string[] myArr; //Declare an array
+ /// int nCount = 0 ;
+ ///
+ /// //Call Alines() and fill each line in the text file as an item in the array
+ /// nCount = VFPToolkit.arrays.ALines(out myArr, cString, VFPToolkit.strings.Chr(13));
+ ///
+ ///
+ public static int ALines(out string[] aArray, string cExpression, string cParseString)
+ {
+ //Initialize a blank array
+ int i = 0;
+ aArray = new string[0];
+ char[] aParseChar = new char[cParseString.Length];
+ for ( i=0 ; i
+ /// Receives a file skeleton as a parameter and returns an array of files that match the skeleton.
+ ///
+ /// Example:
+ /// string[] myArr;
+ /// myArr = VFPToolkit.arrays.ADir("c:\\*.*");
+ ///
+ ///
+ ///
+ ///
+ public static string[] ADir(string cFileSkeleton)
+ {
+ string[] aFiles;
+ string lcDrive = VFPToolkit.strings.SubStr(cFileSkeleton, 1,VFPToolkit.strings.RAt("\\", cFileSkeleton));
+ string lcStem = VFPToolkit.strings.SubStr(cFileSkeleton, strings.RAt("\\", cFileSkeleton) + 1);
+ aFiles = System.IO.Directory.GetFiles(lcDrive, lcStem);
+ return aFiles;
+ }
+
+ ///
+ /// Returns a array containing a list of all the fonts installed in the system.
+ ///
+ /// Example:
+ /// string[] MyFontsArr;
+ /// int nTotalFonts = VFPToolkit.arrays.AFonts(out MyFontsArr);
+ ///
+ ///
+ ///
+ ///
+ public static int AFont(out string[] aArray)
+ {
+ //
+ //Note: You could return the FontFamily array and use the font objects directy and it would make things easier
+
+ //Initialize the InstalledFontCollection object
+ InstalledFontCollection fc = new InstalledFontCollection();
+
+ //Create an empty FontFamily array and fill it up
+ FontFamily[] afm;
+ afm = fc.Families;
+
+ //RE Initialize a string array
+ aArray = new string[afm.Length];
+
+ //loop through the array of fonts and fill the font names
+ int i = 0;
+ for (i=0; i< afm.Length; i++)
+ {
+ aArray.SetValue(afm[i].Name, i);
+ }
+
+ //Return the number of fonts
+ return i + 1;
+ }
+
+ ///
+ /// Fills an array with all the printers that can be accessed by this machine.
+ ///
+ /// Example:
+ /// string[] MyPrinters;
+ /// int nCount = VFPToolkit.arrays.APrinters(out MyPrinters);
+ ///
+ ///
+ ///
+ ///
+ public static int APrinters(out string[] aArray)
+ {
+ //Initialize the PrinterSettings object
+ PrinterSettings oPrtSettings = new PrinterSettings();
+
+ IEnumerator se = System.Drawing.Printing.PrinterSettings.InstalledPrinters.GetEnumerator();
+ int i = 0;
+
+ //simply count in the first round
+ while (se.MoveNext())
+ i++;
+
+ //update the array now
+ aArray = new string[i];
+ i = 0;
+ se.Reset();
+ while (se.MoveNext())
+ {
+ aArray[i] = se.Current.ToString();
+ i++;
+ }
+
+
+ //Return a 1 based length
+ return aArray.Length;
+ }
+ ///
+ ///
+ //End of arrays class
+
+ }
+
+ //End of vfp Namespace
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Common.cs b/VFPToolkitNET_CSharpNET_Standard/Common.cs
new file mode 100644
index 0000000..4032f29
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Common.cs
@@ -0,0 +1,530 @@
+using System;
+using System.Windows.Forms;
+using System.Windows.Forms.Design;
+using System.Text;
+using System.ComponentModel;
+using System.Collections;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro Common Functions
+ /// This class contains implementions of those functions that are common. Functions such as Between(),
+ /// InList() receive any datatype and return values are included here. Also functions
+ /// such as VarType(), Empty() that check for any data type are also included in this class.
+ ///
+ public class common
+ {
+ ///
+ /// Receives an object (string, int etc.) as a parameter and returns the datatype of that object.
+ /// Unlike VFP, this method returns the .NET type. So, for a string object it
+ /// will return "System.String" and not "C". This will allow you to get the type
+ /// of any object including custom classes you develop. For a string object,
+ /// this method will return "System.String" instead of a "C" in VFP.
+ ///
+ /// Example:
+ /// VFPToolkit.common.VarType(MyObject); //returns the type of object
+ ///
+ ///
+ ///
+ ///
+ public static string VarType(object oObj)
+ {
+ //Return a string that specifies the type of the object
+ if(oObj == null)
+ return "null";
+ else
+ return oObj.GetType().ToString();
+ }
+
+ ///
+ /// Returns the type of the object. (Please note that currently this method does not receive
+ /// a string and then evaluates the type of object. It simply forwards the call to VarType(oObj).
+ ///
+ /// Example:
+ /// VFPToolkit.common.Type(MyObject); //returns the type of object
+ ///
+ ///
+ ///
+ ///
+ public static string Type(object oObj)
+ {
+ return VarType(oObj);
+ }
+ ///
+ /// Returns a bool indicating if the object is null or not
+ ///
+ /// Example:
+ /// VFPToolkit.common.IsNull(MyObject);
+ ///
+ ///
+ ///
+ ///
+ public static bool IsNull(object oObj)
+ {
+ return (oObj == null);
+ }
+ ///
+ /// Receives two objects as parameters and returns the one which is not null. If both of them are null
+ /// then returns a null, if the first one is not null then returns the first object.
+ ///
+ /// Example:
+ /// string myNullObj; //The string is not initialized yet
+ /// VFPToolkit.common.NVL("mystring", myNullObj); //returns mystring object
+ /// Note: All strings, int, long etc. all of them are objects
+ ///
+ ///
+ ///
+ ///
+ public static object NVL(object oExp1, object oExp2)
+ {
+ //if oExp1 is not null then return oExp1
+ if (oExp1 != null)
+ {
+ return oExp1;
+ }
+ else if ((oExp1 == null) && (oExp2 != null))
+ {
+ //If oExp1 is null return oExp2
+ return oExp2;
+ }
+ else
+ //If both of them are null return nothing
+ return null;
+ }
+ ///
+ /// Receives a key (string format) as a parameter and sends the key to the currently active form.
+ ///
+ /// Example:
+ /// VFPToolkit.common.KeyBoard("Kamal"); //If we are in a textbox this code will add "Kamal" to the textbox
+ ///
+ /// Tip: In order to get a listing of all the keys and their formats look for System.Windows.Forms.SendKeys class
+ ///
+ /// WinForms
+ ///
+ public static void KeyBoard(string cKey)
+ {
+ try
+ {
+ //Call the Send() method passing the key as a parameter
+ System.Windows.Forms.SendKeys.Send(cKey);
+ }
+ catch
+ {
+ //Do not throw an exception simply return a false
+ MessageBox.Show("An error occured while sending the key: " + cKey, "KeyPress Error", MessageBoxButtons.OK);
+ }
+ }
+
+
+ ///
+ /// Returns a logical value indicating if an integer is 0 or not
+ ///
+ ///
+ ///
+ public static bool Empty(int nValue)
+ {
+ return (nValue == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a long is 0 or not
+ ///
+ ///
+ ///
+ public static bool Empty(long nValue)
+ {
+ return (nValue == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a double is 0 or not
+ ///
+ ///
+ ///
+ public static bool Empty(double nValue)
+ {
+ return (nValue == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a decimal is 0 or not
+ ///
+ ///
+ ///
+ public static bool Empty(decimal nValue)
+ {
+ return (nValue == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a string is blank or not
+ ///
+ ///
+ ///
+ public static bool Empty(string tcString)
+ {
+ string lcString = tcString.Trim();
+ return (lcString.Length == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a character is a blank space or not
+ ///
+ ///
+ ///
+ public static bool Empty(char lcChar)
+ {
+ return (lcChar == ' ');
+ }
+ ///
+ /// Returns a logical value indicating if a logical value is a true or not
+ ///
+ ///
+ ///
+ public static bool Empty(bool lValue)
+ {
+ return (lValue == false);
+ }
+ ///
+ /// Returns a logical value indicating if an integer is 0 or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(int nValue)
+ {
+ return Empty(nValue);
+ }
+ ///
+ /// Returns a logical value indicating if a long is 0 or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(long nValue)
+ {
+ return Empty(nValue);
+ }
+ ///
+ /// Returns a logical value indicating if a double is 0 or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(double nValue)
+ {
+ return Empty(nValue);
+ }
+ ///
+ /// Returns a logical value indicating if a decimal is 0 or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(decimal nValue)
+ {
+ return Empty(nValue);
+ }
+ ///
+ /// Returns a logical value indicating if a string is blank or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(string tcString)
+ {
+ //Does not check for string with blank spaces
+ return (tcString.Length == 0);
+ }
+ ///
+ /// Returns a logical value indicating if a character is a blank space or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(char lcChar)
+ {
+ return Empty(lcChar);
+ }
+ ///
+ /// Returns a logical value indicating if a character is a blank space or not
+ ///
+ ///
+ ///
+ public static bool IsBlank(bool lValue)
+ {
+ return Empty(lValue);
+ }
+
+
+ ///
+ /// Returns the default CodePage being used.
+ /// (Currently, the optional parameter that returns Application or OS codepage is not implemented.)
+ ///
+ /// Example:
+ /// VFPToolkit.common.CPCurrent(); //returns an integer with the CodePage being used
+ ///
+ ///
+ ///
+ public static int CPCurrent()
+ {
+ return System.Text.Encoding.Default.CodePage ;
+ }
+
+ ///
+ /// Converts a string in one CodePage to another. This method receives three parameters; a string which is to
+ /// be converted, the current code page number and the new code page number.
+ ///
+ /// Example:
+ /// string MyString = "äää";
+ /// VFPToolkit.others.CPConvert(1252, 10000, MyString); //Converts the string from Windows CP to Mac CP
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string CPConvert(int nCurrentCodePage, int nNewCodePage, string cExpression)
+ {
+ int i=0;
+ int nLength = cExpression.Length;
+
+ //Create a current and new array of bytes with the length of the string
+ byte[] aCurr = new byte[nLength];
+ byte[] aNew = new byte[nLength];
+
+ //Fill the current array from the string
+ for (i=0; i< cExpression.Length; i++)
+ {
+ aCurr[i] = Convert.ToByte(cExpression[i]);
+ }
+
+ //Get the encoding objects for the current and new Code Pages
+ Encoding CurCP = Encoding.GetEncoding(nCurrentCodePage);
+ Encoding NewCP = Encoding.GetEncoding(nNewCodePage);
+
+ //Fill the new array after converting current code page to new code page
+ aNew = Encoding.Convert(CurCP, NewCP, aCurr);
+
+ //We still have bytes so we convert each byte to a char and add it to a string builder
+ StringBuilder sb = new StringBuilder();
+ for (i=0; i< cExpression.Length; i++)
+ {
+ sb.Append(Convert.ToChar(aNew[i]));
+ }
+
+ //Return a string back
+ return sb.ToString();
+
+ }
+
+
+ ///
+ /// Returns a bool specifying whether a property/method/event exists in an object.
+ /// (Currently this method does not implement all the parameters.)
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// //Create a new listbox
+ /// ListBox lstMyListBox;
+ /// lstMyListBox = new ListBox();
+ ///
+ /// //Check if the listbox has a ForeColor or MyColor property
+ /// VFPToolkit.common.GetPem(lstMyListBox,"ForeColor"); //return true
+ /// VFPToolkit.common.GetPem(lstMyListBox,"MyColor"); //return false
+ ///
+ public static bool GetPem(object oObject, string cPropertyEventMethodName)
+ {
+ //Get a list of all the properties in this object
+ PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(oObject);
+
+ //Beta 1 code
+ //PropertyDescriptor[] pda = TypeDescriptor.GetProperties(oObject).All;
+
+ //Loop through the properties an check if our property exists
+ foreach (MemberDescriptor md in pdc)
+ {
+ if (md.Name.ToLower() == cPropertyEventMethodName.ToLower())
+ {
+ //This means that we found our property
+ return true;
+ }
+ }
+
+ //Now we check for event name in this object
+ //Get a list of all the events/methods in this object
+ EventDescriptorCollection edc= TypeDescriptor.GetEvents(oObject);
+
+ //Loop through the events/methods an check if our event/method exists
+ foreach (EventDescriptor ed in edc)
+ {
+ if (ed.Name.ToLower() == cPropertyEventMethodName.ToLower())
+ {
+ //This means that we found our event/method
+ return true;
+ }
+ }
+
+ //If we reached here this means that we did not find our event/method/property
+ return false;
+ }
+
+
+ ///
+ /// This method receives three parameters and returns a color object from those values.
+ /// In VFP, this method returned a value whereas, in this case we are actually returning
+ /// a System.Drawing.Color object.
+ ///
+ /// Example:
+ /// Color o = VFPToolkit.common.RGB(255,255,255);
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static System.Drawing.Color RGB(int R, int G, int B)
+ {
+ return System.Drawing.Color.FromArgb(R,G,B);
+ }
+
+ ///
+ /// Receives an expression, low and high values and return a bool specifying
+ /// if the value was between the low and high values. This contains overloads
+ /// for int, float, decimal, char, date and string data types.
+ ///
+ /// Example:
+ /// if(VFPToolkit.common.Between(5,7,29))....
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool Between(int tnExpression, int tnLowValue, int tnHighValue)
+ {
+ return ((tnExpression >= tnLowValue) && (tnExpression <= tnHighValue));
+ }
+ public static bool Between(double tnExpression, double tnLowValue, double tnHighValue)
+ {
+ return ((tnExpression >= tnLowValue) && (tnExpression <= tnHighValue));
+ }
+ public static bool Between(decimal tnExpression, decimal tnLowValue, decimal tnHighValue)
+ {
+ return ((tnExpression >= tnLowValue) && (tnExpression <= tnHighValue));
+ }
+
+ // Compares between for date range
+ public static bool Between(System.DateTime tdDateTime, System.DateTime tdStartDate, System.DateTime tdEndDate)
+ {
+ return ((tdDateTime >= tdStartDate) && (tdDateTime <= tdEndDate));
+ }
+
+ // Compares between for char
+ public static bool Between(char tcChar, char tcLowChar, char tcHighChar)
+ {
+ return (((int)tcChar >= (int)tcLowChar) && ((int)tcChar <= (int)tcHighChar));
+ }
+
+ // Compares between for strings
+ // The way strings are compared in VFP is interesting
+ public static bool Between(string tcExpression, string tcStart, string tcEnd)
+ {
+ bool llRetVal = true;
+
+ // We start with the start string, tcStart, and compare each character in this
+ // with tcExpression. If we fail at anytime we return a false
+ for(int i = 0; i< tcStart.Length; i++)
+ {
+ if(tcStart[i] < tcExpression[i] )
+ {
+ llRetVal = false;
+ break;
+ }
+
+ //if we have reached the end of tcExpression break
+ if(i == tcExpression.Length)
+ break;
+ }
+
+
+ // The way strings are compared in VFP is interesting
+ // We start with the start string, tcStart, and compare each character in this
+ // with tcExpression. If we fail at anytime we return a false
+ for(int i = 0; i< tcEnd.Length; i++)
+ {
+ if(tcEnd[i] > tcExpression[i] )
+ {
+ llRetVal = false;
+ break;
+ }
+
+ //if we have reached the end of tcExpression break
+ if(i == tcExpression.Length)
+ break;
+ }
+
+ return llRetVal;
+
+ }
+
+
+ ///
+ /// Receives a MethodInfo as a parameter and returns the number of parameters for
+ /// that method. Instead of calling this method by passing the MethodInfo you can also use
+ /// System.Reflection.MethodBase.GetCurrentMethod().GetParameters().Length;
+ /// right from your method to get the parameter count.
+ ///
+ ///
+ /// private string GetStatus(string tcCustomer)
+ /// {
+ /// //Gets the number of parameters for this method. In this case 1
+ /// int lnPCount = VFPToolkit.common.PCount(System.Reflection.MethodBase.GetCurrentMethod());
+ /// }
+ ///
+ ///
+ ///
+ public static int PCount(System.Reflection.MethodBase mb)
+ {
+ return mb.GetParameters().Length;
+ }
+
+ ///
+ /// Receives a MethodInfo as a parameter and forwards the call to PCount to get
+ /// the number of parameters for that method
+ ///
+ ///
+ /// private string GetStatus(string tcCustomer)
+ /// {
+ /// //Gets the number of parameters for this method. In this case 1
+ /// int lnPCount = VFPToolkit.common.Parameters(System.Reflection.MethodBase.GetCurrentMethod());
+ /// }
+ ///
+ ///
+ ///
+ public static int Parameters(System.Reflection.MethodBase ms)
+ {
+ return PCount(ms);
+ }
+
+ ///
+ /// Receives an expression and a list of values as parameter and returns a true
+ /// if the expression exists in the list. Please note that the Visual FoxPro's
+ /// InList() function has a limitation of 23 items whereas this one does not have
+ /// a limitation on the number of items passed.
+ ///
+ ///
+ /// Console.WriteLine(InList("Kamal", "Pat", "abc", "Kamal")); //returns true
+ /// Console.WriteLine(InList("Kamal", "Pat", "abc", "xyz")); //returns false
+ /// Console.WriteLine(InList(123, 12, 13, 16, 1717, 123)); //returns true
+ ///
+ ///
+ ///
+ ///
+ public static bool InList(object toExpression, params object[] toItems)
+ {
+ return Array.IndexOf(toItems, toExpression) > -1;
+ }
+
+ ///
+ ///
+
+ //End of class
+ }
+
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Dates.cs b/VFPToolkitNET_CSharpNET_Standard/Dates.cs
new file mode 100644
index 0000000..3c74887
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Dates.cs
@@ -0,0 +1,353 @@
+using System;
+using System.Globalization;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro Date/Time Functions
+ /// This class contains all the functions that allow us to work with dates, time, datetime, character dates etc.
+ /// Class contains methods that return Date(), DateTime(), Time(), Day(), Month(), Year(), CDOW(), Quarter(),
+ /// Sec(), CMonth() etc. It also contains functions such as MDY(), DMY() and GoMonth()
+ ///
+ public class dates
+ {
+
+ ///
+ /// Receives a date in string format as a parameter and converts it to a DateTime format
+ ///
+ /// Example:
+ /// string lcDate = "4/12/01";
+ /// DateTime MyDate = VFPToolkit.dates.CTOT(lcDate); //converts the string to a DateTime value
+ ///
+ ///
+ ///
+ public static System.DateTime CTOT(string cDateTime)
+ {
+ return System.DateTime.Parse(cDateTime);
+ }
+
+ ///
+ /// Receives a date in string format as a parameter and returns the current day of week as a string
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string lcCurrentDay = VFPToolkit.dates.CDOW(tDateTime); //returns "Wednesday"
+ ///
+ ///
+ ///
+ ///
+ public static string CDOW(System.DateTime dDate)
+ {
+ return dDate.DayOfWeek.ToString();
+ }
+
+ ///
+ /// Receives a DateTime as a parameter and returns the current month formatted as a string
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string lcDate = VFPToolkit.dates.CMonth(tDateTime); //returns "May"
+ ///
+ ///
+ ///
+ ///
+ public static string CMonth(System.DateTime dDate)
+ {
+ return dDate.ToString("MMMM");
+ }
+
+ ///
+ /// Receives a date in string format as a parameter and converts it to a DateTime format
+ ///
+ /// Example:
+ /// string lcDate = "4/12/01";
+ /// DateTime MyDate = VFPToolkit.dates.CTOT(lcDate); //converts the string to a DateTime value
+ ///
+ ///
+ ///
+ ///
+ public static System.DateTime CTOD(string tcDate)
+ {
+ return System.DateTime.Parse(tcDate);
+ }
+
+ ///
+ /// Returns the current Date in System.DateTime format. (Use System.DateTime.Today instead)
+ ///
+ ///
+ public static System.DateTime Date()
+ {
+ return System.DateTime.Today;
+ }
+
+ ///
+ /// Returns the current DateTime in System.DateTime format. (Use System.DateTime.Now instead)
+ ///
+ ///
+ public static System.DateTime DateTime()
+ {
+ return System.DateTime.Now;
+ }
+
+ ///
+ /// Returns the current Day from a DateTime (Use MyDate.Day instead)
+ ///
+ ///
+ public static int Day(System.DateTime dDate)
+ {
+ return dDate.Day;
+ }
+
+
+ ///
+ /// Receives a DateTime as a parameter and returns a string formatted as a DMY
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string cDate = VFPToolkit.dates.CMonth(tDateTime); //returns "09 May 01"
+ ///
+ ///
+ ///
+ ///
+ public static string DMY(System.DateTime dDate)
+ {
+ return dDate.ToString("dd MMM yy");
+ }
+
+ ///
+ /// Receives a Date as a parameter and returns a string of that date. (Use MyDate.ToShortDateString() instead)
+ ///
+ ///
+ ///
+ public static string DTOC(System.DateTime dDate)
+ {
+ return dDate.ToShortDateString();
+ }
+
+ ///
+ /// Receives a DateTime as a parameter and returns a DTOS formatted string
+ ///
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string cDate = VFPToolkit.dates.DTOS(tDateTime); //returns "20010509"
+ ///
+ ///
+ ///
+ public static string DTOS(System.DateTime dDate)
+ {
+ return dDate.ToString("yyyyMMdd");
+ }
+
+ ///
+ /// This is simply a placeholder. VFP had Date and DateTime as separate datatypes. Now there
+ /// is no difference here as there is only a single datatype; DateTime.
+ ///
+ ///
+ public static System.DateTime DTOT(System.DateTime tDateTime)
+ {
+ //The date is the same as the datetime. Return the same value back :)
+ return tDateTime;
+ }
+
+ ///
+ /// Receives a date as a parameter and returns an integer specifying the day of the week for that date
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// int nDow = VFPToolkit.dates.DOW(tDateTime);
+ ///
+ ///
+ ///
+ ///
+ public static int DOW(System.DateTime dDate)
+ {
+ return (int)dDate.DayOfWeek;
+ }
+
+
+ ///
+ /// Receives a date and number of months as parameters and adds that many months to the date and returns the new date.
+ ///
+ /// Example:
+ /// DateTime myNewDate;
+ /// myNewDate = VFPToolkit.dates.GoMonth(DateTime.Now, 2); //returns a date after adding 2 months
+ ///
+ ///
+ ///
+ public static System.DateTime GoMonth(System.DateTime dDate, int nMonths)
+ {
+ return dDate.AddMonths(nMonths);
+ }
+
+ ///
+ /// Returns the current Hour from a DateTime (Use MyDate.Hour instead)
+ ///
+ ///
+ public static int Hour(System.DateTime dDate)
+ {
+ return dDate.Hour ;
+ }
+
+ ///
+ /// Receives a DateTime as a parameter and returns a formatted string in MDY format
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string cDate = VFPToolkit.dates.MDY(tDateTime); //returns "May 09 2001"
+ ///
+ ///
+ ///
+ ///
+ public static string MDY(System.DateTime dDate)
+ {
+ return dDate.ToString("MMMM dd yyyy");
+ }
+
+ ///
+ /// Returns the current Minute from a DateTime (Use MyDate.Minute instead)
+ ///
+ ///
+ public static int Minute(System.DateTime dDate)
+ {
+ return dDate.Minute ;
+ }
+
+ ///
+ /// Returns the current Month from a DateTime (Use MyDate.Month instead)
+ ///
+ ///
+ public static int Month(System.DateTime dDate)
+ {
+ return dDate.Month;
+ }
+
+ ///
+ /// Receives a date time as a parameter and returns an integer with the quarter the date
+ /// falls in
+ ///
+ /// Example:
+ /// int nCurrentQuarter = VFPToolkit.dates.Quarter(DateTime.Now); //returns 2
+ ///
+ ///
+ ///
+ ///
+ public static int Quarter(System.DateTime dDate)
+ {
+ //Get the current month
+ int i = dDate.Month;
+
+ //Based on the current month return the quarter
+ if (i <= 3)
+ { return 1; }
+ else if (i >= 4 && i <= 6)
+ { return 2; }
+ else if (i >=7 && i<= 9)
+ { return 3; }
+ else if (i >=10 && i <= 12)
+ { return 4; }
+ else
+ //Something probably is wrong
+ return 0;
+ }
+
+ ///
+ /// Returns the current second from a DateTime (Use MyDate.Second instead)
+ ///
+ ///
+ public static int Sec(System.DateTime dDate)
+ {
+ return dDate.Second ;
+ }
+
+ ///
+ /// Returns the number of seconds since midnight
+ ///
+ /// Example:
+ /// double nTotalSeconds = VFPToolkit.dates.Seconds();
+ ///
+ ///
+ ///
+ public static double Seconds()
+ {
+ //Create the timespan object get the time between the dates
+ System.TimeSpan st = System.DateTime.Now.Subtract(System.DateTime.Today);
+
+ //Return the number of seconds
+ return st.Duration().TotalMilliseconds/1000;
+ }
+
+ ///
+ /// Returns the current time in string format from a DateTime.
+ ///
+ /// Example:
+ /// string MyTime = VFPToolkit.dates.Time(); //returns "2:33 AM"
+ ///
+ ///
+ ///
+ public static string Time()
+ {
+ return System.DateTime.Now.ToShortTimeString();
+ }
+
+ ///
+ /// Receives a Date as a parameter and returns a string of that date and time.
+ /// (Use MyDate.ToShortDateString() and MyDate.ToShortTimeString() instead)
+ ///
+ ///
+ ///
+ public static string TTOC(System.DateTime dDate)
+ {
+ return String.Concat(dDate.ToShortDateString(), " ", dDate.ToShortTimeString()) ;
+ }
+
+ ///
+ /// Converts a DateTime expression to a short date string
+ ///
+ /// Example:
+ /// DateTime tDateTime = DateTime.Now;
+ /// string cDate = VFPToolkit.dates.TTOD(tDateTime);
+ ///
+ ///
+ ///
+ ///
+ public static string TTOD(System.DateTime tDateTime)
+ {
+ //Call tDateTime.ToShortDateString() which is a string to get this value
+ return tDateTime.ToShortDateString();
+ }
+
+ ///
+ /// Returns the current Year from a DateTime (Use MyDate.Year instead)
+ ///
+ ///
+ public static int Year(System.DateTime dDate)
+ {
+ return dDate.Year;
+ }
+
+
+ ///
+ /// Receives a DateTime as a parameter and returns the week of the year
+ ///
+ ///
+ /// int nCurrentWeek = VFPToolkit.dates.Week(DateTime.Now);
+ ///
+ ///
+ public static int Week(System.DateTime tdDate)
+ {
+ DateTimeFormatInfo d = new DateTimeFormatInfo();
+
+ //Receives the DateTime, Rule to start first day and first starting day (Mon, tue etc)
+ return d.Calendar.GetWeekOfYear(System.DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
+ }
+
+
+ ///
+ ///
+ //End of Dates class
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Files.cs b/VFPToolkitNET_CSharpNET_Standard/Files.cs
new file mode 100644
index 0000000..bb9d343
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Files.cs
@@ -0,0 +1,643 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Diagnostics;
+using System.Collections;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+
+ ///
+ /// Visual FoxPro File/Directory Functions
+ /// This class contains all the functions that work on files and directories such as CurDir(), Home(), JustPath(), FullPath(), DisplayPath(), AGetFileVersion() etc.
+ /// This class also contains low level file manipulation functions such as FOpen(), FWrite() FRead(), FFlush() etc.
+ ///
+ public class files
+ {
+
+ ///
+ /// Creates an array containing detailed information for a file
+ /// Note: Params 13 and 15 are not implemented. Param 13 specifies if file can self register and param 15 specified the translation code.
+ ///
+ /// //Create an array of type string and pass it by reference to the AGetFileVersion() along with the name of the file
+ /// //Fills MyArray with detailed information about the file
+ /// string[] MyArray = new string[0];
+ /// int i = VFPToolkit.arrays.AGetFileVersion(ref MyArray, "c:\\visio10\\gdiplus.dll");
+ ///
+ /// Tip: Note the use of double backslash \\ as a separator. In C# the backslash is used to specify escape sequence so you need to specify the \\ as a separator or specify the path using the @"c:\MyPath\MyFile".
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AGetFileVersion(ref string[] aFileInfoArray, string cFileName)
+ {
+ //Create the FileVersionInfo object from System.Diagnostics and pass the FileName for which we want to get information
+ System.Diagnostics.FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(cFileName);
+
+ //Specify the right dimensions for the array
+ aFileInfoArray = new string[15];
+
+ //Fill the array the right values
+ aFileInfoArray[0] = fvi.Comments;
+ aFileInfoArray[1] = fvi.CompanyName;
+ aFileInfoArray[2] = fvi.FileDescription;
+ aFileInfoArray[3] = fvi.FileVersion;
+ aFileInfoArray[4] = fvi.InternalName;
+ aFileInfoArray[5] = fvi.LegalCopyright;
+ aFileInfoArray[6] = fvi.LegalTrademarks;
+ aFileInfoArray[7] = fvi.OriginalFilename;
+ aFileInfoArray[8] = fvi.PrivateBuild;
+ aFileInfoArray[9] = fvi.ProductName;
+ aFileInfoArray[10] = fvi.ProductVersion;
+ aFileInfoArray[11] = fvi.SpecialBuild;
+ aFileInfoArray[12] = "";
+ aFileInfoArray[13] = fvi.Language;
+ aFileInfoArray[14] = "";
+
+ //Return the number of items back
+ return aFileInfoArray.Length ;
+ }
+
+ ///
+ /// Receives a path as a parameter and checks if the last character is a backslash. If not then adds one and returns the path otherwise returns the string
+ ///
+ ///
+ ///
+ public static string AddBS(string cPath)
+ {
+ if (cPath.Trim().EndsWith("\\"))
+ {
+ return cPath.Trim();
+ }
+ else
+ {
+ return cPath.Trim() + "\\";
+ }
+ }
+
+ ///
+ /// Returns the current directory. (In VFP, CurDir() receives a parameter for the volume/drive. This has not been implemented.)
+ ///
+ /// Example: MyLabel.Text = VFPToolkit.files.CurDir() //returns c:\VisualFoxProCommands\bin\debug
+ /// Tip: In order to change the current directory use: System.IO.Directory.SetCurrentDirectory(cPathName)
+ ///
+ ///
+ ///
+ public static string CurDir()
+ {
+ return System.IO.Directory.GetCurrentDirectory();
+ }
+
+ ///
+ /// Receives a file name and extension as parameters. If the file name does not have an extension then adds the extension. If the file has a different extension then changes that extension to the new extension.
+ ///
+ /// Example: VFPToolkit.files.DefaultExt("MyFile.txt","txt"); //Returns MyFile.txt
+ /// Example: VFPToolkit.files.DefaultExt("MyFile","txt"); //Returns MyFile.txt
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string DefaultExt(string cFileName, string cExtension)
+ {
+
+ int nLastDot, nLastBackSlash, nLength;
+ nLength = cFileName.Length;
+
+ //In this case we check if the file has an extension and if it does not then we simply supply one
+ nLastDot = cFileName.LastIndexOf('.') + 1;
+
+ if (nLastDot < 1)
+ {
+ //We did not find an extension so specify one
+ return cFileName + "." + cExtension;
+ }
+ else
+ {
+ //If we do not find an extension then specify one
+ nLastBackSlash = cFileName.LastIndexOf('\\') + 1;
+ if (nLastDot > nLastBackSlash)
+ {
+ return cFileName ;
+ }
+ else
+ {
+ return cFileName + "." + cExtension ;
+ }
+ }
+
+ }
+
+ ///
+ /// Receives a path as a parameter and returns true if a directory exists otherwise returns false
+ ///
+ ///
+ ///
+ public static bool Directory(string cPath)
+ {
+ return System.IO.Directory.Exists(cPath);
+ }
+
+ ///
+ /// Receives a filename with path and maxlength as parameters and returns a truncated version of the path for display purposes
+ ///
+ /// Example:
+ /// string lcFile = @"c:\My Folders\My Custom Folders\My Files\ResultFile.txt"
+ /// DisplayPath(lcFile, 10) //returns ResultFile
+ /// DisplayPath(lcFile, 15) //returns \ResultFile.txt
+ /// DisplayPath(lcFile, 20) //returns c:\...\ResultFile.txt
+ /// DisplayPath(lcFile, 30) //returns c:\...\My Files\ResultFile.txt
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string DisplayPath(string cFileNameWithPath, int nMaxLength)
+ {
+ //We will begin by taking the string and splitting it apart into an array
+
+ //Check if we are within the max length then return the whole string
+ if (cFileNameWithPath.Length <= nMaxLength)
+ {
+ return cFileNameWithPath;
+ }
+
+ //Split the string into an array using the \ as a delimiter
+ char[] cSeparator = {'\\'};
+ string[] aStr;
+ aStr = cFileNameWithPath.Split(cSeparator);
+
+ //The first value of the array is taken in case we need to create the string
+ string lcBegin = aStr[0] + "\\...";
+ int lnBeginLength = aStr[0].Length + 3;
+ string lcRetVal = "";
+ int lnLength = lcRetVal.Length ;
+ bool lAddHeader = false;
+
+ string s = "";
+ int n = 0;
+
+ //Now we loop backwards through the string
+ int i = 0;
+ for (i = aStr.Length - 1 ; i > 0; i--)
+ {
+ s = '\\' + aStr[i];
+ n = s.Length;
+
+ //Check if adding the current item does not increase the length of the max string
+ if (lnLength + n <= nMaxLength)
+ {
+ //In this case we can afford to add the item
+ lcRetVal = s + lcRetVal;
+ lnLength += n;
+ }
+ else
+ {
+ break;
+ }
+
+ //Check if there is room to add the header and if so then reserve it by incrementing the length
+ if ((lAddHeader == false) && (lnLength + lnBeginLength <= nMaxLength))
+ {
+ lAddHeader = true;
+ lnLength += lnBeginLength;
+ }
+ }
+
+ //Add the header if the bool is true
+ if (lAddHeader == true)
+ {
+ lcRetVal = lcBegin + lcRetVal;
+ }
+
+ //It is possible that the last value in the array itself was long. In such case simply use the substring of the last value
+ if (lcRetVal.Length == 0)
+ {
+ lcRetVal = aStr[aStr.Length-1].Substring(0,nMaxLength);
+ }
+
+ return lcRetVal;
+ }
+
+ ///
+ /// Receives a FileStream and new size as parameters and changes the size of the FileStream
+ ///
+ ///
+ ///
+ ///
+ public static long FChSize(FileStream oFileStream, int nNewSize)
+ {
+ oFileStream.SetLength(nNewSize);
+ return oFileStream.Length;
+ }
+
+ ///
+ /// Closes the FileStream
+ ///
+ ///
+ public static void FClose(ref System.IO.FileStream oFileStream)
+ {
+ oFileStream.Close();
+ }
+
+ ///
+ /// Creates a new file and returns a FileStream object back
+ ///
+ ///
+ ///
+ public static System.IO.FileStream FCreate(string cFileName)
+ {
+ return new FileStream(cFileName, System.IO.FileMode.CreateNew);
+ }
+
+ ///
+ /// Returns a string containing the last modification date for a file
+ ///
+ /// Example:
+ /// FDate("c:\\My Folders\\MyFile.txt"); //returns "04/29/2001"
+ ///
+ ///
+ ///
+ ///
+ public static string FDate(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the LastWriteTime in the right format.
+ //The LastWriteTime is a DateTime object which is more easier to work with than dates
+ //and manipulations could be applied on the DateTime object
+ return fi.LastWriteTime.ToShortDateString();
+ }
+
+ ///
+ /// Returns a bool value indicating if we have reached the end of the FileStream
+ ///
+ ///
+ ///
+ public static bool FEOF(System.IO.FileStream oFileStream)
+ {
+ return oFileStream.Length == oFileStream.Position;
+ }
+
+ ///
+ /// Flushes the contents of the FileStream object
+ ///
+ ///
+ public static void FFlush(System.IO.FileStream oFileStream)
+ {
+ oFileStream.Flush();
+ }
+
+ ///
+ /// Receives a file name with path as a parameter and returns true if the file exists otherwise false
+ ///
+ /// Example:
+ /// File(@"c:\My Folders\MyFile.txt"); //or
+ /// File("c:\\My Folders\\MyFile.txt");
+ ///
+ ///
+ ///
+ ///
+ public static bool File(string cFileName)
+ {
+ return System.IO.File.Exists(cFileName);
+ }
+
+ ///
+ /// Receives a file name as a parameter and returns a FileStream back after opening the file
+ ///
+ ///
+ ///
+ public static System.IO.FileStream FOpen(string cFileName)
+ {
+ return new FileStream(cFileName, System.IO.FileMode.Open);
+ }
+
+ ///
+ /// Receives a file name and extension as parameters. If the file name does not have an extension then adds the extension. If the file has a different extension then changes that extension to the new extension. (Forces the file to have then new extension)
+ ///
+ /// Example: VFPToolkit.files.ForceExt("MyFile.txt","txt"); //Returns MyFile.txt
+ /// Example: VFPToolkit.files.ForceExt("MyFile","txt"); //Returns MyFile.txt
+ /// Example: VFPToolkit.files.ForceExt("MyFile.kpp","txt"); //Returns MyFile.txt ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string ForceExt(string cFileName, string cExtension)
+ {
+ cFileName = cFileName.Trim();
+
+ int nLastDot, nLastBackSlash, nLength;
+ nLength = cFileName.Length;
+
+ //In this case we check if the file has an extension and if it does not then we simply supply one
+ nLastDot = cFileName.LastIndexOf('.') + 1;
+
+ if (nLastDot < 1)
+ {
+ //File does not have an extension. Specify an extension and leave
+ return cFileName + "." + cExtension;
+ }
+ else
+ {
+ nLastBackSlash = cFileName.LastIndexOf('\\') + 1;
+ if (nLastDot > nLastBackSlash)
+ {
+ // In this case we actually have to remove the last few characters and force the new extension
+ return cFileName.Substring(0,nLastDot-1) + "." + cExtension;
+ }
+ else
+ {
+ return cFileName + "." + cExtension ;
+ }
+ }
+
+ }
+
+ ///
+ /// Receives a file name and path as parameters and returns a file name
+ /// with a new path name substituted for the old one
+ ///
+ ///
+ ///
+ ///
+ public static string ForcePath(string cFileName, string cPath)
+ {
+ cPath = cPath.Trim();
+ cFileName = JustFName(cFileName.Trim());
+
+ if(cPath.Length == 0)
+ return cFileName;
+ else if(cPath[cPath.Length-1] == '\\')
+ return cPath + cFileName;
+ else
+ return cPath + "\\" + cFileName;
+ }
+
+ ///
+ /// Receives a FileStream and a string as parameters and adds the string to
+ /// the FileStream and then appends a carriage return followed by a line feed
+ ///
+ ///
+ /// System.IO.FileStream goErrFile ;
+ /// if(VFPToolkit.files.File("errors.txt"))
+ /// goErrFile = VFPToolkit.files.FOpen("errors.txt");
+ /// else
+ /// goErrFile = VFPToolkit.files.FCreate("errors.txt");
+ /// if(goErrFile.Handle.ToInt32() < 0)
+ /// //No errors. If so handle them here
+ /// else
+ /// VFPToolkit.files.FPuts(goErrFile, "Kamal Patel");
+ /// VFPToolkit.files.FClose(goErrFile) // Close file
+ ///
+ ///
+ ///
+ ///
+ public static int FPuts(ref FileStream oFileStream, string cString)
+ {
+ //Add a carriage return and line feed then write the string
+ //cString = cString + "\r\n";
+ return FWrite(ref oFileStream, cString) + FWrite(ref oFileStream, "\r\n");
+ }
+ public static int FPuts(ref FileStream oFileStream, string cString, int nCharactersWritten)
+ {
+ //Add a carriage return and line feed then write the string
+ return FWrite(ref oFileStream, cString, nCharactersWritten) + FWrite(ref oFileStream, "\r\n");
+ }
+
+ ///
+ /// Receives a FileStream and Bytes as parameters. The function reads the FileStream
+ /// starting from the current position until the number of specified bytes and returns a string
+ ///
+ ///
+ ///
+ ///
+ public static string FRead(ref FileStream oFileStream, int nBytes)
+ {
+ byte[] aBytes = new byte[nBytes];
+ int n = oFileStream.Read(aBytes,0,nBytes);
+ StringBuilder sb = new StringBuilder();
+
+ for (int i=0; i
+ /// Positions the position of the pointer to a specific location in the FileStream
+ ///
+ ///
+ ///
+ ///
+ public static long FSeek(ref FileStream oFileStream, int nBytesMoved)
+ {
+ return oFileStream.Seek(nBytesMoved,0);
+ }
+
+ ///
+ /// Positions the position of the pointer to a specific location in the FileStream.
+ /// This one receives a relative position as a third parameter
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static long FSeek(ref FileStream oFileStream, int nBytesMoved, int nRelativePosition)
+ {
+ if (nRelativePosition == 2)
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.End);
+ }
+ else if (nRelativePosition == 0)
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Begin);
+ }
+ else
+ {
+ return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Current);
+ }
+ }
+
+ ///
+ /// Returns a string containing the last modification time for a file
+ ///
+ ///
+ ///
+ public static string FTime(string cFileName)
+ {
+ //Check if it exists
+ if(!System.IO.File.Exists(cFileName))
+ return "";
+
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the LastWriteTime farmatted as a string.
+ //Call the LastAccessTime to get the last read/write/copy time
+ return fi.LastWriteTime.ToShortTimeString();
+ }
+
+
+ ///
+ /// Receives a filename as a parameter and returns a fully qualified path for the filename/path.
+ /// (Please note that the last two parameters nMsDosPath and cFileName2 are not implemented.)
+ ///
+ /// Example:
+ /// FullPath("files.cs"); //returns "c:\projects\VisualFoxProCommands\bin\Debug\files.cs"
+ ///
+ ///
+ ///
+ ///
+ public static string FullPath(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the FullName property
+ return fi.FullName;
+ }
+
+ ///
+ /// Receives a FileStream and string as parameters and writes a string to a FileStream
+ ///
+ ///
+ ///
+ ///
+ public static int FWrite(ref FileStream oFileStream, string cString)
+ {
+ return VFPToolkit.files.FWrite(ref oFileStream, cString, cString.Length);
+ }
+ public static int FWrite(ref FileStream oFileStream, string cString, int nCharactersWritten)
+ {
+ int i;
+ //Move the position to the end of the file
+ //oFileStream.Position = oFileStream.Length;
+
+ if(cString.Length < nCharactersWritten)
+ nCharactersWritten = cString.Length;
+
+ //Convert the string into an array of bytes
+ byte[] aBytes = new byte[nCharactersWritten];
+ for (i= 0; i < nCharactersWritten ; i++)
+ {
+ aBytes[i] = (byte)cString[i];
+ }
+
+ //Call the write method of the FileStream
+ oFileStream.Write(aBytes, 0, nCharactersWritten);
+ return cString.Length;
+ }
+
+
+ ///
+ /// Receives a path as a parameter and returns only the drive part
+ ///
+ /// Example:
+ /// JustPath("c:\\My Folders\\MyFile.txt"); //returns "c:"
+ ///
+ ///
+ ///
+ ///
+ public static string JustDrive(string cPath)
+ {
+ if(cPath.Trim().Length == 0)
+ return cPath.Trim();
+
+ string lcJustDrive = System.IO.Directory.GetDirectoryRoot(cPath);
+ lcJustDrive = strings.StrTran(lcJustDrive, "\\", "");
+ return lcJustDrive;
+ }
+
+ ///
+ /// Receives a FileName as a parameter and returns the extension of that file
+ ///
+ /// JustExt("c:\\My Folders\\MyFile.txt"); //returns ".txt"
+ ///
+ ///
+ ///
+ ///
+ public static string JustExt(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the extension of the file
+ return fi.Extension;
+ }
+
+ ///
+ /// Returns the only the file name with extension from a fully qualified path
+ ///
+ /// JustFName("c:\\My Folders\\MyFile.txt"); //returns "MyFile.txt"
+ ///
+ ///
+ ///
+ ///
+ public static string JustFName(string cFileName)
+ {
+ //Create the FileInfo object
+ FileInfo fi = new FileInfo(cFileName);
+
+ //Return the file name
+ return fi.Name;
+ }
+
+ ///
+ /// Receives a path as a parameter and returns only the path part without the file name.
+ ///
+ /// Example:
+ /// JustPath("c:\\My Folders\\MyFile.txt"); //returns "c:\My Folders"
+ ///
+ ///
+ ///
+ ///
+ public static string JustPath(string cPath)
+ {
+ //Get the full path of this path
+ string lcPath = cPath.Trim();
+
+ //If the file contains a backslash then remove it and return the path onlyfile name get rid of it
+ if(lcPath.IndexOf('\\') == -1)
+ return "";
+ else
+ return lcPath.Substring(0, lcPath.LastIndexOf('\\'));
+ }
+
+ ///
+ /// Returns the file name part without extension from a Path\FileName.ext string
+ ///
+ /// JustStem("c:\\My Folders\\MyFile.txt"); //returns "MyFile"
+ ///
+ ///
+ ///
+ ///
+ public static string JustStem(string cPath)
+ {
+ //Get the name of the file
+ string lcFileName = JustFName(cPath.Trim());
+
+ //Remove the extension and return the string
+ if(lcFileName.IndexOf(".") == -1)
+ return lcFileName;
+ else
+ return lcFileName.Substring(0, lcFileName.LastIndexOf('.'));
+ }
+
+
+ ///
+ ///
+
+
+ //End of File Class
+ }
+
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Help.cs b/VFPToolkitNET_CSharpNET_Standard/Help.cs
new file mode 100644
index 0000000..169c88f
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Help.cs
@@ -0,0 +1,157 @@
+using System;
+using System.Drawing.Printing;
+
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+
+ ///
+ /// Visual FoxPro Helper Functions
+ /// This class contains dummy helper functions that guides you in the right direction to achieve a desired functionality.
+ /// For example, if you need to call DoDefault(), the function will contains a sample code showing how this can be
+ /// achieved using the .NET Framework. The function itself returns nothing.
+ ///
+ public class help
+ {
+
+ ///
+ /// Use System.Windows.Forms.Application object to get a reference to the application
+ ///
+ public static void _Screen() {}
+
+ ///
+ /// The functionality of DoDefault() to call the parent class's default
+ /// behavior can be achieved by calling base.MethodName().
+ ///
+ ///
+ /// Here is an example:
+ /// Example: base.MethodName(Parameters);
+ ///
+ public static void DoDefault()
+ {
+ //This method only provides help
+ }
+
+ ///
+ /// The functionality of EditSource() can be achieved by writing a macro
+ /// for the IDE. A sample is included in example section.
+ ///
+ ///
+ /// Here is an example that opens up a document for editing inside the IDE.
+ /// 'Open a source code document for editing
+ /// Dim Cmd As Command
+ /// Dim Doc As Document
+ /// Dim TxtDoc As TextDocument
+ /// DTE.ItemOperations.OpenFile("FilePath\File Name")
+ ///
+ public static void EditSource()
+ {
+ //This method only provides help
+ }
+
+ ///
+ /// The functionality of IIF() can be achieved by using the ? : syntax as follows
+ ///
+ ///
+ /// MyValue = IIF(x=y, .T., .F.) && VFP
+ /// MyValue = x == y ? True : False //C# .NET
+ /// MyValue = Iif(x = y, True , False) 'VB .NET
+ ///
+ ///
+ public static void IIF()
+ {
+ //Dummy place holder method used for helping how an IIF can be achieved
+ //MyValue = IIF(x=y, .T., .F.) now becomes
+ //MyValue = x == y ? True : False
+ }
+
+ ///
+ /// An example of how the Do() functionality is achieved in .NET is included.
+ ///
+ ///
+ /// Do MyFile.exe can now be achieved using
+ /// Process.Start("MyFile.exe");
+ ///
+ public static void Do(){}
+
+ ///
+ /// There are couple of ways in which the functionality of NewObject()
+ /// is achieved in the .NET Framework. Please check the example section
+ /// for further details.
+ ///
+ ///
+ /// This functionality can be achieved couple of ways:
+ /// The first method is to create the object: Both a and b do the same job
+ /// a. MyCustomerForm oForm = new MyCustomerForm(); //Create a new object here
+ /// b. Application.Load(new MyCustomerForm());
+ /// c. Activator.CreateInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void NewObject(){}
+
+ ///
+ /// There are couple of ways in which the functionality of CreateObject()
+ /// is achieved in the .NET Framework. Please check the example section
+ /// for further details.
+ ///
+ ///
+ /// This functionality can be achieved couple of ways:
+ /// The first method is to create the object: Both a and b do the same job
+ /// a. MyCustomerForm oForm = new MyCustomerForm(); //Create a new object here
+ /// b. Application.Load(new MyCustomerForm());
+ /// c. Activator.CreateInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void CreateObject(){}
+
+ ///
+ /// Please refer further documentation in the .NET Framework on:
+ /// Activator.CreateInstance() and Activator.CreateComInstance()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void CreateObjectEx(){}
+
+ ///
+ /// Please refer further documentation in the .NET Framework on
+ /// Activator.GetObject()
+ /// Note: Please review GetInterface() to see how an Excel.Application can
+ /// be created in .NET
+ ///
+ public static void GetObject(){}
+
+
+ ///
+ /// GetInterface() can be achieved by adding object references through
+ /// the "Add References" tab to achieve early binding. An example of how
+ /// an Excel object is accessed from .NET Framework is included in the example
+ /// section.
+ ///
+ ///
+ /// A Type has to be specified for all the objects in .NET so in order to get
+ /// early bound controls you could follow the following steps: The example
+ /// demonstrates how an Excel object is created in .NET
+ ///
+ /// 1. Right click on References and select "Add Reference"
+ /// 2. Select the "COM Components" tab
+ /// 3. Locate the "Microsoft Excel Object Library" and select it
+ /// 4. Add the following code
+ /// private Excel.Application oExcel = null;
+ /// oExcel = new Excel.Application();
+ /// oExcel.Visible = true;
+ ///
+ public static void GetInterface(){}
+
+
+ ///
+ ///
+
+
+
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Math.cs b/VFPToolkitNET_CSharpNET_Standard/Math.cs
new file mode 100644
index 0000000..b7daec6
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Math.cs
@@ -0,0 +1,665 @@
+using System;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro Math Functions
+ /// This class contains all the math functions such as Cos(), Sin(), Tan(), Abs(), Mod(), Sqrt(),
+ /// Int(), Log(), Max(), Min() etc.
+ /// (Most of the math functions are decoraters that call the System.Math methods.)
+ ///
+ public class math
+ {
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static decimal Abs(decimal nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static double Abs(double nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an absolute value from a number (Use Math.Abs() instead)
+ ///
+ ///
+ ///
+ public static int Abs(int nNumber)
+ {
+ return System.Math.Abs(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Cosine (Use Math.ACos() instead)
+ ///
+ ///
+ ///
+ public static double ACos(double nNumber)
+ {
+ return System.Math.Acos(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Cosine (Use Math.ACos() instead)
+ ///
+ ///
+ ///
+ public static double ACos(int nNumber)
+ {
+ return System.Math.Acos((double)nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Sin (Use Math.ASin() instead)
+ ///
+ ///
+ ///
+ public static double ASin(double nNumber)
+ {
+ return System.Math.Asin(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Sin (Use Math.ASin() instead)
+ ///
+ ///
+ ///
+ public static double ASin(int nNumber)
+ {
+ return System.Math.Asin((double)nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Tangent (Use Math.ATan() instead)
+ ///
+ ///
+ ///
+ public static double ATan(double nNumber)
+ {
+ return System.Math.Atan(nNumber);
+ }
+
+ ///
+ /// Returns an angle from a Tangent (Use Math.ATan() instead)
+ ///
+ ///
+ ///
+ public static double ATan(int nNumber)
+ {
+ return System.Math.Atan((double)nNumber);
+ }
+
+ ///
+ /// Returns an Atn2() from two coordinates (Use Math.Atn2() instead)
+ ///
+ ///
+ ///
+ public static double Atn2(double nYCoordinate, double nXCoordinate)
+ {
+ return System.Math.Atan2(nYCoordinate, nXCoordinate);
+ }
+
+ ///
+ /// Returns an ceiling value from a number (Use Math.Celing() instead)
+ ///
+ ///
+ ///
+ public static double Ceiling(double nNumber)
+ {
+ return System.Math.Ceiling(nNumber);
+ }
+
+ ///
+ /// Returns the Cosine of an angle(Use Math.Cos() instead)
+ ///
+ ///
+ ///
+ public static double Cos(double nNumber)
+ {
+ return System.Math.Cos(nNumber);
+ }
+
+ ///
+ /// Returns the Cosine of an angle (Use Math.Cos() instead)
+ ///
+ ///
+ ///
+ public static double Cos(int nNumber)
+ {
+ return System.Math.Cos((double)nNumber);
+ }
+
+ ///
+ /// Receives degrees as a parameter and converts it to radiants
+ ///
+ ///
+ ///
+ public static double DTOR(double nDegrees)
+ {
+ return ((nDegrees * System.Math.PI)/180);
+ }
+
+ ///
+ /// Returns a number raised to the specified power (Use Math.Exp() instead)
+ ///
+ ///
+ ///
+ public static double Exp(double nNumber)
+ {
+ return System.Math.Exp(nNumber);
+ }
+
+ ///
+ /// Returns an Floor value from a number (Use Math.Floor() instead)
+ ///
+ ///
+ ///
+ public static double Floor(double nNumber)
+ {
+ return System.Math.Floor(nNumber);
+ }
+
+ ///
+ /// Converts a double to an integer (Use (int)MyNumber instead)
+ ///
+ ///
+ ///
+ public static int Int(double nNumber)
+ {
+ return (int)nNumber;
+ }
+
+ ///
+ /// Converts a float to an integer (Use (int)MyNumber instead)
+ ///
+ ///
+ ///
+ public static int Int(float nNumber)
+ {
+ return (int)nNumber;
+ }
+
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(double nNumber)
+ {
+ return System.Math.Log(nNumber);
+ }
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(int nNumber)
+ {
+ return System.Math.Log((double)nNumber);
+ }
+
+ ///
+ /// Returns the Log of a specified number (Use Math.Log() instead)
+ ///
+ ///
+ ///
+ public static double Log(decimal nNumber)
+ {
+ return System.Math.Log((double)nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(double nNumber)
+ {
+ return System.Math.Log10(nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(int nNumber)
+ {
+ return System.Math.Log10((double)nNumber);
+ }
+
+ ///
+ /// Returns the base 10 Log of a specified number (Use Math.Log10() instead)
+ ///
+ ///
+ ///
+ public static double Log10(decimal nNumber)
+ {
+ return System.Math.Log10((double)nNumber);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static double Max(double nVal1, double nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static decimal Max(decimal nVal1, decimal nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ public static int Max(int nVal1, int nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Max number
+ ///
+ ///
+ ///
+ ///
+ public static float Max(float nVal1, float nVal2)
+ {
+ return System.Math.Max(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static double Min(double nVal1, double nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static decimal Min(decimal nVal1, decimal nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static int Min(int nVal1, int nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Receives two numbers as parameters and returns the Lower number
+ ///
+ ///
+ ///
+ ///
+ public static float Min(float nVal1, float nVal2)
+ {
+ return System.Math.Min(nVal1,nVal2);
+ }
+
+ ///
+ /// Returns the Mod of two numbers.
+ ///
+ ///
+ ///
+ ///
+ public static double Mod(double nDividend, double nDivisor)
+ {
+ return nDividend % nDivisor ;
+ }
+
+ ///
+ /// Converts a decimal value to double (use (double)MyDecimalValue instead)
+ ///
+ ///
+ ///
+ public static double MTON(decimal nMoney)
+ {
+ return (double)nMoney;
+ }
+
+ ///
+ /// Converts a double value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(double nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Converts a integer value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(int nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Converts a float value to decimal (use (decimal)MyValue instead)
+ ///
+ ///
+ ///
+ public static decimal NTOM(float nMoney)
+ {
+ return (decimal)nMoney;
+ }
+
+ ///
+ /// Returns the value of PI (Use Math.PI instead)
+ ///
+ ///
+ public static double PI()
+ {
+ return System.Math.PI;
+ }
+
+ ///
+ /// Receives a seed as a parameter and returns a random number.
+ ///
+ ///
+ ///
+ public static double Random(int nSeed)
+ {
+ System.Random r = new System.Random(nSeed);
+ return r.Next();
+ }
+ public static double Random()
+ {
+ System.Random r = new System.Random();
+ return r.Next();
+ }
+
+ ///
+ /// Rounds a number and returns it back. (Use Math.Round() instead)
+ ///
+ ///
+ ///
+ public static decimal Round(decimal nNumber)
+ {
+ return System.Math.Round(nNumber);
+ }
+
+ ///
+ /// Rounds a number and returns it back. (Use Math.Round() instead)
+ ///
+ ///
+ ///
+ ///
+ public static double Round(double nNumber, int nDigits)
+ {
+ return System.Math.Round(nNumber, nDigits);
+ }
+
+ ///
+ /// Receives radiants as a parameter and converts it to degrees
+ ///
+ ///
+ ///
+ public static double RTOD(double nRadians)
+ {
+ return ((nRadians * 180)/System.Math.PI);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(decimal nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(double nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(int nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns an integer sign (0,1 or 2) based on if the number is negative, zero or positive.
+ /// (Use Math.Sign() instead)
+ ///
+ ///
+ ///
+ public static int Sign(float nNumber)
+ {
+ return System.Math.Sign(nNumber);
+ }
+
+ ///
+ /// Returns the Sin of an angle (Use Math.Sin() instead)
+ ///
+ ///
+ ///
+ public static double Sin(double nNumber)
+ {
+ return System.Math.Sin(nNumber);
+ }
+
+ ///
+ /// Returns the Sin of an angle (Use Math.Sin() instead)
+ ///
+ ///
+ ///
+ public static double Sin(int nNumber)
+ {
+ return System.Math.Sin((double)nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ /// Console.WriteLine(Sqrt(4)); //Returns 2
+ /// Console.WriteLine(Sqrt(2 * Sqrt(2))); //Returns 1.6817928
+ ///
+ ///
+ ///
+ public static double Sqrt(double nNumber)
+ {
+ return System.Math.Sqrt(nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ ///
+ public static double Sqrt(decimal nNumber)
+ {
+ return System.Math.Sqrt((double)nNumber);
+ }
+
+ ///
+ /// Returns a square root of a number. (Use Math.Sqrt() instead)
+ ///
+ ///
+ ///
+ public static double Sqrt(int nNumber)
+ {
+ return System.Math.Sqrt((double)nNumber);
+ }
+
+ ///
+ /// Returns the Tangent of an angle (Use Math.Tan() instead)
+ ///
+ ///
+ ///
+ public static double Tan(double nNumber)
+ {
+ return System.Math.Tan(nNumber);
+ }
+
+ ///
+ /// Returns the Tangent of an angle (Use Math.Tan() instead)
+ ///
+ ///
+ ///
+ public static double Tan(int nNumber)
+ {
+ return System.Math.Tan((double)nNumber);
+ }
+
+
+ ///
+ /// Receives and integer expression and position as parameter and returns the
+ /// result of shifting the bits to the left for the specified number of positions
+ ///
+ ///
+ ///
+ ///
+ public static int BitLShift(int tnExpression, int tnPositions)
+ {
+ return tnExpression << tnPositions;
+ }
+
+ ///
+ /// Receives and integer expression and position as parameter and returns the
+ /// result of shifting the bits to the left for the specified number of positions
+ ///
+ ///
+ ///
+ ///
+ public static int BitRShift(int tnExpression, int tnPositions)
+ {
+ return tnExpression >> tnPositions;
+ }
+
+ ///
+ /// Receives two integers and returns the result of a bitwise and operation
+ ///
+ ///
+ ///
+ ///
+ public static int BitAnd(int tnExpression1, int tnExpression2)
+ {
+ return tnExpression1 & tnExpression2;
+ }
+
+ ///
+ /// Receives two integers and returns the result of a bitwise or operation
+ ///
+ ///
+ ///
+ ///
+ public static int BitOr(int tnExpression1, int tnExpression2)
+ {
+ return tnExpression1 | tnExpression2;
+ }
+
+ ///
+ /// Receives and integer and returns the negation
+ ///
+ ///
+ ///
+ public static int BitNot(int tnExpression)
+ {
+ return ~tnExpression;
+ }
+
+
+ ///
+ /// Receives an integer value and position as parameter and returns the
+ /// specified bit in that position.
+ ///
+ ///
+ ///
+ ///
+ public static bool BitTest(int tnExpression, int tnPosition)
+ {
+ //Create an array of integer
+ int[] aInt = {5};
+
+ //Create the BitArray so the bits are populated
+ System.Collections.BitArray ba = new System.Collections.BitArray(aInt);
+
+ //Return the appropriate position
+ return ba[0];
+ }
+
+
+ ///
+ ///
+
+ //public static void FV(decimal nPayment, decimal nInterestRate, int nPeriods)
+ //{
+ //return nPayment/(1+nInterestRate)^nPeriods;
+ //Microsoft.VisualBasic.VBCodeProvider.
+
+ //}
+
+ //The following three functions used for calculations are not implemented
+ //public static decimal FV(decimal nPayment, decimal nInterestRate, int nPeriods)
+ //public static decimal PV(decimal nPayment, decimal nInterestRate, int nTotalPayments)
+ //public static decimal Payment(decimal nPrincipal, decimal nInterestRate, int nPayments)
+
+ //End of Math class
+ }
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/Strings.cs b/VFPToolkitNET_CSharpNET_Standard/Strings.cs
new file mode 100644
index 0000000..9546126
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/Strings.cs
@@ -0,0 +1,1238 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Globalization;
+
+/// Author: Kamal Patel
+/// Email: kppatel@yahoo.com
+/// Copyright: None (Public Domain)
+namespace VFPToolkit
+{
+ ///
+ /// Visual FoxPro String Functions
+ /// This class contains all the string manipulations functions. Some of the new
+ /// functions in VFP7 such as StrExtract(), GetWordCount(), GetWordNumber() have also
+ /// been implemented. Favourites such as FileToStr(), StrToFile(), Stuff(), Proper(),
+ /// StrTran(), At(), RAt(), Occurs() etc. are also included.
+ ///
+ /// Note:
+ /// One string function is not implemented
+ /// public static string StrConv(cExpression, nConversionSetting [, nLocaleID])
+ public class strings
+ {
+ ///
+ /// Removes leading and trailing spaces from cExpression
+ ///
+ ///
+ public static string AllTrim(string cExpression)
+ {
+ return cExpression.Trim();
+ }
+
+
+ ///
+ /// Receives a character as a parameter and returns its ANSI code
+ ///
+ /// Example
+ /// Asc('#'); //returns 35
+ ///
+ ///
+ ///
+ public static int Asc(char cCharacter)
+ {
+ return (int)cCharacter;
+ }
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// If found, returns the beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.At("D", "Joe Doe"); //returns 5
+ ///
+ ///
+ ///
+ ///
+ public static int At(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.IndexOf(cSearchFor) + 1;
+ }
+
+ ///
+ /// Receives two strings and an occurence position (1st, 2nd etc) as parameters and
+ /// searches for one string within another for that position.
+ /// If found, returns the beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.At("o", "Joe Doe", 1); //returns 2
+ /// VFPToolkit.strings.At("o", "Joe Doe", 2); //returns 6
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int At(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor, cSearchIn, nOccurence, 1);
+ }
+
+ /// Private Implementation: This is the actual implementation of the At() and RAt() functions.
+ /// Receives two strings, the expression in which search is performed and the expression to search for.
+ /// Also receives an occurence position and the mode (1 or 0) that specifies whether it is a search
+ /// from Left to Right (for At() function) or from Right to Left (for RAt() function)
+ private static int __at(string cSearchFor, string cSearchIn, int nOccurence, int nMode)
+ {
+ //In this case we actually have to locate the occurence
+ int i = 0;
+ int nOccured = 0;
+ int nPos = 0;
+ if (nMode == 1) {nPos = 0;}
+ else {nPos = cSearchIn.Length;}
+
+ //Loop through the string and get the position of the requiref occurence
+ for (i=1;i<=nOccurence;i++)
+ {
+ if(nMode == 1) {nPos = cSearchIn.IndexOf(cSearchFor,nPos);}
+ else {nPos = cSearchIn.LastIndexOf(cSearchFor,nPos);}
+
+ if (nPos < 0)
+ {
+ //This means that we did not find the item
+ break;
+ }
+ else
+ {
+ //Increment the occured counter based on the current mode we are in
+ nOccured++;
+
+ //Check if this is the occurence we are looking for
+ if (nOccured == nOccurence)
+ {
+ return nPos + 1;
+ }
+ else
+ {
+ if(nMode == 1) {nPos++;}
+ else {nPos--;}
+
+ }
+ }
+ }
+ //We never found our guy if we reached here
+ return 0;
+ }
+
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// This function ignores the case and if found, returns the beginning numeric position
+ /// otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtC("d", "Joe Doe"); //returns 5
+ ///
+ ///
+ ///
+ ///
+ public static int AtC(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.ToLower().IndexOf(cSearchFor.ToLower()) + 1;
+ }
+
+ ///
+ /// Receives two strings and an occurence position (1st, 2nd etc) as parameters and
+ /// searches for one string within another for that position. This function ignores the
+ /// case of both the strings and if found, returns the beginning numeric position
+ /// otherwise returns 0.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtC("d", "Joe Doe", 1); //returns 5
+ /// VFPToolkit.strings.AtC("O", "Joe Doe", 2); //returns 6
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtC(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor.ToLower(), cSearchIn.ToLower(), nOccurence, 1);
+ }
+
+ ///
+ /// Receives an integer ANSI code and returns a character associated with it
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Chr(35); //returns '#'
+ ///
+ ///
+ ///
+ public static char Chr(int nAnsiCode)
+ {
+ return (char)nAnsiCode;
+ }
+
+ ///
+ /// Replaces each character in a character expression that matches a character
+ /// in a second character expression with the corresponding character in a
+ /// third character expression
+ ///
+ ///
+ /// Console.WriteLine(ChrTran("ABCDEF", "ACE", "XYZ")); //Displays XBYDZF
+ /// Console.WriteLine(ChrTran("ABCD", "ABC", "YZ")); //Displays YZD
+ /// Console.WriteLine(ChrTran("ABCDEF", "ACE", "XYZQRST")); //Displays XBYDZF
+ ///
+ ///
+ ///
+ ///
+ public static string ChrTran(string cSearchIn, string cSearchFor, string cReplaceWith)
+ {
+ string lcRetVal = cSearchIn;
+ string cReplaceChar;
+ for(int i=0; i< cSearchFor.Length; i++)
+ {
+ if(cReplaceWith.Length <= i)
+ cReplaceChar = "";
+ else
+ cReplaceChar = cReplaceWith[i].ToString();
+
+ lcRetVal = StrTran(lcRetVal, cSearchFor[i].ToString(), cReplaceChar);
+ }
+ return lcRetVal;
+ }
+
+
+ ///
+ /// Converts character type data to binary type character string. Just a place
+ /// holder function as this becomes irrelevent now.
+ ///
+ ///
+ public static string CreateBinary(string cExpression)
+ {
+ //This decorator simply returns the expression back
+ //This is because we used this function to converts VFP strings to binary type
+ //character string so they could be passed to an ActiveX control or
+ //automation object. In the .NET Framework this becomes irrelevent
+ return cExpression;
+ }
+
+ ///
+ /// Receives a file name as a parameter and returns the contents of that file
+ /// as a string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.FileToStr("c:\\My Folders\\MyFile.txt"); //returns the contents of the file
+ ///
+ ///
+ ///
+ public static string FileToStr(string cFileName)
+ {
+ //Create a StreamReader and open the file
+ StreamReader oReader = System.IO.File.OpenText(cFileName);
+
+ //Read all the contents of the file in a string
+ string lcString = oReader.ReadToEnd();
+
+ //Close the StreamReader and return the string
+ oReader.Close();
+ return lcString;
+ }
+
+ ///
+ /// Receives a string as a parameter and counts the number of words in that string
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe is a good man";
+ /// VFPToolkit.strings.GetWordCount(lcString); //returns 6
+ ///
+ ///
+ ///
+ public static long GetWordCount(string cString)
+ {
+ int i = 0 ;
+ long nLength = cString.Length;
+ long nWordCount = 0;
+
+ //Begin by checking for the first word
+ if (!Char.IsWhiteSpace(cString[0]))
+ {
+ nWordCount ++;
+ }
+
+ //Now look for white spaces and count each word
+ for ( i=0 ; i < nLength ; i++ )
+ {
+ //Check for a space to begin counting a word
+ if (Char.IsWhiteSpace(cString[i]))
+ {
+ //We think we encountered a word
+ //Remove any following white spaces if any after this word
+ do
+ {
+ //Check if we have reached the limit and if so then exit the loop
+ i ++ ;
+ if (i >= nLength) {break;}
+ if (!Char.IsWhiteSpace(cString[i]))
+ {
+ nWordCount++;
+ break;
+ }
+ } while (true);
+
+ }
+
+ }
+ return nWordCount;
+ }
+
+ ///
+ /// Based on the position specified, returns a word from a string
+ /// Receives a string as a parameter and counts the number of words in that string
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe is a good man";
+ /// VFPToolkit.strings.GetWordNumber(lcString, 5); //returns "good"
+ ///
+ ///
+ ///
+ ///
+ public static string GetWordNumb(string cString, int nWordPosition)
+ {
+ int nBeginPos = VFPToolkit.strings.At(" ",cString,nWordPosition - 1);
+ int nEndPos = VFPToolkit.strings.At(" ",cString, nWordPosition);
+ return VFPToolkit.strings.SubStr(cString, nBeginPos + 1, nEndPos -1 - nBeginPos);
+ }
+
+
+ ///
+ /// Returns a bool indicating if the first character in a string is an alphabet or not
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsAlpha("Joe Doe"); //returns true
+ ///
+ /// Tip: This method uses Char.IsAlpha(char) to check if it is an alphabet or not.
+ /// In order to check if the first character is a digit use Char.IsDigit(char)
+ ///
+ ///
+ ///
+ public static bool IsAlpha(string cExpression)
+ {
+ //Check if the first character is a letter
+ return Char.IsLetter(cExpression[0]);
+ }
+
+ ///
+ /// Checks if the first character of a string is a lowercase char and if so then returns true
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsLower("MyName"); //returns false
+ /// VFPToolkit.strings.IsLower("mYnAme"); //returns true
+ ///
+ ///
+ ///
+ public static bool IsLower(string cExpression)
+ {
+ try
+ {
+ //Get the first character in the string
+ string lcString = cExpression.Substring(0,1);
+
+ //Return a bool indicating if the char is an lowercase or not
+ return lcString == lcString.ToLower() ;
+ }
+ catch
+ {
+ //In case of an error return false
+ return false;
+ }
+ }
+
+ ///
+ /// Checks if the first character of a string is an uppercase and if so then returns true
+ ///
+ /// Example:
+ /// VFPToolkit.strings.IsUpper("MyName"); //returns true
+ /// VFPToolkit.strings.IsUpper("mYnAme"); //returns false
+ ///
+ ///
+ ///
+ public static bool IsUpper(string cExpression)
+ {
+ try
+ {
+ //Get the first character in the string
+ string lcString = cExpression.Substring(0,1);
+
+ //Return a bool indicating if the char is an uppercase or not
+ return lcString == lcString.ToUpper() ;
+ }
+ catch
+ {
+ //In case of an error return false
+ return false;
+ }
+ }
+
+ ///
+ /// Receives a string and the number of characters as parameters and returns the
+ /// specified number of leftmost characters of that string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Left("Joe Doe", 3); //returns "Joe"
+ ///
+ ///
+ ///
+ ///
+ public static string Left(string cExpression, int nDigits)
+ {
+ return cExpression.Substring(0, nDigits);
+ }
+
+ ///
+ /// Receives a string as a parameter and returns the length of the string
+ ///
+ /// Example:
+ /// string MyString = "Hi there";
+ /// VFPToolkit.strings.Len(MyString); //returns 8
+ ///
+ ///
+ ///
+ public static int Len(string cExpression)
+ {
+ return cExpression.Length;
+ }
+
+ ///
+ /// Receives a string as a parameter and converts it to lowercase
+ ///
+ ///
+ public static string Lower(string cExpression)
+ {
+ //Call the ToLower() method of the string object
+ return cExpression.ToLower() ;
+ }
+
+ ///
+ /// Removes the leading spaces in cExpression
+ ///
+ ///
+ public static string LTrim(string cExpression)
+ {
+ //Hint: Pass null as the first parameter to remove white spaces
+ return cExpression.TrimStart(null);
+ }
+
+ ///
+ /// Returns the number of occurences of a character within a string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Occurs('o', "Joe Doe"); //returns 2
+ ///
+ /// Tip: If we have a string say lcString, then lcString[3] gives us the 3rd character in the string
+ ///
+ ///
+ ///
+ ///
+ public static int Occurs(char tcChar, string cExpression)
+ {
+ int i, nOccured = 0;
+
+ //Loop through the string
+ for (i = 0; i < cExpression.Length ; i++ )
+ {
+ //Check if each expression is equal to the one we want to check against
+ if (cExpression[i] == tcChar)
+ {
+ //if so increment the counter
+ nOccured++ ;
+ }
+ }
+ return nOccured;
+ }
+ ///
+ /// Returns the number of occurences of one string within another string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Occurs("oe", "Joe Doe"); //returns 2
+ /// VFPToolkit.strings.Occurs("Joe", "Joe Doe"); //returns 1
+ ///
+ /// Tip: String.IndexOf() searches the string (starting from left) for another character or string expression
+ ///
+ ///
+ ///
+ ///
+ public static int Occurs(string cString, string cExpression)
+ {
+ int nPos = 0;
+ int nOccured = 0;
+ do
+ {
+ //Look for the search string in the expression
+ nPos = cExpression.IndexOf(cString,nPos);
+
+ if (nPos < 0)
+ {
+ //This means that we did not find the item
+ break;
+ }
+ else
+ {
+ //Increment the occured counter based on the current mode we are in
+ nOccured++;
+ nPos++;
+ }
+ } while (true);
+
+ //Return the number of occurences
+ return nOccured;
+ }
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the both sides of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns " Joe Doe "
+ ///
+ ///
+ ///
+ ///
+ public static string PadC(string cExpression, int nResultSize)
+ {
+ //Determine the number of padding characters
+ int nPaddTotal = nResultSize - cExpression.Length;
+ int lnHalfLength = (int)(nPaddTotal/2);
+
+ string lcString = PadL(cExpression, cExpression.Length + lnHalfLength);
+ return lcString.PadRight(nResultSize);
+ }
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on both sides of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "xJoe Doexx"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string PadC(string cExpression, int nResultSize, char cPaddingChar)
+ {
+ //Determine the number of padding characters
+ int nPaddTotal = nResultSize - cExpression.Length;
+ int lnHalfLength =(int)(nPaddTotal/2);
+
+ string lcString = PadL(cExpression, cExpression.Length + lnHalfLength,cPaddingChar);
+ return lcString.PadRight(nResultSize, cPaddingChar);
+ }
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the left of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns " Joe Doe"
+ ///
+ ///
+ ///
+ ///
+ public static string PadL(string cExpression, int nResultSize)
+ {return cExpression.PadLeft(nResultSize);}
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on the left of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "xxxJoe Doe"
+ ///
+ /// Tip: Use single quote to create a character type data and double quotes for strings
+ ///
+ ///
+ public static string PadL(string cExpression, int nResultSize, char cPaddingChar)
+ {return cExpression.PadLeft(nResultSize, cPaddingChar);}
+
+ ///
+ /// Receives a string and the length of the result string as parameters. Pads blank
+ /// characters on the right of this string and returns a string with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10); //returns "Joe Doe "
+ ///
+ ///
+ ///
+ ///
+ public static string PadR(string cExpression, int nResultSize)
+ {return cExpression.PadRight(nResultSize);}
+
+
+ ///
+ /// Receives a string, the length of the result string and the padding character as
+ /// parameters. Pads the padding character on the right of this string and returns a string
+ /// with the length specified.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.PadL("Joe Doe", 10, 'x'); //returns "Joe Doexxx"
+ ///
+ /// Tip: Use single quote to create a character type data and double quotes for strings
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string PadR(string cExpression, int nResultSize, char cPaddingChar)
+ {return cExpression.PadRight(nResultSize, cPaddingChar);}
+
+ ///
+ /// Receives a string as a parameter and returns the string in Proper format (makes each letter after a space capital)
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Proper("joe doe is a good man"); //returns "Joe Doe Is A Good Man"
+ ///
+ ///
+ ///
+ /// ToDo: Split the string instead and you do not have to worry about comparing each char
+ public static string Proper(string cString)
+ {
+
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cString);
+
+ int i,j = 0 ;
+ int nLength = cString.Length ;
+
+ for ( i = 0 ; i < nLength; i++)
+ {
+ //look for a blank space and once found make the next character to uppercase
+ if ((i== 0) || (char.IsWhiteSpace(cString[i])))
+ {
+ //Handle the first character differently
+ if( i==0 ) {j=i;}
+ else {j=i+1;}
+
+ //Make the next character uppercase and update the stringBuilder
+ sb.Remove(j, 1);
+ sb.Insert(j, Char.ToUpper(cString[j]));
+ }
+ }
+ return sb.ToString();
+ }
+
+ ///
+ /// Receives two strings as parameters and searches for one string within another.
+ /// The search is performed starting from Right to Left and if found, returns the
+ /// beginning numeric position otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAt("o", "Joe Doe"); //returns 6
+ ///
+ ///
+ ///
+ ///
+ public static int RAt(string cSearchFor, string cSearchIn)
+ {
+ return cSearchIn.LastIndexOf(cSearchFor) + 1;
+ }
+
+ ///
+ /// Receives two strings as parameters and an occurence position as parameters.
+ /// The function searches for one string within another and the search is performed
+ /// starting from Right to Left and if found, returns the beginning numeric position
+ /// otherwise returns 0
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAt("o", "Joe Doe", 1); //returns 6
+ /// VFPToolkit.strings.RAt("o", "Joe Doe", 2); //returns 2
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int RAt(string cSearchFor, string cSearchIn, int nOccurence)
+ {
+ return __at(cSearchFor, cSearchIn, nOccurence, 0);
+ }
+
+ ///
+ /// Receives a string expression and a numeric value indicating number of time
+ /// and replicates that string for the specified number of times.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Replicate("Joe", 5); //returns JoeJoeJoeJoeJoe
+ ///
+ /// Tip: Use a StringBuilder when lengthy string manipulations are required.
+ ///
+ ///
+ ///
+ ///
+ public static string Replicate(string cExpression, int nTimes)
+ {
+ //Create a stringBuilder
+ StringBuilder sb = new StringBuilder();
+
+ //Insert the expression into the StringBuilder for nTimes
+ sb.Insert(0,cExpression,nTimes);
+
+ //Convert it to a string and return it back
+ return sb.ToString();
+ }
+
+ ///
+ /// Receives a string and the number of characters as parameters and returns the
+ /// specified number of rightmost characters of that string
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Right("Joe Doe", 3); //returns "Doe"
+ ///
+ ///
+ ///
+ ///
+ public static string Right(string cExpression, int nDigits)
+ {
+ return cExpression.Substring(cExpression.Length - nDigits);
+ }
+
+ ///
+ /// Removes the trailing spaces in cExpression
+ ///
+ ///
+ /// VfpToolkit.strings.RTrim("VFPToolkitNET "); //returns "VFPToolkitNET"
+ ///
+ ///
+ public static string RTrim(string cExpression)
+ {
+ //Hint: Pass null as the first parameter to remove white spaces
+ return cExpression.TrimEnd(null);
+ }
+
+ ///
+ /// Receives an integer as a parameter and returns an empty string of that length
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Space(20); //returns a string with 20 spaces
+ ///
+ ///
+ ///
+ public static string Space(int nSpaces)
+ {
+ //Create a new string and return those many spaces in it
+ char val = ' ';
+ return new string(val,nSpaces);
+ }
+
+ ///
+ /// Receives an integer/decimal/double as a parameter and converts it to a string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Str(135); //returns "135"
+ ///
+ ///
+ ///
+ public static string Str(int nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+ ///
+ /// Overloaded method for receiving a parameter of type double
+ ///
+ ///
+ public static string Str(double nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+ ///
+ /// Overloaded method for receiving a parameter of type decimal
+ ///
+ ///
+ public static string Str(decimal nNumber)
+ {
+ return nNumber.ToString();
+ }
+
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters. Receives a beginning occurence
+ /// to begin the extraction from and also receives a flag (0/1) where 1 indicates
+ /// that the search should be case insensitive.
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ", 1, 0); //returns "eDo"
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim, int nBeginOccurence, int nFlags)
+ {
+ string cstring = cSearchExpression;
+ string cb = cBeginDelim;
+ string ce = cEndDelim;
+ string lcRetVal = "";
+
+ //Check for case-sensitive or insensitive search
+ if (nFlags == 1)
+ {
+ cstring = cstring.ToLower();
+ cb = cb.ToLower();
+ ce = ce.ToLower();
+ }
+
+ //Lookup the position in the string
+ int nbpos = At(cb, cstring, nBeginOccurence) + cb.Length - 1;
+ int nepos = cstring.IndexOf(ce, nbpos + 1);
+
+ //Extract the part of the strign if we get it right
+ if (nepos > nbpos)
+ {
+ lcRetVal = cSearchExpression.Substring(nbpos , nepos - nbpos);
+ }
+
+ return lcRetVal;
+ }
+
+ ///
+ /// Receives a string and a delimiter as parameters and returns a string starting
+ /// from the position after the delimiter
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o"); //returns "eDoeJoeDoe"
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim)
+ {
+ int nbpos = At(cBeginDelim, cSearchExpression);
+ return cSearchExpression.Substring(nbpos + cBeginDelim.Length - 1);
+ }
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ"); //returns "eDo"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim)
+ {
+ return StrExtract(cSearchExpression, cBeginDelim, cEndDelim, 1, 0);
+ }
+
+ ///
+ /// Receives a string along with starting and ending delimiters and returns the
+ /// part of the string between the delimiters. It also receives a beginning occurence
+ /// to begin the extraction from.
+ ///
+ /// Example:
+ /// string cExpression = "JoeDoeJoeDoe";
+ /// VFPToolkit.strings.StrExtract(cExpression, "o", "eJ", 2); //returns ""
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrExtract(string cSearchExpression, string cBeginDelim, string cEndDelim, int nBeginOccurence)
+ {
+ return StrExtract(cSearchExpression, cBeginDelim, cEndDelim, nBeginOccurence, 0);
+ }
+
+ ///
+ /// Receives a string and a file name as parameters and writes the contents of the
+ /// string to that file
+ ///
+ /// Example:
+ /// string lcString = "This is the line we want to insert in our file.";
+ /// VFPToolkit.strings.StrToFile(lcString, "c:\\My Folders\\MyFile.txt");
+ ///
+ ///
+ ///
+ ///
+ public static void StrToFile(string cExpression, string cFileName)
+ {
+ //Check if the sepcified file exists
+ if (System.IO.File.Exists(cFileName) == true)
+ {
+ //If so then Erase the file first as in this case we are overwriting
+ System.IO.File.Delete(cFileName);
+ }
+
+ //Create the file if it does not exist and open it
+ FileStream oFs = new FileStream(cFileName,FileMode.CreateNew,FileAccess.ReadWrite);
+
+ //Create a writer for the file
+ StreamWriter oWriter = new StreamWriter(oFs);
+
+ //Write the contents
+ oWriter.Write(cExpression);
+ oWriter.Flush();
+ oWriter.Close();
+
+ oFs.Close();
+ }
+ ///
+ /// Receives a string and a file name as parameters and writes the contents of the
+ /// string to that file. Receives an additional parameter specifying whether the
+ /// contents should be appended at the end of the file
+ ///
+ /// Example:
+ /// string lcString = "This is the line we want to insert in our file.";
+ /// VFPToolkit.strings.StrToFile(lcString, "c:\\My Folders\\MyFile.txt");
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void StrToFile(string cExpression, string cFileName, bool lAdditive)
+ {
+ //Create the file if it does not exist and open it
+ FileStream oFs = new FileStream(cFileName,FileMode.OpenOrCreate,FileAccess.ReadWrite);
+
+ //Create a writer for the file
+ StreamWriter oWriter = new StreamWriter(oFs);
+
+ //Set the pointer to the end of file
+ oWriter.BaseStream.Seek(0, SeekOrigin.End);
+
+ //Write the contents
+ oWriter.Write(cExpression);
+ oWriter.Flush();
+ oWriter.Close();
+ oFs.Close();
+ }
+
+ ///
+ /// Searches one string into another string and replaces all occurences with
+ /// a blank character.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o"); //returns "J e D e" :)
+ ///
+ ///
+ ///
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //Call the Replace() method of the StringBuilder
+ return sb.Replace(cSearchFor," ").ToString();
+ }
+
+ ///
+ /// Searches one string into another string and replaces all occurences with
+ /// a third string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o", "ak"); //returns "Jake Dake"
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor, string cReplaceWith)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //There is a bug in the replace method of the StringBuilder
+ sb.Replace(cSearchFor, cReplaceWith);
+
+ //Call the Replace() method of the StringBuilder and specify the string to replace with
+ return sb.Replace(cSearchFor, cReplaceWith).ToString();
+ }
+
+ /// Searches one string into another string and replaces each occurences with
+ /// a third string. The fourth parameter specifies the starting occurence and the
+ /// number of times it should be replaced
+ ///
+ /// Example:
+ /// VFPToolkit.strings.StrTran("Joe Doe", "o", "ak", 2, 1); //returns "Joe Dake"
+ ///
+ public static string StrTran(string cSearchIn, string cSearchFor, string cReplaceWith, int nStartoccurence, int nCount)
+ {
+ //Create the StringBuilder
+ StringBuilder sb = new StringBuilder(cSearchIn);
+
+ //There is a bug in the replace method of the StringBuilder
+ sb.Replace(cSearchFor, cReplaceWith);
+
+ //Call the Replace() method of the StringBuilder specifying the replace with string, occurence and count
+ return sb.Replace(cSearchFor, cReplaceWith, nStartoccurence, nCount).ToString();
+ }
+
+
+ ///
+ /// Receives a string (cExpression) as a parameter and replaces a specified number
+ /// of characters in that string (nCharactersReplaced) from a specified location
+ /// (nStartReplacement) with a specified string (cReplacement)
+ ///
+ /// Example:
+ /// string lcString = "Joe Doe";
+ /// string lcReplace = "Foo ";
+ /// VFPToolkit.strings.Stuff(lcString, 5, 0, lcReplace); //returns "Joe Foo Doe";
+ /// VFPToolkit.strings.Stuff(lcString, 5, 3, lcReplace); //returns "Joe Foo ";
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string Stuff(string cExpression, int nStartReplacement, int nCharactersReplaced, string cReplacement)
+ {
+ //Create a stringbuilder to work with the string
+ StringBuilder sb = new StringBuilder(cExpression);
+
+ if(nCharactersReplaced + nStartReplacement -1 >= cExpression.Length)
+ nCharactersReplaced = cExpression.Length - nStartReplacement + 1;
+
+
+ //First remove the characters specified in nCharacterReplaced
+ if (nCharactersReplaced != 0)
+ {
+ sb.Remove(nStartReplacement - 1, nCharactersReplaced);
+ }
+
+ //Now Add the new string at the right location
+ //sb.Insert(0,cExpression,nTimes);
+ sb.Insert(nStartReplacement - 1,cReplacement);
+ return sb.ToString();
+ }
+
+
+ ///
+ /// Receives a string as a parameter and returns a part of the string based on the parameters specified.
+ ///
+ /// string lcName = "Joe Doe";
+ /// SubStr(lcName, 1, 3); //returns "Joe"
+ /// SubStr(lcName, 5); //returns Doe
+ ///
+ ///
+ ///
+ ///
+ public static string SubStr(string cExpression, int nStartPosition)
+ {
+ return cExpression.Substring(nStartPosition-1);
+ }
+
+ ///
+ /// Overloaded method for SubStr() that receives starting position and length
+ ///
+ ///
+ ///
+ ///
+ public static string SubStr(string cExpression, int nStartPosition, int nLength)
+ {
+ nStartPosition--;
+ if((nLength + nStartPosition) > cExpression.Length)
+ return cExpression.Substring(nStartPosition);
+ else
+ return cExpression.Substring(nStartPosition,nLength);
+ }
+
+ ///
+ /// Removes leading and trailing spaces from cExpression
+ ///
+ ///
+ public static string Trim(string cExpression)
+ {
+ return cExpression.Trim();
+ }
+
+
+ ///
+ /// Receives a string as a parameter and converts it to uppercase
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Upper("MyName"); //returns "MYNAME"
+ ///
+ ///
+ ///
+ public static string Upper(string cExpression)
+ {
+ //Call the ToUpper() method of the string object
+ return cExpression.ToUpper();
+ }
+
+
+ ///
+ /// Receives a string and converts it to an integer
+ ///
+ /// Example:
+ /// VFPToolkit.strings.Val("1325"); //returns 1325
+ ///
+ ///
+ ///
+ public static int Val(string cExpression)
+ {
+ //Remove all the spaces and commas from the string
+ //Get the integer portion of the string
+ return Int32.Parse(cExpression, NumberStyles.Any);
+ }
+
+
+ ///
+ /// Receives a string and converts it to an integer
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtLine("Is", "Is Life Beautiful? \r\n It sure is"); //returns 1
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ string lcString ;
+ int nPosition;
+ int nCount = 0;
+
+ try
+ {
+ nPosition = VFPToolkit.strings.At(tcSearchExpression, tcExpressionSearched);
+ if (nPosition > 0)
+ {
+ lcString = VFPToolkit.strings.SubStr(tcExpressionSearched , 1, nPosition -1);
+ nCount = VFPToolkit.strings.Occurs(@"\r", lcString) + 1;
+ }
+ }
+ catch
+ {
+ nCount = 0;
+ }
+
+ return nCount;
+ }
+
+ ///
+ /// Receives a search expression and string to search as parameters and returns an integer specifying
+ /// the line where it was found. This function starts it search from the end of the string.
+ ///
+ /// Example:
+ /// VFPToolkit.strings.RAtLine("sure", "Is Life Beautiful? \r\n It sure is") 'returns 2
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int RAtLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ string lcString ;
+ int nPosition;
+ int nCount = 0;
+
+ try
+ {
+ nPosition = VFPToolkit.strings.RAt(tcSearchExpression, tcExpressionSearched);
+ if (nPosition > 0)
+ {
+ lcString = VFPToolkit.strings.SubStr(tcExpressionSearched , 1, nPosition -1);
+ nCount = VFPToolkit.strings.Occurs(@"\r", lcString) + 1;
+ }
+ }
+ catch
+ {
+ nCount = 0;
+ }
+
+ return nCount;
+ }
+
+ ///
+ /// Returns the line number of the first occurence of a string expression within
+ /// another string expression without regard to case (upper or lower)
+ ///
+ /// Example:
+ /// VFPToolkit.strings.AtCLine("Is Life Beautiful? \r\n It sure is", "Is"); //returns 1
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int AtCLine(string tcSearchExpression, string tcExpressionSearched)
+ {
+ return AtLine(tcSearchExpression.ToLower(), tcExpressionSearched.ToLower());
+ }
+
+ ///
+ /// Receives a string as a parameter and returns a bool indicating if the left most
+ /// character in the string is a valid digit.
+ ///
+ /// Example:
+ /// if(VFPToolkit.strings.IsDigit("1Kamal")){...} //returns true
+ ///
+ ///
+ ///
+ ///
+ public static bool IsDigit(string tcString)
+ {
+ //get the first character in the string
+ char c = tcString[0];
+ return Char.IsDigit(c);
+ }
+
+ ///
+ /// Returns the number of lines in a string
+ ///
+ /// Example:
+ /// int lnLines = VFPToolkit.strings.MemLines(lcMyLongString);
+ ///
+ ///
+ ///
+ ///
+ public static int MemLines(string tcString)
+ {
+ if(tcString.Trim().Length == 0)
+ return 0;
+ else
+ return VFPToolkit.strings.Occurs("\\r", tcString) + 1;
+ }
+
+ ///
+ /// Receives a string and a line number as parameters and returns the
+ /// specified line in that string
+ ///
+ /// Example:
+ /// string lcCity = VFPToolkit.strings.MLine(tcAddress, 2); // Not that you would want to do something like this but you could ;)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string MLine(string tcString, int tnLineNo)
+ {
+ string[] aLines = tcString.Split('\r');
+ string lcRetVal = "";
+ try
+ {
+ lcRetVal = aLines[tnLineNo -1];
+ }
+ catch
+ {
+ //Ignore the exception as MLINE always returns a value
+ }
+
+ return lcRetVal;
+ }
+
+
+
+ ///
+ ///
+
+
+ //End of stringsclass
+ }
+ //End of vfp namespace
+}
diff --git a/VFPToolkitNET_CSharpNET_Standard/VFPToolkitNET_CSharpNET_Standard.csproj b/VFPToolkitNET_CSharpNET_Standard/VFPToolkitNET_CSharpNET_Standard.csproj
new file mode 100644
index 0000000..c6d8999
--- /dev/null
+++ b/VFPToolkitNET_CSharpNET_Standard/VFPToolkitNET_CSharpNET_Standard.csproj
@@ -0,0 +1,35 @@
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+
+