Just Code : Using word spell check

Adding this snipit. came in helpfull today

Dim TaskKill
TaskKill = CreateObject("WScript.Shell").Run("taskkill /f /im winword.exe", 0, True)
Dim oWord,x
Set oWord = CreateObject("Word.Application")

oWord.visible = true
oWord.DisplayAlerts = false
oWord.Documents.Add()

x = oWord.CheckSpelling("Carrrots",,true,,,,,,,,,,)

if ( x = false ) Then 

    debug.log(oWord.GetSpellingSuggestions("Carrrots").Item(1))

End if

 

Here is some code to tabulate questions in PHP

 

<?php
// url to test : http://[server]/[VirtualDirectory]/TOM.php?q=d1&m=&f=d1.containsany({japan,china})

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if (isset($_GET["q"]) && $_GET["q"] != ""){
// d1*d3 or d1]d3 or d1+d3
$q = $_GET["q"]; 
$q = str_replace("]","+",$q); 
echo $q;
} else {
die("No Question Specified"); 
}

if (isset($_GET["m"]) && $_GET["m"] != ""){
$m = "json"; 
} else {
$m="html";
}

if (isset($_GET["f"]) && $_GET["f"] != ""){
$filter =$_GET["f"]; 
} else {
$filter="";
}

//phpinfo();
echo 'Start';
// Create the Tables object and open the DataSet
//Set TableDoc = CreateObject("TOM.Document")
$oTableDoc = new COM("TOM.Document") or die("Unable to instantiate TOM.Document"); 

$sProject = "CSUITE_2019";
$oMDD = "D:\\FMRoot\\Master\\CSUITE_2019\\CSUITE_2019.mdd";


$oData = "Provider=SQLOLEDB.1;Data Source=IBMIBV001;User ID=;Password=;Initial Catalog=" . $sProject . ";Integrated Security=SSPI;Persist Security Info=true";

$oTableDoc->DataSet->Load($oMDD, "", $oData, "mrRdbDsc2", "", "{..}");
$oTableDoc->DataSet->View = 1 ;

// Set the properties of the table document
//$oTableDoc->Language = "ENA";
//$oTableDoc->Context = "Question";
//$oTableDoc->LabelType = "Label";


$oTableDoc->Default->Clear();
$oTableDoc->Default->CellItems->AddNew(0);
//$oTableDoc->Default->CellItems->AddNew(1); // Percents
$oTableDoc->ProfileDefault->Clear();

//Define the tables
$oTable = $oTableDoc->Tables->AddNew("Table1",$q, "Table1");
if ( $filter != "" ) {
echo $filter;
$oTable->Filters->AddNew("Filter1", $filter);
}
//Table.Filters.AddNew("Filter1", "d1.ContainsAny({China})")

//Populate the tables
$oTableDoc->Populate();
$oTableXML = $oTableDoc->GetTablesXml("Table1", 1);

$xml=simplexml_load_string($oTableXML) or die("Error: Cannot create object");
$json = json_encode($xml); // convert the XML string to JSON

if ( $m == "json" ) {
echo $json;
} else {
$oHtmlRender = new COM("ExportHtml.Renderer") or die("Unable to instantiate TOM.Document"); 
//$oHtmlRender->OutputBodyOnly = 1;
echo $oHtmlRender->Render($oTableXML);
}

// Render as an HTML table
//$oHtmlRender = new COM("ExportHtml.Renderer") or die("Unable to instantiate TOM.Document"); 
//$oHtmlRender->OutputBodyOnly = 1;
//echo $oHtmlRender->Render($oTableXML);

echo 'Done';

?>

PHP to List mdd labels

Here is some code to list the variables in an MDD

 

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

//phpinfo();
echo 'Start';
// Create the MDM object and open the Short Drinks .mdd file in read-write mode

$oMDM = new COM("MDM.Document") or die("Unable to instantiate MDM.Document"); 
$oMDM->Open("C:\\inetpub\\wwwroot\\IBV_USERS.mdd", '', 2);
foreach ($oMDM->Variables as $oVar) {
echo $oVar->Label ."<br/>";
}


echo 'Done';

?>

IBM Watson API Test

I have been meaning to post something like this code for a while. Here is an example of calling one of the IBM watson API’s from a MRS script.  Its just code and i think easy to understand. The full API i am playing with can be found here. https://cloud.ibm.com/apidocs/language-translator#translate

Dim sUrl
Dim http
Dim apiHash

sUrl = "https://gateway-syd.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01"
set oHTTP = createObject("Microsoft.XMLHTTP")

oHTTP.open("GET", sUrl, false)
'The string after "Basic" is the base64 encoded of apikey:[YourAPIKEY]
'I.e.: apihash = Base64Encode("apikey:[YourAPIKEY]")

