Converting JB Newsletters to Run BASIC

General Computer Utilities
Post Reply
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Converting JB Newsletters to Run BASIC

Post by JanetTerra »

A simple converter from plain html to Run BASIC. Code needs to be added to accomodate images. No support for tables. No CSS support. Program was tested using a saved source file of Adding Pizzaz to JB Programs with Help with this output
Call SetCSS

Cls

Html "<Script>document.title = 'Adding Pizzaz To JB Programs With HELP'</Script>"

Div MainContainer

Div LogoContainer
Html "<img src='http://www.justbasic.com/justbasictitle.jpg' alt=''>"
End Div

Div h2
Print "Adding Pizzaz To JB Programs With HELP"
End Div

Div h3
Print "Welopez"
End Div

Div para
Print "A long time ago, in Small-town, USA, life was much simpler. A teen-age hot rodder or shade-tree mechanic could take a screw-driver, a pair of pliers, and a ";Chr$(34);"knuckle-buster";Chr$(34);" (adjustable wrench) into the back yard, pop the hood on the family jitney, and perform anything short of a complete engine replacement. He could probably do that too, and wouldn't hesitate to attempt the task, but special tools might make it easier."
End Div

Div para
Print "So it is with personal computers, programming in general, and programming in Just Basic specifically. When you write simple programs, such as ";Chr$(34);"Guess a Number";Chr$(34);" or ";Chr$(34);"EZ Calculator,";Chr$(34);" you don't have to provide much information to the user. By adding common icons, most users will know how to start, make an entry, and quit, without needing help files."
End Div

Div para
Print "As programs become more complicated, limited prompting can be made with STATICTEXT boxes. A larger program may require a text file to explain what the program is intended to do, what options are available, and what shortcuts are provided for common tasks. The simplest help files are text files you create with your word processor."
End Div

Div para
Print "When applications become even larger, HTML and CHM files are used as help files. HTML help files are web pages displayed in your browser. They can easily be created using word pad (if you know HTML markup language), or you can use an HTML editor to produce web pages for you as easily as typing a word document. MS Word can be used to create web pages, including colors, links, and images. Simply prepare your help file and click on File, choose Save as Web Page, and an HTML file will be created for you."
End Div

Div para
Print "If you create an HTML file for your program, you will have to include any images, sounds, or other supporting files with needed for the web page."
End Div

Div para
Print "Another type of help file is the CHM, or compiled help file. This consists of one or more HTML files, images, and sounds, compiled as a single stand alone file. You must first create HTML files for your program, then compile them using an application such as MS Visual CHM, which can be downloaded free from http://msdn.microsoft.com/library/defau ... nloads.asp. See Alyce Watson's tutorial in Liberty NL#108 for examples using this Wizard. http://babek.info/libertybasicfiles/lbn ... 08/chm.htm"
End Div

Div para
Print "Using Visual CHM is fairly simple, as explained in the newsletter. Alyce illustrates an API call to run a CHM file, which cannot be used in Just Basic, but she kindly provided me with a work around which can be used with JB."
End Div

Div para
Print "Here is the code for this DEMO."
End Div

Div pre
Print " "
Print "'Running Help Files with Just Basic"
Print " "
Print " "
Print "NOMAINWIN"
Print " "
Print " "
Print "WindowWidth=200"
Print " "
Print "WindowHeight=150"
Print " "
Print "UpperLeftX=INT((DisplayWidth-WindowWidth)/2)"
Print " "
Print "UpperLeftY=INT((DisplayHeight-WindowHeight)/2)"
Print " "
Print " "
Print "STATICTEXT #w.stt, ";Chr$(34);"Please click a button.";Chr$(34);", 20, 10, 160, 25"
Print " "
Print "BUTTON #w.btn1, ";Chr$(34);"TEXT";Chr$(34);", [txt], UL, 20, 50, 60, 25"
Print " "
Print "BUTTON #w.btn2, ";Chr$(34);"HTML";Chr$(34);", [htm], UL, 20, 90, 60, 25"
Print " "
Print "BUTTON #w.btn3, ";Chr$(34);"CHM";Chr$(34);", [chm], UL, 120, 50, 60, 25"
Print " "
Print "BUTTON #w.btn4, ";Chr$(34);"QUIT";Chr$(34);", [quit], UL, 120, 90, 60, 25"
Print " "
Print " "
Print "OPEN ";Chr$(34);"Help Files";Chr$(34);" for Window as #w"
Print " "
Print "PRINT #w, ";Chr$(34);"trapclose [quit]";Chr$(34);""
Print " "
Print "PRINT #w.stt, ";Chr$(34);"!font arial 12";Chr$(34);""
Print " "
Print " "
Print "WAIT"
Print " "
Print "[txt] 'Runs a text file."
Print " "
Print "RUN ";Chr$(34);"notepad myHelp.txt";Chr$(34);""
Print " "
Print " "
Print "WAIT"
Print " "
Print "[htm] 'Runs an HTML file."
Print " "
Print "fileName$=DefaultDir$+";Chr$(34);"myHelp.htm";Chr$(34);""
Print " "
Print "RUN ";Chr$(34);"C:Program FilesInternet Exploreriexplore.exe ";Chr$(34);"+fileName$"
Print " "
Print " "
Print "WAIT"
Print " "
Print "[chm] 'Runs a compiled help file."
Print " "
Print "RUN ";Chr$(34);"hh myhelp.chm";Chr$(34);""
Print " "
Print " "
Print "WAIT"
Print " "
Print "[quit]"
Print " "
Print "CLOSE #w"
Print " "
Print "END"
Print " "
End Div

