'************************************************************************* ' IQ-to-Cell vsn 0.11 12/2/2009 JJS ' ' This Windows script enables IQ text data to be read, somewhat crudely, on a Java-capable cell phone. ' It requires the free mobile app TinyBook, available from GetJar.com, and the filter program ' HtmlAsText, available at nirsoft.net or on shareware sites. ' ' Suggested approach to set-up: ' - Get TinyBook running on your phone first, displaying its own sample book. ' - On PC, create a Project Root folder of your choice, save this script into it as "IQ-to-Cell.vbs". ' - Edit the BluetoothDest variable below to reflect the PC folder your Bluetooth phone reads from. ' -- For convenience, create a shortcut from Project Root into BluetoothDest. ' - Edit the ProjRoot variable below to reflect your Project Root folder name. ' - Create subfolders as listed: FolderToZip, CleanOriginals ' - Copy Tinybook.jar and Tinybook.jad into the CleanOriginals subfolder ' - Copy HtmlAsText.exe into your Project Root ' - Create a dummy file, any name, in FolderToZip. Without a dummy file in the folder, our ' file "book1.txt" is created as "Book1.txt" and won't be read by TinyBook. Reason unknown. ' - In IQ, create or activate a grid with Hierarchy Off. ' Ctrl-A to select all Items, or select items individually. ' Click Grid - Export to Web Page ' Output to "IQ-to-Cell.htm" in your IQbase folder (probably not your ProjRoot) ' - Run HtmlAsText.exe directly, to create a configuration file for future batch execution. ' HTML file is the one created by IQ. ("IQ-to-Cell.htm" in IQbase folder) ' Text file is "iqc-workfile1.txt" in your Project Root ' Save as "IQ-to-Cell.cfg" in your Project Root ' - Create a shortcut to the script, with command line: ' cscript.exe "D:\install\TinyBook\IQ-to-Cell.vbs" ' (substitute your own Project Root folder of course). ' - Running the .vbs file directly will show all status and error messages as clickable pop-ups ' for debugging. Running the shortcut with Cscript will execute the script in a non-interactive ' window, with one pop-up used as a pause. Most errors will cause an undisplayed early exit ' in cscript mode. ' - After successful execution, updated TinyBook.jad and .jar files will be found in your ' Bluetooth Exchange Folder for copying to the cell. These contain executables and a "book" ' of text from IQ. ' 'To run in future: ' - From IQ grid, select items, click Grid - Export to Web Page ' - Browse to "IQ-to-Cell.htm" and save under that name, overwriting. ' - Execute "IQ-to-Cell.vbs" from the cscript shortcut ' - Click the shortcut to your Bluetooth Exchange Folder ' - Verify the newly updated Tinybook.jar and Tinybook.jad, transfer to your phone ' - Execute Tinybook.jar in your phone ' ' Please post your improvements and any error messages (after double-checking set-up steps.) ' I'm hoping to evolve this script to use a database app rather than the TinyBook text app. ' ''************************************************************************* ProjRoot="D:\install\Tinybook\" HtmlAsTextCmd=ProjRoot+"HtmlAsText.exe /run "+ProjRoot+"IQ-to-Cell.cfg" FileToFilter=ProjRoot+"iqc-workfile1.txt" WorkFile2=ProjRoot+"iqc-workfile2.txt" FolderToZip = ProjRoot+"FolderToZip\" DestFile=FolderToZip+"book1.txt" zipFile = ProjRoot+"iqc-workfile3.zip" JadSource=ProjRoot+"CleanOriginals\Tinybook.jad" JadDest=ProjRoot+"Tinybook.jad" JarSource=ProjRoot+"CleanOriginals\Tinybook.jar" BluetoothDest="E:\batches\BatchShortcuts\Bluetooth Exchange Folder\" JarDest=BluetoothDest+"Tinybook.jar" ' ' Convert HTML to Txt ' ' WScript.Echo "Executing: "+HtmlAsTextCmd Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") 'WshShell.Run() Set oExec = WshShell.Exec(HtmlAsTextCmd) Do While oExec.Status = 0 WScript.Sleep 100 Loop ' ' Open created file for regex replaces ' WScript.Echo "Opening..."+FileToFilter ' public strFileContents ' Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(FileToFilter) Then Set objFile = objFSO.OpenTextFile(FileToFilter) strFileContents = objFile.ReadAll Else WScript.Echo "Error: File not found." WScript.Quit End If public strReplacedText 'strReplacedText=strFileContents 'Perform Regex Replaces to clean the txt a bit ------------- strRegExp = " " strReplace = "" Call IQReplace ' strFileContents=strReplacedText strRegExp = " " Call IQReplace ' strFileContents=strReplacedText strRegExp ="DB=" strReplace = vbCrLf+"DB=" Call IQReplace '------------------------------------------------------ ' ' Write to Book file ' strFileOut=WorkFile2 Set objFile = objFSO.OpenTextFile(strFileOut, 2, True) objFile.Write strReplacedText objFile.Close WScript.Echo strMatch & vbCrLf & "Saved file " & strFileOut ' Set f2 = objFSO.GetFile(WorkFile2) f2.Copy(DestFile) ' WScript.Echo "Copying JAR to Zip File: "+zipFile Set f2 = objFSO.GetFile(JarSource) f2.Copy(zipFile) ' WScript.Echo "Adding to Zip File: "+zipFile set sa = CreateObject("Shell.Application") Set zip= sa.NameSpace(zipFile) Set Fol=sa.NameSpace(FolderToZip) zip.CopyHere Fol.Items, 16 WScript.Sleep 2000 ' WScript.Echo "Obtaining Size of Zip File" ' Set objFile = objFSO.GetFile(zipFile) ZipFileSize=objFile.Size Wscript.Echo "Zip File Size: " & ZipFileSize ' WScript.Echo "Opening..."+JadSource ' Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(JadSource) Then Set objFile = objFSO.OpenTextFile(JadSource) strFileContents = objFile.ReadAll Else WScript.Echo "Error: File not found." WScript.Quit End If strRegExp = "!!!SET TinyBook.jar SIZE HERE!!!" strReplace = ZipFileSize Call IQReplace ' ' Write to JAD file ' strFileOut=DestFile Set objFile = objFSO.OpenTextFile(JadDest, 2, True) objFile.Write strReplacedText WScript.Echo strMatch & vbCrLf & "Saved file " & JadDest ' WScript.Echo "Copying to: "+BluetoothDest ' Set f2 = objFSO.GetFile(JadDest) f2.Copy(BluetoothDest) ' Set f2 = objFSO.GetFile(zipFile) f2.Copy(JarDest) ' PopMsg="TinyBook files with IQ Data available in "+Bluetoothdest ' WScript.Echo "Clear Popup msg to Exit." WshShell.Popup(PopMsg) ' '---------------Subroutines ' sub IQReplace ' WScript.Echo "Sub IQReplace called. Replacing: "+strRegExp 'WScript.Echo strFileContents ' 'Create a regular expression object Set objRegExp = New RegExp objRegExp.Global = True objRegExp.IgnoreCase = True objRegExp.Pattern = strRegExp 'Get the matches Set colMatches = objRegExp.Execute(strFileContents) For Each objMatch In colMatches strReplacedText = objRegExp.Replace(strFileContents, strReplace) strMatch = strMatch & "Replaced match """ & objMatch.Value & """ with """_ & strReplace & """ at position " & objMatch.FirstIndex & vbCrLf Next If strMatch = "" Then strReplacedText=strFileContents End If end sub