Create HTML File Programatically

Category: Internet

Date: 02-16-2022

Return to Index


 
'This is not a tutorial on HTML, just an example of how to write HTML
'code using PowerBASIC statements. In general, HTML is simply text
'so the Print# statements are the primary tool.
 
'Primary Code:
'Here are two simple examples which result in HTML files (.htm extension is used)
'Example #1:
'minimal HTML code - just a header and basic body tags
Sub PrintBasicHTML
   Open "mypage.htmFor Output As #1
   Print #1, "<html>"
   Print #1, "<body>"
   Print #1, "<h2>My Page</h2>"   'use additional statements as needed
   Print #1, "</body>"
   Print #1, "</html>"
   Close #1
End Sub
 
'Example #2:
'more complicated HTML code - header, image, table
Sub PrintMediumHTML
   Open "mypage.htmFor Output As #1
   Print #1, "<html>"
   Print #1, "<body>"
   Print #1, "<h2>My Page</h2>"   'use additional statements as needed
   Print #1, "<img src='images/mypicture.jpg'>"
   Print #1, "<table>"
   Print #1, "<tr><td>Row1Col1"
   Print #1, "<tr><td>Row2Col1"
   Print #1, "</table>"
   Print #1 "Copyright © GaryLBeene"
   Print #1, "</body>"
   Print #1, "</html>"
   Close #1
End Sub
 
'Notes:
'HTML browsers interpret < > symbols as the start and end of an HTML
'tag. If you want to display the symbol then you must use one of the
'following (other common symbols and their code are also listed).
   ' non-breaking space               
   '<  less than              <        <
   '>  greater than           >        >
   '&  ampersand              &       &
   '�  cent                   ¢      ¢
   '�  copyright              ©      ©
   '�  registered trademark   ®       ®
'See the code below for an example of putting these in the file.
 
'Compilable Example:  (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
 
Function PBMain() As Long
   Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add Button, hDlg, 100,"Push", 50,10,100,20
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
      PrintBasicHTML
   End If
End Function
 
Sub PrintBasicHTML
   Open "mypage.htmFor Output As #1
   Print #1, "<html>"
   Print #1, "<body>"
   Print #1, "<h2>My Page</h2>"            'use additional statements as needed
   Print #1, "© Gary L. Beene 2009"   'inserts a copyright symbol
   Print #1, "</body>"
   Print #1, "</html>"
   Close #1
End Sub
 
'gbs_00182
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm