REM Export to QuickLink II Fax Phonebook Format (c)1995 InterApps Inc. REM REM This routine is designed to allow you to export any database file REM which contains a fax number field, and a company name/person's name REM field, into a format compatible with Smith Micro Systems QuickLink II REM fax format. This is the program that comes with USRobotics Sportster REM modems and many others. REM REM The program is kind-of patterned after the way the EXPORT command usually REM works where it prompts for a filename, and then prompts for a Filter. REM Because I had to be bothered, I put code into the function to "remember" REM which fields you picked, and which filter you last used. It writes REM these into the MACHINE.INI file, which is where all Machine-Dependant REM information should go. REM REM Note the clever use of Superbase.RaiseError to "throw" the same error REM that the EXPORT command would do if you attempted to perform an export REM without first opening up a database file. (Like the EXPORT command, I REM don't provide a file open dialog: instead the function fails.) Also note REM that we don't handle errors, although the program is pretty wise about REM not making any...(I hope) I Hate code that it littered with special REM errorhandlers. REM REM You are free to use this code in your own program, but if you improve REM on the design, please Email me a copy of the changes! Enjoy! REM REM -Mark Hripko. CompuServe: 71154,3414 AOL: MHripko@AOL.COM REM REM A very special thanks to SuperBase Guru Phil Alexander 100121,1001 REM for showing me how to write a binary file using the "kernel" functions! REM REM REM When Who Why REM 951115 Mark Hripko Initial Version 1.0 REM SUB main() CALL EXP2QL2() END SUB ' ************************************************************************* ' * EXP2QL2() - Export to QuickLink Fax PB ' * ' * Example : CALL EXP2QL2() ' * Result : The Export to QuickLink User Interface will appear... ' ************************************************************************* SUB EXP2QL2() DIM btn%% DIM fax_name%%,fax_old_dir$ DIM lpDefault$,lpReturn$ DIM retval$ REM Throw an error if we don't have a file open yet. IF FILE = "" THEN Superbase.RaiseError(44," ") REM QuickLink's path information is in the WIN.INI file... REGISTER CLEAR REGISTER "Kernel","GetProfileString","ICCCFI" a%% = CALL ("GetProfileString","Quick Link II Fax","InstallDirectory",lpDefault$,lpReturn$,80) REM Save the current subdir in case we switch... fax_old_dir$ = DIRECTORY IF EXISTS (lpReturn$) THEN DIRECTORY lpReturn$ retval$ = "FAXPHONE.LST" REQUEST "QuickLink File Name","",27,btn%%,retval$ DIRECTORY fax_old_dir$ REM Now go the work... IF btn%% = 1 THEN NULL%% = EXP2QuickLink%%( FILE ,retval$) END SUB ' ************************************************************************* ' * EXP2QuickLink%%(Source_File$,Dest_File$) - Export to QuickLink Fax PB. ' * ' * Example : IF EXP2QuickLink%%("PEOPLE","C:\QL2FAXW\DOMINION.LST") THEN BELL ' * Result : The QuickLink phonebook will be created. ' ************************************************************************* FUNCTION EXP2QuickLink%%(Src$,Dest$) DIM bits$,btnAttn%%,btnFax%% DIM CntProcessed%%,comma%%,comma1%% DIM did_ok%% DIM ex$ DIM flds$,FldFax$,FldAttn$ DIM i%% DIM LenFiller%% DIM NULL%% DIM saved_file$,saved_filter$ DIM w$ did_ok%% = - 1 REGISTER CLEAR REGISTER "kernel","_llseek","JHJI" REGISTER "kernel","_lopen","ICI" REGISTER "kernel","_lclose","II" REGISTER "kernel","_lcreat","ICI" REGISTER "kernel","_lwrite","IICI" REGISTER "Kernel","GetPrivateProfileString","ICCCFIC" REGISTER "Kernel","WritePrivateProfileString","ICCCC" REM Make sure the source file is open... of$ = Src$ CLEAR ERRNO SET ERROR OFF ALL IF NOT OPEN (of$) THEN OPEN FILE SHARE ,0of$ SET ERROR ON ALL IF ERRNO <> 0 THEN did_ok%% = 0 IF did_ok%% THEN REM Make sure the file is current... saved_file$ = FILE IF FILE <> FN root (Src$) THEN FILE FN root (Src$) REM Save the old filter, in case we should restore it... saved_filter$ = WHERE REM Now let's ask them for the matching information... a%% = CALL ("GetPrivateProfileString","Export","Quick Link Template for " + FILE ,"",Flds$,250,"MACHINE.INI") IF flds$ <> "" THEN comma%% = INSTR (Flds$,",") comma1%% = INSTR (comma%% + 1,Flds$,",") IF comma%% > 1 THEN FldFax$ = LEFT$ (flds$,comma%% - 1) FldAttn$ = MID$ (flds$,comma%% + 1,comma1%% - comma%% - 1) w$ = MID$ (flds$,comma1%% + 1) END IF END IF WHILE (btnAttn%% = 0 OR btnFax%% = 0) REQUEST "Select the Field that holds the FAX number","",5,btnFax%%,FldFax$ REQUEST "Select the Field that holds the Person's Name","or Company (or whatever you want in the Fax list)",5,btnAttn%%,FldAttn$ WEND REM Preload the filter, if it's there, or generate a useful one... IF w$ = "" THEN w$ = FldFax$ + " <> " + CHR$ (34) + CHR$ (34) ex$ = "SELECT WHERE " + w$ EXECUTE ex$ REM Let them set a filter as necessary... SET ERROR OFF ALL SELECT WHERE ASK SET ERROR ON ALL w$ = WHERE IF w$ <> "" THEN ex$ = "SELECT WHERE " + w$ EXECUTE ex$ END IF REM Write out the template information in MACHINE.INI for next time. flds$ = FldFax$ + "," + FldAttn$ + "," + w$ NULL%% = CALL ("WritePrivateProfileString","Export","Quick Link Template for " + FILE ,Flds$,"machine.ini") SELECT FIRST CntProcessed%% = 1 REM REM This is the point of no return. We are ready to create the FAX Phonebook. REM Currently, we only recreate. There is no update or merge allowed. REM IF EXISTS (Dest$) THEN DELETE Dest$ FileHand% = CALL ("_lcreat",Dest$,0) WHILE NOT EOF ( FILE ) REM Write the Null i%% = CALL ("_lwrite",FileHand%,"",1) REM Write the Group (currently null) i%% = CALL ("_lwrite",FileHand%,"",1) REM Write the Name of the entry... bits$ = FldAttn$$ i%% = CALL ("_lwrite",FileHand%,bits$, LEN (bits$)) LenFiller%% = 40 - LEN (bits$) FOR i%% = 1 TO LenFiller%%:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% REM Write 3 more nulls FOR i%% = 1 TO 3:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% REM Write the Fax Number IF LEN (FldFax$$) > 9 AND LEFT$ (FldFax$$,1) = "(" THEN bits$ = "1 " + FldFax$$ ELSE bits$ = FldFax$$ END IF i%% = CALL ("_lwrite",FileHand%,bits$, LEN (bits$)) LenFiller%% = 40 - LEN (bits$) FOR i%% = 1 TO LenFiller%%:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% REM Write 3 more nulls FOR i%% = 1 TO 3:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% REM Write the Attn: part of the entry... bits$ = FldAttn$$ i%% = CALL ("_lwrite",FileHand%,bits$, LEN (bits$)) LenFiller%% = 40 - LEN (bits$) FOR i%% = 1 TO LenFiller%%:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% REM Write the final Nulls FOR i%% = 1 TO 46:null%% = CALL ("_lwrite",FileHand%,"",1):NEXT i%% IF CntProcessed%% MOD 7 = 0 THEN Superbase.StatusText = "Records Exported: " + STR$ (CntProcessed%%,"z9999") + "." SELECT NEXT CntProcessed%% = CntProcessed%% + 1 WEND REM Close the Txt File FileHand% = CALL ("_lclose",FileHand%) REM Restore original filter (if it existed) or remove the filter we used... IF saved_filter$ <> "" THEN ex$ = "SELECT WHERE " + saved_filter$ EXECUTE ex$ ELSE SELECT WHERE END IF REM Restore the original file, if necessary... IF saved_file$ <> "" THEN FILE saved_file$ END IF Superbase.StatusText = "" EXP2QuickLink%% = did_ok%% END FUNCTION