Some questions spacePosition = INSTR( 1, lineStr) it says String expected here & gRestOfLine$ = MID$( spacePosition + 1 ) it says missing comma fix it A numeric or string value expected here gRestOfLine$ = MID$( spacePosition + 1 ) A expression expected here gRestOfLine$ = MID$( spacePosition + 1 ) Error: Expected an end ‘)’ here... Example: Too many parameters, or mismatched (). in file HBasic.proj:HBASIC.MAIN at line 842 in decodePRINT •gRestOfLine$ = MID$( spacePosition + 1 )• Error: Functions must be defined before using... in file HBasic.proj:HBASIC.MAIN at line 1094 in DoMenu •fn ParseEFLines•(_cEdit ) Error: End of Statement expected here... After compiling this statement, I encountered extra (Unexpected) information. Example: Too many parameters or missing operation(s). in file HBasic.proj:HBASIC.MAIN at line 1108 in DoMenu •fn ParseEFLines (•_cEdit) Error: Missing '=' or BEGIN ENUM when defining a constant in file HBasic.proj:HBASIC.MAIN at line 1108 in DoMenu fn ParseEFLines (•_cEdit•) Here's the full source RESOURCES "HBasic.rsrc","APPLHBas" //COMPILE 0, _strResource /* '~'A ' Runtime : Rntm Appearance.Incl ' Debugger : Off ' CPU : Carbon ' CALL Req'd : Off ' No Re-DIM'd Vars : On ' DIM'd Vars Only : On ' Debug Labels : On ' QB Labels : Off ' Optimize STR# : On ' Ary Bounds Checking : On ' Show Warnings : Off ' Register Vars : On ' Make Line Start Table : Off '~'B FB code generated by TWM (The Window Maker) <http://homepage.ntlworld.com/bernie.w/twmad.htm> Portions generated & © 2005 by TWM/Bernie Wylde Portions © 2005 by Stu Cram Portions © 2005 by Al Stafferri Jr. Portions © 2005 by various contributers on the FB list Portions © 2005 & 2006 by Brian Heibert */ KILL RESOURCES "ICN#",130 KILL RESOURCES "icl4",130 KILL RESOURCES "icl8",130 KILL RESOURCES "ics4", 128, "ics4",129, "ics8",128,"ics8",129,"ics8",130 KILL RESOURCES "FB3a",0 KILL RESOURCES "icm#",128, "icm#", 129, "icm4",128, "icm4",129 KILL RESOURCES "icm8", 128, "icm8",129, "icns",128 APPLE MENU "<BAbout HBasic...;About this Program..." edit menu 2 menu 2,7,1, "-" menu 2,8,1, "/ASelect All" menu 3,0,1, "Command" menu 3,1,1, "<B/RRun..." menu 3,2,1, "<I/BBuild Application..." num = 0 _mFile = 1 _iNew = 1 _iLine = 2 _iOpen = 3 _iMerge = 4 _iClose = 5 _iSaveAs = 7 _iSave = 8 //_iMerge = 9 _iPageSetup = 11 _iPrint = 12 menu _mFile,0,_Enable, "File" menu _mFile,_iNew,_Enable, "<B/NNew Program" menu _mFile,2,_Enable, "-" menu _mFile,_iOpen,_enable, "/OOpen..." menu _mFile,4,_enable, "-" menu _mFile,_iClose,_enable, "/WClose Window" menu _mFile,6,_enable, "-" menu _mFile,_iSaveAs,_enable, "Save Program as..." menu _mFile,_iSave,_enable, "/SSave Program" menu _mFile,_iMerge,_enable, "Merge..." menu _mFile,10,_enable, "-" menu _mFile,_iPageSetup,_enable, "Page Setup..." menu _mFile,_iPrint,_enable, "/PPrint..." DIM AS INT OSErr, @firstCustomHelpItem DIM AS HANDLE @hmHandle #If CarbonLib OSErr = FN HMGETHELPMENU(hmHandle,firstCustomHelpItem) #ELSE OSErr = FN HMGETHELPMENUHANDLE(hmHandle) firstCustomHelpItem = FN COUNTMITEMS(hmHandle)+1 #EndIf CALL APPENDMENU(hmHandle,"<B/?HBasic Help...") CALL APPENDMENU(hmHandle,"-") CALL APPENDMENU(hmHandle,"/1Programming Manual") CALL APPENDMENU(hmHandle,"/2HBasic on the Web") include "Tlbx SpeechSynthesis.Incl" Include "Subs AppleScript.Incl" #if CarbonLib = _false compile shutdown "HBasic only works in Carbon OSX" #endif LOCAL FN doBreak dim i CALL PARAMTEXT("","","","") i = FN STOPALERT (131,0) dim cancel IF i = 2 then cancel = _ztrue IF i = 1 then end END FN on break fn doBreak #IF cpuPPC <> 0 #If CarbonLib = 0 Library "ICAp;InternetConfigLib" #Endif #Define ICError As Long #Define ICInstance As Pointer Begin Record ICDirSpec Dim vRefNum As Short Dim dirID As Long End Record #Define ICDirSpecArrayPtr As Pointer To ICDirSpec Toolbox Fn ICStart(ICInstance * inst, OSType signature) = OSStatus Toolbox Fn ICLaunchURL(ICInstance inst, Str255 hint, Ptr * theData, Long length, Long * selStart, Long * selEnd) = OSStatus `0x2F3C, 0x0014, 0x0011, 0x7000, 0xA82A Toolbox Fn ICStop(ICInstance inst) = OSStatus #If CarbonLib = 0 Toolbox Fn ICFindConfigFile(ICInstance inst, Short count, ICDirSpecArrayPtr folders) = OSStatus `0x2F3C, 0x0006, 0x0002, 0x7000, 0xA82A Library #Endif '~'1 Clear Local Mode Local Fn GetMyCreator Dim creator As OSType Dim psn As ProcessSerialNumber Dim info As ProcessInfoRec Dim fSpec As FSSpec Dim appName As STR63 creator = _"????" Long If Fn GetCurrentProcess( psn ) = _noErr info.processInfoLength = 60 info.processName = @appName info.processAppSpec = @fSpec Long If Fn GetProcessInformation( psn, info ) = _noErr creator = info.processSignature End If End If End Fn = creator '~'1 Clear Local Mode Local Fn LaunchURL( @urlStr As ^Str255 ) Dim As Long err,junk,@ startSel,endSel Dim As ICInstance @ inst err = Fn ICStart( inst, Fn GetMyCreator ) Long If err = _noErr #If CarbonLib = 0 err = Fn ICFindConfigFile( inst, 0, _nil ) #Endif Long If err = _noErr startSel = 0 endSel = urlStr.nil$[0] err = Fn ICLaunchURL(inst,":",@urlStr.nil$[1],urlStr.nil $[0],startSel,endSel) End If junk = Fn ICStop( inst ) 'If err Then Stop "InternetConfig Error"+Str$(err) End If End Fn = err 'Fn LaunchURL("file:///Macintosh HD/test.html") #ENDIF LOCAL FN STRINGALERT1 (sal$) sal$ = MID$(restOfLine$,13) CALL PARAMTEXT (sal$,"","","") i = FN ALERT (128,0) EXIT FN END FN LOCAL FN NOTEALERT1 (MSG$) 'nla$ = MID$(lineStr,11) //msg$ = MID$(lineStr,11) CALL PARAMTEXT(MSG$,"","","") i = FN NOTEALERT (128,0) END FN LOCAL FN CAUTIONALERT1 (MSG$) CALL PARAMTEXT (MSG$,"","","") i = FN CAUTIONALERT (128,0) 'EXIT FN END FN LOCAL FN STOPALERT1 (MSG$) CALL PARAMTEXT (MSG$,"","","") i = FN STOPALERT (128,0) END FN LOCAL FN SPEAKABLEALERT (spAL$) MSG$ = spAL$ CALL PARAMTEXT (MSG$,"","","") i = FN ALERT (128,0) err = FN SPEAKSTRING (MSG$) END FN LOCAL FN ALERT1 (MSG$) CALL PARAMTEXT (MSG$,"","","") i = FN ALERT (128,0) END FN LOCAL FN ALERT2 (MSG$) CALL PARAMTEXT (MSG$,"","","") i = FN ALERT (128,0) END FN dim xi,sst sst = SYSTEM(_sysVers) long if system(_sysvers) <1030 CALL PARAMTEXT ("","","","") xi = FN STOPALERT (141,0) end end if dim stwelcome$,ans$,ans1$,sfl,wtxt$ stwelcome$ = STR#(128,1) Long if system(_macPlus) = _ztrue CALL PARAMTEXT("","","","") xi = FN STOPALERT (140,0) end end if 'speak stwelcome1$ = "Welcome to HBasic" dim ii,err err = FN speakString (stwelcome1$) CALL PARAMTEXT ("","","","") ii = FN ALERT (129,0) DIM x CALL PARAMTEXT ("","","","") x = FN ALERT (137,0) //Shareware Notice clear local #if ndef _gestaltSpeechMgrPresent _gestaltSpeechMgrPresent = 0 #endif local fn hasSpeechMgr' returns non-zero if Speech Mgr present dim @ speechAttr as long end fn = fn Gestalt(_"ttsc",speechAttr) = _noErr and (speechAttr and _gestaltSpeechMgrPresent%) Local Fn AnswerRequest( @instruction As .Str255 ) Dim As Str255 request, answer Dim As Handle resultHndl //Dim As OSErr err Long If instruction.1& =_"INPU" request = instruction.0$ request[6] = instruction.0`- 6 request = Pstr$(@request[6]) Route _toAppleScript Print "display dialog """""+request+""""" default answer """"" Print "return text returned of result" Route _toScreen err = Usr AppleScriptRun( answer ) resultHndl = Usr AppleScriptGetResult Long If err = _noErr answer[1] = answer[0]-2 answer = Pstr$(@answer[1]) Print answer End If End If End Fn begin enum 1 _Editor end enum begin enum 1 _cEdit _cScroll end enum #define FMFontFamily as SInt16 toolbox fn FMGetFontFamilyFromName(Str255 iName) = FMFontFamily xnum = +1 local fn BuildEditor dim as ControlFontStyleRec tfs dim as WindowAttributes wa dim as Rect r '~'< wa = _kWindowCloseBoxAttribute¬ _kWindowCollapseBoxAttribute SetRect(r, 0, 0, 635, 480)// Optional FB auto-centre //SetRect(r, 58, 128, 692, 608)// w: 640 h: 480 dim wt$ appearance window -_Editor,¬ wt$, @r,¬ _kDocumentWindowClass, wa def SetWindowBackground(_kThemeActiveDialogBackgroundBrush, _zTrue) '~'< SetRect(r, 0,0, 619, 471) s$ = "" color _zBlue edit field _cEdit, s$, @r, _framed_noDrawFocus, _leftJust edit text #_cEdit, fn FMGetFontFamilyFromName("Courier"), 13 text _Courier,13 SetRect(r, 619, 3, 634, 472) scroll button -_cEdit,0,0,0,0, @r, _scrollOther SetRect(r, 625, 1, 640, 474) //appearance button _cScroll,¬ // _activeBtn, 0, 0, 100,, @r,¬ // _kControlScrollBarProc //xnum = xnum + 1 wt$ = "HBasic ( "+xnum+ " )" appearance window _Editor, wt$ end fn local fn Init fn BuildEditor end fn FN init '~dims dim wnum,wtit$ dim rs$,nl1$ DIM gt1,gt2 DIM gt2$,gt3,c DIM crsr DIM sal$ DIM sxi$ DIM asc1$ DIM fsz dim wnumx,wtx$ dim wnumxNumber '-- DIM efHndl&, dataLine$, lineNum DIM spacePosition DIM keyWord$, restOfLine$ '-- /* Local fn ParseEFLines( efID as long ) // Obtain handle to selected edit field dim type,wd,wtype dim wnumx,wtx$ dim wnumxNumber dim wnumx,wtx$ dim wnumxNumber dim atxt$,atxt11$ DIM sal$ DIM sxi$ dim spxx$ dim nla$ DIM ast$,stxt1$,stx1$ dim size,size3,size4,size1,size2 dim abs2,abs3 dim rndm,rnum dim rnm1,rnm2 dim cl dim nl$ dim vl,final dim gt1,gt2 dim gt2$,gt3,c // Test for valid handle efHndl& = TEhandle( _cEdit ) FOR lineNum = 1 TO efHndl&..TEnLines% DIM efHndl&, dataLine$, lineNum DIM spacePosition dataLine$ = EDIT$( _cEdit, lineNum ) spacePosition = INSTR(1, dataLine$+" "," ") keyWord$ = LEFT$(dataLine$,spacePosition-1) restOfLine$ = MID$(dataLine$,spacePosition+1) SELECT UCASE$( keyWord$ ) CASE "WIN#" ' wnumx = VAL( restOfLine ) ' wtx$ = MID$(restOfLine,3) wnumx = RIGHT$(VAL(restOfLine),3) wtxt$ = RIGHT$(restOfLine,6) WINDOW wnumx, wtx$ // make the new window WINDOW _editor // and return to editor window CASE "PRINT;" dim nl$ nl$ = (restOfLine) WINDOW OUTPUT wnumx PRINT nl$; CASE "PRINT¬" dim nl$ nl$ = (restOfLine) WINDOW OUTPUT wnumx PRINT nl$; CASE "PRINTNUM" dim nmu nmu = restOfLine WINDOW OUTPUT wnumx PRINT nmu CASE "VAL" vl = VAL(restOfLine) final = VAL(vl) WINDOW OUTPUT wnumx PRINT final CASE "LETA" DIM gt1,gt2 gt1 = VAL(restOfLine) CASE "LETB" DIM gt1,gt2 gt2 = VAL(restOfLine) CASE "LETAOUTPUT" WINDOW OUTPUT wnumx PRINT gt1 CASE "LETBOUTPUT" WINDOW OUTPUT wnumx PRINT gt2 CASE "ADDLET" LET C = gt1+gt2 WINDOW OUTPUT wnumx PRINT C CASE "SUBTRACTLET" LET C = gt1-gt2 WINDOW OUTPUT wnumx PRINT C CASE "MULTIPLYLET" LET C = gt1*gt2 WINDOW OUTPUT wnumx PRINT C CASE "DIVIDELET" LET C = gt1/gt2 WINDOW OUTPUT wnumx PRINT C CASE "STR " ls$ = restOfLine final$ = ls$ WINDOW OUTPUT wnumx WINDOW wnumx TEXT wfid PRINT final$ CASE "ARROWCURSOR" CURSOR _arrowCursor DELAY 2000 CASE "WATCHCURSOR" CURSOR _watchCursor DELAY 2000 CASE "TEXTCURSOR" CURSOR _iBeamCursor DELAY 2000 CASE "CROSSCURSOR" CURSOR _crossCursor DELAY 2000 CASE "PLUSCURSOR" CURSOR _plusCursor DELAY 2000 CASE "HANDCURSOR" CURSOR 128 DELAY 2000 CASE "POINTERCURSOR" CURSOR 129 DELAY 2000 CASE "STRING$=" sxi$ = restOfLine CASE "GET" gt$ = restOfLine WINDOW OUTPUT wnumx PRINT gt$; INPUT "";ans$ CASE "PGET" WINDOW OUTPUT wnumx PRINT ans$ CASE "INPUT" rx$ = STR#(128,4) //errx$ = "INPUT,INPUT$, USERASK have been replaced with GET & PGET." CALL PARAMTEXT (errx$,"","","") i = FN ALERT(128,0) CASE "INPUT$" rx$ = STR#(128,4) //errx$ = "INPUT,INPUT$, USERASK have been replaced with GET & PGET." CALL PARAMTEXT (errx$,"","","") i = FN ALERT(128,0) CASE "PSTR$" WINDOW OUTPUT wnumx TEXT wfid PRINT sxi$ CASE "SSTR$" long if fn hasSpeechMgr err = fn SpeakString (sxi$) while fn SpeechBusy wend xelse beep end if CASE "CSTR$" PRINT sxi$ long if fn hasSpeechMgr err = fn SpeakString (sxi$) while fn SpeechBusy wend xelse beep end if CASE "ASC" asc1$ = MID$(restOfLine,4) WINDOW OUTPUT wnumx PRINT ASC(asc1$) CASE "GETFNUM" getf$ = restOfLine CALL GETFNUM (fid%,getf$) sfl = STR#(128,7) WINDOW OUTPUT wnumx PRINT sfl+fid% CASE "NOTEALERT" MSG$ = restOfLine FN NOTEALERT1 (MSG$) CASE "STOPALERT" MSG$ = restOfLine FN STOPALERT1 (MSG$) CASE "SPEAKABLEALERT" spAL$ = restOfLine MSG$ = spAL$ FN SPEAKABLEALERT (MSG$) CASE "CAUTIONALERT" MSG1$ = restOfLine FN CAUTIONALERT1 (MSG1$) CASE "LAUNCHURL " url$ = restOfLine FN LaunchURL (url$) CASE "LAUNCHURL{FROMSTRING}" IF sxi$ = "" THEN BEEP Fn LaunchURL (sxi$) CASE "MAILTO" mail$ = restOfLine Fn LaunchURL ("mailto:"+mail$) CASE "AOL:" aol$ = restOfLine Fn LaunchURL ("AOL:"+aol$) CASE "SPEAKABLECAUTIONALERT" spc$ = restOfLine long if fn hasSpeechMgr err = fn SpeakString (spc$) while fn SpeechBusy wend FN CAUTIONALERT1 (spc$) xelse beep end if CASE "EASTEREGG" CALL PARAMTEXT("Suprise! Gotcha","","","") i = FN ALERT (132,0) CASE "VOICE{EASTEREGG}" err = FN speakString ("Suprise! Gotcha") CASE "STOPALERT" MSG$ = restofLine FN STOPALERT1 (MSG$) CASE "ALERT" DIM att$ alx2$ = restOfLine FN ALERT2 (alx2$) CASE "STR$=" stxt1$ = restOfLine CASE "?" WINDOW OUTPUT wnumx PRINT restOfLine CASE "SPEAKSTRING" long if fn hasSpeechMgr err = fn SpeakString (stxt1$) while fn SpeechBusy wend xelse beep end if CASE "PRINTSTRING" WINDOW OUTPUT wnumx PRINT stxt1$ CASE "SPEAK " stxt$ = restOfLine long if fn hasSpeechMgr err = fn SpeakString (stxt$) while fn SpeechBusy wend xelse beep end if CASE "TALK" stxt$ = restOfLine long if fn hasSpeechMgr err = fn SpeakString (stxt$) while fn SpeechBusy wend xelse beep end if CASE "EXITTOSHELL" EXITTOSHELL CASE "SHUTDOWN" SHUTDOWN CASE "SHUTDOWN$" SHUTDOWN restOfLine$ CASE "TIMER" wt = restOfLine DELAY wt CASE "WAIT" wt = restOfLine DELAY wt CASE "PAUSE" wt = restOfLine DELAY wt CASE "DELAY" wt = restOfLine DELAY wt CASE "UCPRINT" dim UC$ UC$ = UCASE$(restOfLine$) WINDOW OUTPUT wnumx PRINT UC$ CASE "LCPRINT" dim LC$ LC$ = restOfLine$ DEF LCASE(LC$) WINDOW OUTPUT wnumx PRINT LC$ CASE "FSIZE" DIM fsz fsz = VAL(restOfLine$) WINDOW OUTPUT wnumx TEXT ,fsz WINDOW _editor CASE "SYSTEM" SYSTEM CASE "DEFCOORDS1" defcoords = VAL(restOfLine) CASE "DEFCOORDS2" defcoords2 = VAL(restOfLine) CASE "DEFCOORDS3" defcoords3 = VAL(restOfLine) CASE "DEFCOORDS4" defcoords4 = VAL(restOfLine) CASE "SIZE1" size = restOfLine CASE "SIZE2" size2 = restOfLine CASE "SIZE3" size3 = restOfLine CASE "SIZE4" size4 = restOfLine CASE "SETUPWIN" WINDOW wnumx, wtx$, (size,size2)-(size3,size4) WINDOW OUTPUT wnumx CASE "ABS" abs2 = ABS(restOfLine) PRINT abs2 CASE "ABS;" abs2 = ABS(restOfLine) PRINT abs2; CASE "ABOUT" err = FN speakString ("Welcome to HBasic") CALL PARAMTEXT ("","","","") i = FN ALERT (129,0) CALL PARAMTEXT ("","","","") i = FN ALERT (137,0) CASE "RANDOMIZE TIMER" i = FN NOTEALERT (133,0) IF i = 1 then exitok=0 CASE "RANDOMIZETIMER" i = FN NOTEALERT (133,0) IF i = 1 then exitok=0 CASE "RANDOM" RANDOMIZE TIMER rndm = VAL(restOfLine) rnum = INT(RND(rndm)) WINDOW OUTPUT wnumx PRINT rnum CASE "RND" RANDOMIZE TIMER rndm = VAL(restOfLine) rnum = INT(RND(rndm)) WINDOW OUTPUT wnumx PRINT rnum CASE "ADDRND1" RANDOMIZE TIMER rnm1 = INT(RND(restOfLine)) CASE "ADDRND2" RANDOMIZE TIMER rnm2 = INT(RND(restOfLine)) CASE "FINALRND" WINDOW OUTPUT wnumx RANDOMIZE TIMER PRINT INT(RND(rnmm1))+INT(RND(rnm2)) CASE "FLASH" WINDOW OUTPUT wnumx DEF FLASH CASE "//" 'donothing CASE "CLS" CLS CASE "PRINT;" nl$ = restOfLine WINDOW OUTPUT wnumx PRINT nl$; CASE "PRINT¬" nl$ = restOfLine WINDOW OUTPUT wnumx PRINT nl$; CASE "PRINTNUM" nmu = VAL(restOfLine) WINDOW OUTPUT wnumx PRINT nmu CASE "VAL" vl = VAL(restOfLine) final = VAL(vl) WINDOW OUTPUT wnumx PRINT final CASE "LETA" gt1 = restOfLine CASE "LETB" gt2 = restOfLine CASE "LETAOUTPUT" WINDOW OUTPUT wnumx PRINT gt1 CASE "LETBOUTPUT" WINDOW OUTPUT wnumx PRINT gt2 CASE "ADDLET" LET C = gt1+gt2 WINDOW OUTPUT wnumx PRINT C CASE ELSE CALL PARAMTEXT ("Unknown Instruction on line#:"+STR$(lineNum), dataLine$, "","") i = FN ALERT (149,0) END SELECT NEXT lineNum end fn */ LOCAL FN decodeWIN DIM wNum, wTitle$ wNum = VAL( gRestOfLine ) ' <=== modified way, was wTitle$ = MID$(gRestOfLine,3) ' <=== modified way WINDOW wNum, wTitle$ // make the new window WINDOW _editor // and return to editor window gUserWndNum = wNum END FN LOCAL FN decodePRINT dim nl$ nl$ = (grestOfLine$) WINDOW OUTPUT wnumx PRINT nl$; END FN LOCAL FN decodeLETA END FN LOCAL FN ShowError END FN FOR lineNum = 1 to maxNumLines lineStr = EDIT$( _cEdit, lineNum ) spacePosition = INSTR( 1, lineStr) gKeyWord$ = LEFT$( lineStr, spacePosition-1 ) gRestOfLine$ = MID$( spacePosition + 1 ) SELECT gKeyWord$ CASE "PRINT" : FN decodePRINT CASE "LETA" : FN decodeLETA CASE "WIN#" : FN decodeWIN ' ... CASE ELSE : FN ShowError( "Invalid instruction", lineStr ) END SELECT NEXT lineNum //end if //end if //end fn txt2$ = EDIT$(_cEdit) DIM AS DOUBLE num1, num2 DIM AS STR255 txt1, txt2 DIM AS STR255 filename local fn fileError2 CALL PARAMTEXT("","","","") i = FN STOPALERT (135,0) End FN local fn fileError1 CALL PARAMTEXT ("","","","") i = FN STOPALERT (134,0) END FN LOCAL FN HandlesX Dim @EditH As Handle //Dim FileName //As Str63 Dim @Vol As Int END FN //override runtime FBDefaultErrorHandler //end fn local fn DoMenu dim as long menuID, itemID menuID = menu(_menuID) itemID = menu(_itemID) num = num +1 dim @refNumVar% select case( menuID ) case _mFile select (itemID) case _iNew '-- new ' find out how to tell if visible this is just a guess //Dim WindowRef @ wndRef& //wndRef = 1 //wndRef& = 1 DIM @wndRef1& Get Window wndNum, wndRef1& long if FN IsWindowVisible (wndRef1&) window close #_Editor xnum = num+ 1 //wt$ = "HBasic ( "+xnum+" )" xelse //what to do here? //xnum = xnum + 1 edit field _cEdit, "" menu //wt$ = "HBasic ( "+xnum+" )" window close #_Editor window close #1 xnum = xnum + 1 wt$ = "HBasic ("+xnum+")" fn buildEditor end if //num = num+1 case _iPageSetup DEF PAGE IF PRCANCEL = _False then beep case _iPrint DEF PRINTEDITFIELD(_cEdit) case _iOpen /* DIM fo1$ menu DEF OPEN "HBSf" dim wxn$,wt$ fo1$ = FILES$(_fOpen, "HBSf","Open HBasic file...",refNumVar%) if fo1$ = "" then beep: FN fileError2:EXIT FN wxn$ = "HBasic: "+fo1$+ " ( "+xnum+" ) " WINDOW #_Editor, fo1$+" - HBasic" wt$ = "HBasic ( "+xnum+" )" OPEN "R",2,fo1$'I 'LINE INPUT #2, txt$ //PRINT #1, txt$ READ #2, txt$ EDIT FIELD _cEdit,txt$ */ TEXT _Courier,13 DIM fileName$, refNumvar%, dataLine$ fileName$ = FILES$(_fopen, "HBSf", "Select a file:", refNumvar% ) IF fileName$ = "" THEN fn fileError2:EXIT FN OPEN "I", 2, fileName$, ,refNumVar% // clear previous contents of edit field TEXT _Courier,13 EDIT$( _cEdit ) = "" TEXT _Courier,13 // repeat loop while not End Of File WHILE NOT EOF( 2 ) // get the next line of text (up to 'return') LINE INPUT #2, dataLine$ // append it to end of info in edit field (with a 'return') TEXT _Courier,13 EDIT$( _cEdit, _maxInt,_maxInt ) = dataLine$ + chr$(13) WEND CLOSE #2 // set cursor at end of edit field's info SetSelect _maxInt, _maxInt WINDOW _Editor, "HBasic - "+filename$ Case _iClose wt1$ = wt$ + " "+STR$(xnum) CALL PARAMTEXT (wt1$,"","","") cli = FN ALERT (142,0) long if cli = 4 window close #_Editor xelse 'do nothing end if menu case _iSave menu dim ed$ dim fo$,txt$ txt$ = EDIT$(_cEdit) DIM fileName$, refNumVar% DIM efHndl&, dataLine$, lineNum //DEF OPEN "HBSfHBas" fo$ = FILES$(_fSave,"Save HBasic file as...","New Program.HBSf",refNumVar%) IF fo$ = "" then beep:FN fileError1:EXIT FN DEF OPEN "HBSf" OPEN "O", 1, fo$, ,refNumVar% efHndl& = TEhandle( _cEdit ) FOR lineNum = 1 TO efHndl&..TEnLines% dataLine$ = EDIT$( _cEdit, lineNum ) PRINT #1, dataLine$ NEXT lineNum CLOSE #1 WINDOW _Editor, "HBasic - "+fo$ //PRINT #1, txt$ //CLOSE #1 menu case _iSaveAs menu dim ed$ dim fo$,txt$ txt$ = EDIT$(_cEdit) DIM fileName$, refNumVar% DIM efHndl&, dataLine$, lineNum //DEF OPEN "HBSfHBas" fo$ = FILES$(_fSave,"Save HBasic file as...","New Program.HBSf",refNumVar%) IF fo$ = "" then beep:FN fileError1:EXIT FN DEF OPEN "HBSf" OPEN "O", 1, fo$, ,refNumVar% efHndl& = TEhandle( _cEdit ) FOR lineNum = 1 TO efHndl&..TEnLines% dataLine$ = EDIT$( _cEdit, lineNum ) PRINT #1, dataLine$ NEXT lineNum CLOSE #1 WINDOW _Editor, "HBasic - "+fo$ case _iMerge 'put merge code here merge$ = EDIT$(_cEdit) 'begin merge TEXT _Courier,13 DIM fileName$, refNumvar%, dataLine$ fileName$ = FILES$(_fopen, "HBSf", "Select a file:", refNumvar% ) IF fileName$ = "" THEN fn fileError2:EXIT FN OPEN "I", 2, fileName$, ,refNumVar% // clear previous contents of edit field TEXT _Courier,13 EDIT$(_cEdit) = EDIT$(_cEdit)+ EDIT$(_cEdit, _maxInt,_maxInt) + dataLine+ chr$(13) TEXT _Courier,13 // repeat loop while not End Of File WHILE NOT EOF( 2 ) // get the next line of text (up to 'return') LINE INPUT #2, dataLine$ // append it to end of info in edit field (with a 'return') TEXT _Courier,13 EDIT$( _cEdit, _maxInt,_maxInt) = dataLine$ WEND CLOSE #2 // set cursor at end of edit field's info SetSelect _maxInt, _maxInt WINDOW _Editor, "HBasic - "+filename$ 'end merge end select case 2 select (itemID) case 8 SetSelect 0,32767 end select case 3 select (itemID ) case 1 fn ParseEFLines(_cEdit ) menu case 2 appearance window -_Editor fo$ = FILES$(_fSave,"Save new application as...","New Program.app",refNumVar%) IF fo$ = "" then beep:FN fileError1:EXIT FN OPEN "O", 1, fo$, ,refNumVar% CLOSE #1 WINDOW _Editor, "HBasic - "+fo$ fn ParseEFLines (_cEdit) end select case _kHMHelpMenuID select itemID case 1 // 1 = HBasic Help case 3 // 3 = Programming Manual hbasicmanual$ = "http://www.hbasic.com/manual/" Fn LaunchURL (hbasicmanual$) case 4 // 4 = HBasic on the Web hbasicweb$ = "http://www.hbasic.com/" Fn LaunchURL(hbasicweb$) end select case _applemenu select( itemID ) case 1 dim i 'speak err = FN speakString ("Welcome to HBasic") CALL PARAMTEXT ("","","","") i = FN ALERT (129,0) ix = FN ALERT (137,0) case 2 'about CALL PARAMTEXT (abt$,"","","") i = FN ALERT (136,0) case 3 dim sp select( itemID ) case 3 : def fn quitprocedure: fn quitprocedure'gFBQuit = _zTrue end select case else select (itemID) case else fn quitprocedure end select menu end select end select menu end fn DIM cli Local fn DoDialog dim as long evnt, id evnt = dialog(0) id = dialog(evnt) select case( evnt ) case _wndClose select( id ) case 1 CALL PARAMTEXT (wt$,"","","") cli = FN ALERT (142,0) long if cli = 4 window close #_Editor menu xelse 'do nothing menu end if end select end select end fn local fn quitprocedure CALL PARAMTEXT (wt$,"","","") cli = FN ALERT (142,0) long if cli = 4 end xelse 'do nothing menu end if end fn ON MENU FN DoMenu ON DIALOG FN DoDialog IF gFBQuit = _zTrue then fn quitprocedure menu do handleevents until gFBQuit On Jan 14, 2006, at 4:04 PM, maxclass@... wrote: > Brian, > > In response to what George and Stu wrote I think these approaches > will all work but they can be made simpler in my opinion. 20 years > of dealing with Parsing PostScript file formats, and very > successfully I might add, has shown me that 2 basic FN's will > handle almost everything. > > They only depend on a simple stack being in place. I'll explain below > > 1. FN ParseLine > 2. FN ProcessStack > > Stack Sample Only for Demonstration Purposes > > //-------------------------------------------------------------------- > -------- > _maxStackDepth = 25 // Or more if needed. > > DIM 255 gTheLine$ > > DIM gNumItems& > > /*---------------------- The Stack Array ---------------------- > This is the stack in width (127) & depth (25). > It needs to be able to handle a single line of text > like that enclosed within qoutes as printable text. > Most items will be very short. > > Each line is read into gTheLine$ > > Example of what the line below would look like parsed (split up) > onto the stack. > > gTheLine$ =3D "The quick brown fox jumped" > > FN ParseLine > > [ The Stack Array would now hold these entries and look like this > with gNumItems& =[ 6 ] > > gStack$( 1 ) =3D "PRINT" > gStack$( 2 ) =3D "The" > gStack$( 3 ) =3D "quick" > gStack$( 4 ) =3D "brown" > gStack$( 5 ) =3D "fox" > gStack$( 6 ) =3D "jumped" > > */ > > DIM 127 gStack$( _maxStackDepth ) // Creates the Stack > //-------------------------------------------------------------------- > -------- > > I have found that it worked best for me to let the FN ParseLine > divide up the line first, then use a separate, FN ProcessStack, > deal with how to handle the pieces. > > Note: All line items are separated by spaces here. There is also > one other FN to Pop items off the stack and return to you in gPopOut$. > > Bottom line here is this. Once the line has been divided up into > its individual parts (like above) then the FN ProcessStack can take > them one at a time and deal with them any way it likes. > > The ParseLine function can also look for leading characters like > quotes, parenthesis, etc. > > For example, if the ParseLine function sees that the leading > chacter of the next part of the line to parse is a quote then it > knows that all of the following is a string and should be handled > as such. > > gTheLine$ =3D "PRINT "The quick brown fox jumped"" would then end > up on the stack as follows. > > gStack$( 1 ) =3D "PRINT" > gStack$( 2 ) =3D "The quick brown fox jumped" > > The FN ProcessStack would then Pop (get) the first item on the > stack (1) and look for a CASE that matches it. That would be > "PRINT". That case then knows that the second item on the stack (2) > contains the quoted string to print. [Example: PRINT gStack$( 2 )] > > You might even call this the "Divide and Conquer" method. Like I > said, 20 years of successfully doing this has never given call to > have to rewrite my code for these routines. They just work. > > Hope this helps you to visualize how this approach works. This > would eliminate 90% or your problems and you would never have to > use LEFT$, MID$, etc. again. > > Max Taylor > The MaxClass Guy > > -- >