apiHash = "[YOURHASH]"
oHTTP.setRequestHeader("Authorization", "Basic " + apiHash)
oHTTP.setRequestHeader("content-type", "application/json")
oHTTP.send("{""text"":[""Hello""],""model_id"":""en-es""}")

If oHTTP.status = 200 Then
    debug.Log("RESPONSE : " + oHTTP.responseText)
else
    debug.Log("ERRCODE : " + ctext(oHTTP.status))
    debug.Log("RESPONSE : " + oHTTP.responseText)
End If

Create a nested folder structure with the file system object.

We needed to make some nested folder structures for a project we are running with mrs scripts and i thought i would post some code to do that.  I am sure there are many ways to do this , but this is what we did in just a few lines

 

Dim sPath , oItem, sCurrentPath,oFSO


Set oFSO = CreateObject("Scripting.FileSystemObject")

For each oItem in split("C:\Temp\Doug\Doug1\Doug2\","\")

if ( find(oItem,":") > -1 ) then 
      sCurrentPath = oItem + "\"
else
      sCurrentPath = replace(sCurrentPath + "\" + oItem,"\\","\")
End If

If oFSO.FolderExists(sCurrentPath) = False Then
      debug.Log(sCurrentPath)
      oFSO.CreateFolder(sCurrentPath)
End If


Next

Just Code : Delete all files with specific month

I needed a quick bit of code today so that i could clean up my hard disk. This script will delete all the files that match a specific month number. One day it may save you a few minutes.

LoopFolders("D:\Servers\116\SQLBackups",10)

Sub LoopFolders(sFullPath,iMonth)
Dim oFolder,oSubFolder,oFSO,oFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

If oFSO.FolderExists(sFullPath) Then
Set oFolder = oFSO.GetFolder(sFullPath)

For Each oFile In oFolder.Files
if ( Month(oFile.DateCreated) = iMonth ) Then
debug.Log(oFolder.Path + "\" + oFile.Name +":" + ctext(oFile.DateCreated))
oFSO.DeleteFile(oFolder.Path + "\" + oFile.Name)
End If
Next

For each oSubFolder in oFolder.SubFolders
debug.Log("“Folder:"+ oSubFolder.Name)
LoopFolders(oSubFolder.Path,iMonth)
Next

End If

Set oFSO = null
Set oFolder = null
Set oFile = null
End Sub

Testing a carousel feature in WP

Here are some images/links to IBM Thought Leadership that the team i work for has helped produce. In most cases Unicom intelligence, SPSS Statistics and Modeler have been used to provide analytical insight into the data collected to help drive and validate the content in these documents. If you work in the Government or Education sectors, then these are for you. Happy Clicking (If you want more info then please feel free to drop me a email at dporton@au1.ibm.com )

PHP 7.2.2 and Unicom

I am currently looking into writing a PHP interface that schedules Unicom tasks and i thought i would make a few post’s as i go along. Obviously, the first thing you have to do is to install PHP and set it up for COM use. Setting PHP up for COM is easy , just make sure you have this in your PHP.ini file. ( Search for [COM] )

; allow Distributed-COM calls
; http://php.net/com.allow-dcom
extension=php_com_dotnet.dll
com.allow_dcom = true

The way to check that com is enabled it so run a PHP file that has this in it

<?php
phpinfo(); 
?>

And when you run the file , make sure you see this

next we need to see if com is activated and works so i tried this on Excel. I have excel 2013 my machine

<?php 
     ini_set('display_errors', 1);
     ini_set('display_startup_errors', 1);
     error_reporting(E_ALL); 
     $xl = new COM("Excel.Application"); 
?>

and it produced this ,

Fatal error: Uncaught com_exception: 
Failed to create COM object `Excel.Application': 
Access is denied. in C:\inetpub\wwwroot\LoopMDD.php:9 Stack trace: #0 C:\inetpub\wwwroot\LoopMDD.php(9): 
com->com('Excel.Applicati...') #1 {main} thrown in C:\inetpub\wwwroot\LoopMDD.php on line 9

and i am ok with that as it shows the COM statement worked. If you want to take the excel thing further then you can take a look at this post and it will show you how to get access to XL this way. So whats next .. Well one of the first things i need to do is open an MDD so here is the PHP code to do that


<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

	echo 'Start';
  	$oMDM = new COM("MDM.Document") or die("Unable to instantiate MDM.Document"); 
	$oMDM->Open("C:\\inetpub\\wwwroot\\USERS.mdd", '', 2);
	foreach ($oMDM->Variables as $oVar) {
		echo $oVar->Label ."<br/>";
	}
	echo 'Done';

?>

and so when i ran the PHP file i got the labels. So PHP COM , 64bit is enabled and working , now onto the next bit, watch this space.