// Website: http://www.investools.com/login.asp' // Automatically create portfolio called 'Automate' and fill with // stock symbols from C:\StockPicks.txt // Requirement: You must have an account and be logged in before // executing this script program CreatePortfolio; const TabToField1 = 23; // number of tabs to Save Portfolio button TabToField2 = 22; // number of tabs to Edit Portfolio button InterFieldTabCount = 7; // number of tabs between successive entry fields StockFile = 'c:\StockPicks.txt'; FieldsPerPage = 15; // number of stock entries allowed per page var TabCount, StockID, NumStocks, StockCount : integer; StockSymbol : array[1..300] of string; // each symbol is 1 - 4 characters long FieldID, PrevValue : string; bProcessed : boolean; procedure OnDocumentComplete(URL : string); begin // delay is needed to since OnDocumentComplete is triggered multiple times Sleep(2000); if URL = 'http://pro.investortoolbox.com/oit/portfolio/Edit_portfolio.asp?Portfolio=-1' then begin for StockID := 1 to 300 do StockSymbol[StockID] := ''; // fill with empty value StockID := 1; Reset(StockFile); // open StockFile for reading PrevValue := ''; while (not(EndofFile) and (StockID <= 300)) do begin Readfl(StockSymbol[StockID]); // read stock symbol if PrevValue <> StockSymbol[StockID] then // eliminates stock duplicates begin PrevValue := StockSymbol[StockID]; StockID := StockID + 1; end; end; NumStocks := StockID-1; // total number of stocks in array CloseFile; // close StockFile, all stock symbols read Fill('PTitle', 'Automate'); // name new portfolio Automate for StockID := 1 to FieldsPerPage do // fill in 15 fields on page begin FieldID := IntToStr(StockID-1); // converts StockID into a string Insert('Symbol',FieldID,1); // insert Symbol to create FieldID Fill(FieldID, StockSymbol[StockID]); // stock symbol end; StockCount := FieldsPerPage; // number of stocks entered for TabCount := 1 to TabToField1 do SendKeyPress('TAB'); SendKeyPress('ENTER'); // press Save Portfolio button end; // will trigger Edit button to be clicked; must force it though if IsPartOf('http://pro.investortoolbox.com/oit/portfolio/Current_Valuations.asp?', URL) or (bProcessed) then begin if StockCount < NumStocks then begin ExecuteWebScript('editPortfolio()', 'javascript'); bProcessed := False; end else NewbieScriptEnd; end; // will start filling in the stock symbols if IsPartOf('current_valuations.asp', URL) and not(bProcessed) then begin if StockCount < NumStocks then // continue to enter stocks begin for StockID := StockCount+1 to StockCount+FieldsPerPage do // fill in 15 fields on page begin FieldID := IntToStr(StockID-1); // converts StockID into a string Insert('Symbol',FieldID,1); // insert Symbol to create FieldID Fill(FieldID, StockSymbol[StockID]); // stock symbol end; StockCount := StockCount+FieldsPerPage; // number of stocks entered // press Save Portfolio button for TabCount := 1 to TabToField1 do SendKeyPress('TAB'); SendKeyPress('ENTER'); // press Save Portfolio button bProcessed := True; end; end; end; begin Navigate('http://pro.investortoolbox.com/oit/portfolio/Edit_portfolio.asp?Portfolio=-1'); end.