| Lescasse Consulting |
| Home Company News Prices Download Buy Forums |
|
|
The RandomTable APL Web Services Here is the APL RandomTable Web Service function:
’ response„RandomTable;R;I;J;table
[1] ©’ RandomTable APL+Win Web Service
[2] ©’ (c) Eric Lescasse 14jan04
[3]
[4] table„?10 10½1000
[5]
[6] R„'<HTML><HEAD></HEAD>'
[7] R„R,Œtcnl,'<BODY>'
[8] R„R,Œtcnl,'<DIV ALIGN="center">'
[9] R„R,Œtcnl,'<H1>APL+Win Web Service</H1>'
[10] R„R,Œtcnl,'<H2>RandomTable</H2>'
[11] R„R,Œtcnl,'<FONT STYLE="font: 8pt Verdana, Helvetica, Arial, sans-serif;">'
[12] R„R,Œtcnl,'This APL+Win Web Service draws a 10 by 10 matrix of Random Numbers<BR>'
[13] R„R,Œtcnl,'and then generates an HTML response stream displaying this Random Numbers matrix<BR>'
[14] R„R,Œtcnl,'in a simple HTML table<BR> '
[15] R„R,Œtcnl,'</FONT>'
[16] R„R,Œtcnl,'<TABLE>',Œtcnl
[17] :for I :in ¼10
[18] R„R,Œtcnl,' <TR>',Œtcnl
[19] :for J :in ¼10
[20] R„R,Œtcnl,' <TD ALIGN="right">',(•table[I;J]),'</TD>',Œtcnl
[21] :end
[22] R„R,Œtcnl,' </TR>',Œtcnl
[23] :end
[24] R„R,Œtcnl,'</TABLE>',Œtcnl
[25] R„R,Œtcnl,'<BR>'
[26] R„R,Œtcnl,''
[27] R„R,Œtcnl,'<FONT STYLE="font: 7pt Verdana, Helvetica, Arial, sans-serif;">'
[28] R„R,Œtcnl,'(click on the Internet Explorer Refresh button to run the Web Service again)'
[29] R„R,Œtcnl,'</FONT>'
[30] R„R,Œtcnl,'</BODY>'
[31] R„R,Œtcnl,'</HTML>'
[32] response„R
[33]
’
Line 4 is all it takes to APL to compute the 10 by 10 matrix of random numbers. Lines 6 to 32 are just there to create some HTML code to render the random matrix in an HTML table with some ecplanations. The RandomTable2 APL Web Services Here is the second APL Web Service RandomTable2 APL function:
’ response„RandomTable2;R;I;J;file;tie;table
[1] ©’ RandomTable2 APL+Win Web Service
[2] ©’ (c) Eric Lescasse 14jan04
[3]
[4] table„?10 10½1000
[5]
[6] R„'<HTML><HEAD></HEAD>'
[7] R„R,Œtcnl,'<BODY>'
[8] R„R,Œtcnl,'<DIV ALIGN="center">'
[9] R„R,Œtcnl,'<H1>APL+Win Web Service</H1>'
[10] R„R,Œtcnl,'<H2>RandomTable2</H2>'
[11] R„R,Œtcnl,'<FONT STYLE="font: 8pt Verdana, Helvetica, Arial, sans-serif;">'
[12] R„R,Œtcnl,'This APL+Win Web Service draws a 10 by 10 matrix of Random Numbers<BR>'
[13] R„R,Œtcnl,'and then generates an HTML response stream with a VB Script using the Microsoft OWC<BR>'
[14] R„R,Œtcnl,'(Office Web Component) spreadsheet to display the Random Numbers table<BR><BR>'
[15] R„R,Œtcnl,'</FONT>'
[16] R„R,Œtcnl,''
[17] R„R,Œtcnl,'<OBJECT classid="clsid:0002E551-0000-0000-C000-000000000046" id="oSS" width=400 height=250 border="1"></OBJECT>'
[18] R„R,Œtcnl,'<BR><BR>'
[19] R„R,Œtcnl,''
[20] R„R,Œtcnl,'<FONT STYLE="font: 7pt Verdana, Helvetica, Arial, sans-serif;">'
[21] R„R,Œtcnl,'(click on the Internet Explorer Refresh button to run the Web Service again)'
[22] R„R,Œtcnl,'</FONT>'
[23] R„R,Œtcnl,''
[24] R„R,Œtcnl,'<SCRIPT LANGUAGE="VBScript">'
[25] R„R,Œtcnl,'<!--'
[26] R„R,Œtcnl,'Sub window_OnLoad()'
[27] R„R,Œtcnl,' Dim oSheet'
[28] R„R,Œtcnl,' Dim iNumCols'
[29] R„R,Œtcnl,' Dim iNumRows'
[30] R„R,Œtcnl,' Dim oTbarButton'
[31] R„R,Œtcnl,' Dim c'
[32] R„R,Œtcnl,' Set c = oSS.Constants'
[33] R„R,Œtcnl,' oSS.ScreenUpdating = False'
[34] R„R,Œtcnl,' ''Add a new worksheet.'
[35] R„R,Œtcnl,' Set oSheet = oSS.Worksheets.Add(1)'
[36] R„R,Œtcnl,' ''Delete all other worksheets.'
[37] R„R,Œtcnl,' Do While oSS.Worksheets.Count > 1'
[38] R„R,Œtcnl,' oSS.Worksheets(2).Delete'
[39] R„R,Œtcnl,' Loop'
[40] R„R,Œtcnl,' ''Name the new worksheet.'
[41] R„R,Œtcnl,' oSheet.Name = "RandomTable2"'
[42] R„R,Œtcnl,' ''Determine the number of rows and columns.'
[43] R„R,Œtcnl,' iNumRows = ',•1œ½table
[44] R„R,Œtcnl,' iNumCols = ',•2œ½table
[45] R„R,Œtcnl,' ''Format columns.'
[46] R„R,Œtcnl,' oSheet.Range(oSheet.Cells(1,1),oSheet.Cells(iNumRows,iNumCols)).HorizontalAlignment = c.xlHAlignRight'
[47] R„R,Œtcnl,' oSheet.Range(oSheet.Cells(1,1),oSheet.Cells(iNumRows,iNumCols)).NumberFormat = "#"'
[48] R„R,Œtcnl,' ''Show the title bar.'
[49] R„R,Œtcnl,' oSS.DisplayTitleBar = False'
[50] R„R,Œtcnl,' ''Hide the Microsoft Office logo on the toolbar.'
[51] R„R,Œtcnl,' oSS.DisplayOfficeLogo = False'
[52] R„R,Œtcnl,' ''Display the Toolbar.'
[53] R„R,Œtcnl,' oSS.DisplayToolbar = True'
[54] :for I :in ¼10
[55] :for J :in ¼10
[56] R„R,Œtcnl,' oSheet.Cells(',(•I),',',(•J),').Value = "',(•table[I;J]),'"'
[57] :end
[58] :end
[59] R„R,Œtcnl,' ''Remove the "Refresh All" and "Help" button from the toolbar.'
[60] R„R,Œtcnl,' On Error Resume Next'
[61] R„R,Œtcnl,' Set oTbarButton = oSS.Toolbar.Buttons("owc10061") ''Refresh All button'
[62] R„R,Œtcnl,' If Not Err.Number Then'
[63] R„R,Œtcnl,' oSS.Toolbar.Buttons.Remove oTbarButton.Index - 1'
[64] R„R,Œtcnl,' oSS.Toolbar.Buttons.Remove oTbarButton.Index'
[65] R„R,Œtcnl,' End If'
[66] R„R,Œtcnl,' Err.Clear'
[67] R„R,Œtcnl,' Set oTbarButton = oSS.Toolbar.Buttons("owc1006") ''Help button'
[68] R„R,Œtcnl,' If Not Err.Number Then'
[69] R„R,Œtcnl,' oSS.Toolbar.Buttons.Remove oTbarButton.Index - 1'
[70] R„R,Œtcnl,' oSS.Toolbar.Buttons.Remove oTbarButton.Index'
[71] R„R,Œtcnl,' End If'
[72] R„R,Œtcnl,' On Error GoTo 0'
[73] R„R,Œtcnl,' ''Apply window settings.'
[74] R„R,Œtcnl,' oSS.Windows(1).ViewableRange = oSheet.UsedRange.Address'
[75] R„R,Œtcnl,' oSS.Windows(1).DisplayRowHeadings = False'
[76] R„R,Œtcnl,' oSS.Windows(1).DisplayColumnHeadings = False'
[77] R„R,Œtcnl,' oSS.Windows(1).DisplayVerticalScrollBar = True'
[78] R„R,Œtcnl,' oSS.Windows(1).DisplayHorizontalScrollBar = True'
[79] R„R,Œtcnl,' ''Autofit the component on the Web page.'
[80] R„R,Œtcnl,' oSS.AutoFit = True'
[81] R„R,Œtcnl,' oSS.ScreenUpdating = True'
[82] R„R,Œtcnl,'End Sub'
[83] R„R,Œtcnl,'</script>'
[84] R„R,Œtcnl,'</HTML>'
[85] response„R
[86]
’
The chore of the Web Service is still the very simple line 4 which computes the 10 by 10 random table. But the rendering is more sophisticated this time: the code from line 6 to 86 uses an Microsoft OWC (Office Web Components) spreadsheet object, instantiated on line 17, to display the random matrix. From line 24 to 82 we use a VB Script routine to fill the spreadhsheet cells with values from our APL variable (lines 55 to 57) and to setup various spreadsheet properties for a nicer display (lines 61 to 81). ConclusionOf course we have used extremely simple APL Web Services here (as a matter of fact, a single APL instruction) but you could as well write Web services spanning hundreds of lines of APL code, using APL or native files, etc. APL+Win 5.0 and the APL+Web Services bring the extraordinary power of APL to the Web and to Internet! |
|||||||||||||||||||||
| This entire Web site has been dynamically generated by APL+Win Objects™ 6.0 For all questions contact: info@lescasse.com Copyright © 2003-2005 Lescasse Consulting. All rights reserved. |