Div para
Print "The above code should be fairly straight forward. Running a help file as a text document simply requires RUN ";Chr$(34);"notepad myHelp.txt";Chr$(34);", where myHelp.txt is the name of the help file. NOTE the space within ";Chr$(34);"notepad myHelp.txt";Chr$(34);". A ";Chr$(34);"File not found";Chr$(34);" error will occur at runtime unless the help file is located within the same folder as the program, unless you provide the full path to the help file."
End Div

Div para
Print "Running an HTML help file can sometimes be as simple as running the text file. RUN ";Chr$(34);"explorer myHelp.htm";Chr$(34);" will usually open the browser and display the help file, but not always. Just as the family jitney has computer chips, seat belts, and air bags to provide safety to the family, some firewalls protect you from spy ware and viruses by isolating your browser. Because you cannot be certain of the configuration of your user's computer, you may need a little more complicated code to run an HTML file."
End Div

Div pre
Print " "
Print "fileName$=DefaultDir$+";Chr$(34);"myHelp.htm";Chr$(34);""
Print " "
Print "RUN ";Chr$(34);"C:Program FilesInternet Exploreriexplore.exe ";Chr$(34);"+fileName$"
Print " "
End Div

Div para
Print "Failure to include the space following iexplore.exe will cause an error at runtime. The first line assigns the full path of myHelp.htm to variable fileName$ which is added to the RUN command to run the browser and help file. This code will work for the 87% of users with Internet Explorer. If they use a different operating system, or have removed Internet Explorer in favor of another browser, the user will receive a ";Chr$(34);"File not found";Chr$(34);" error at runtime."
End Div

Div para
Print "The last form of help file in this DEMO, is the CHM file. You create your help file in the same manner as an HTML help file, and then compile it to myHelp.chm (or whatever filename is appropriate for you). All users should be able to run a CHM file. Because we cannot make an API or DLL call with Just Basic, we run a windows file, hh.exe located in the WINDOWS folder, to open and display myHelp.chm."
End Div

Div pre
Print " "
Print "RUN ";Chr$(34);"hh myHelp.chm";Chr$(34);""
Print " "
End Div

Div para
Print "Adding help files to your programs not only makes them look more professional, they are easier to understand by the user and save a lot of programming space where you might otherwise need to display STATICTEXT."
End Div

Div para
Print "When you are finished, you will have an attractive presentation which can be distributed to your friends to showcase the talents you have learned when writing programs with Just Basic."
End Div

Div QuitContainer
Link #quit, " Quit ", XbyLink
End Div

End Div

Wait



Sub SetCSS
cssID #MainContainer, "{
Margin-Top: 50px;
Margin-Left: 100px;
Width: 800px;
Background-Color: RGB(192 255 255);
Color: #333333;
Font-Family: 'Times New Roman';
Font-Size: 14pt;
Border-Style: Solid;
}"

cssID #LogoContainer, "{
Background-Color: White;
Padding: 25px 0px 25px 225px;
Border-Bottom-Style: Solid;
}"

cssID #h1, "{
Font-Family: 'Times New Roman';
Font-Size: 24pt;
Font-Weight: Bold;
Text-Align: Center;
Color: RGB(0 0 160);
Padding: 10px 0px 10px 0px;
}"

cssID #h2, "{
Font-Family: 'Times New Roman';
Font-Size: 20pt;
Font-Weight: Bold;
Text-Align: Center;
Color: RGB(48 224 160);
Padding: 10px 0px 10px 0px;
}"

cssID #h3, "{
Font-Family: 'Times New Roman';
Font-Size: 18pt;
Font-Weight: Bold;
Text-Align: Center;
Color: RGB(0 0 160);
Padding: 10px 0px 10px 0px;
}"

cssID #para, "{
Font-Family: 'Times New Roman';
Font-Size: 14pt;
Text-Indent: 30px;
Padding: 10px 20px 10px 20px;
}"

cssID #pre, "{
Background-Color: RGB(240 240 240);
Color: #330099;
Font-Family: 'Times New Roman';
Margin-Left: 50px;
Margin-Right: 50px;
Border-Style: Double;
Font-Size: 12pt;
Padding: 10px 30px 10px 30px;
}"

cssID #QuitContainer, "{
Background-Color: White;
Border-Top-Style: Solid;
Border-Color: #333333;
Padding: 50px 350px 50px 350px;
}"

End Sub

Sub XbyLink handle$
Cls
End
End Sub
Program is released as Open Source. Please share your improvements.
Edit: File removed. Please download most current version from Reply #1.
Janet
Last edited by JanetTerra on Sun Nov 25, 2007 5:05 pm, edited 2 times in total.
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Post by JanetTerra »

Version 2, file name SimpleHtm2RBConverter.bas.
Updated to preserve image and url tags, and some inline formatting (bold, italics, underline).
Attachments
SimpleHtm2RBConverter.zip
Zipped file contains 1 .bas file.
(3.52 KiB) Downloaded 297 times
Post Reply