Friday, March 6, 2015

Reading files by File System Object (FSO) in VBA

This subroutine reads all files where the excel file is located.

Public Sub ReadFiles()
   
    Dim FSO As New FileSystemObject
    Dim MyFiles As Folder
    Dim MyFile As File
   
     Set MyFiles = FSO.GetFolder(ActiveWorkbook.path)  'the path of the excel file
   
    For Each MyFile In MyFiles.Files
   
                Print MyFile,name
                'Do something

    Next
 
End Sub

Convert a csv file to excel file by VBA

Code snippet

This subrountine converts a CSV file to an excel file

Public Sub CSVToXLS(ByVal CSVfilePath As String, ByVal XLSFilePath As String)

    Dim FSO As New FileSystemObject
    Dim workbookName As String
    Dim applicationPath As String

   workbookName = ActiveWorkbook.Name
   applicationPath = Application.ActiveWorkbook.path
 
 Workbooks.OpenText CSVfilePath, , , xlDelimited, xlDoubleQuote, False _
  , True, True, , , , dataTypes

  ActiveWorkbook.SaveAs Filename:=XLSFilePath, FileFormat:=xlNormal

  ActiveWorkbook.Close

  Workbooks.Item(workbookName).Activate
   
End Sub

Monday, March 2, 2015

Shrink LDF

Code snippet

USE DatabaseName
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE DatabaseName
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKDATABASE('DatabaseName')
GO
-- Reset the database recovery model.
ALTER DATABASE DatabaseName
SET RECOVERY FULL;
GO

https://msdn.microsoft.com/en-us/library/ms189493(v=sql.90).aspx 

Applying SMA10/20, SMA20/50 as trading signals

This is the comparison for results before and after applying SMA10/20 and SMA20/50 in the stock trader. Background Trading 3 stock ma...