home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lb091.zip / ROLODEX1.BAS < prev    next >
BASIC Source File  |  1995-09-14  |  5KB  |  218 lines

  1.  
  2.     ' This simple Rolodex application is a demonstrator for
  3.     ' the registered version of Liberty BASIC 1.0 or higher version
  4.     ' programming system for Windows 3.x
  5.  
  6.     ' In this demo we touch upon adding buttons to a text window,
  7.     ' sequential file i/o, and more
  8.  
  9.     ' do not open a main window
  10.     nomainwin
  11.  
  12.     dim cards$(100) ' set up one hundred rolodex cards
  13.  
  14.     gosub [loadCards]
  15.  
  16.     if cardLimit = 0 then cards$(0) = "Shoptalk Systems" + chr$(13) + "508-872-5315" + chr$(13) : cardLimit = 1
  17.  
  18.     cardNumber = 0
  19.     WindowWidth = 225
  20.     WindowHeight = 226
  21.  
  22.     bmpbutton #rolo, "lbttn.bmp", [previous], UL, 5, 3
  23.     bmpbutton #rolo, "rbttn.bmp", [next], UL, 34, 3
  24.     bmpbutton #rolo, "addbttn.bmp", [add], UL, 63, 3
  25.     bmpbutton #rolo, "lensbttn.bmp", [find], UL, 92, 3
  26.     bmpbutton #rolo, "xoutbttn.bmp", [del], UL, 121, 3
  27.     bmpbutton #rolo, "tohdrive.bmp", [save], UL, 150, 3
  28.     texteditor #rolo.text, 5, 32, 213, 150
  29.     open "Liberty Rolodex" for window_nf as #rolo
  30.  
  31.     print #rolo, "trapclose [quit]"
  32.     print #rolo.text, cards$(cardNumber) ;
  33.  
  34.  
  35. [mainLoop]
  36.  
  37.     input r$
  38.     goto [mainLoop]
  39.  
  40.  
  41.  
  42. [loadCards]
  43.  
  44.     cardLimit = 0
  45.     open "rolodeck.dat" for input as #data
  46.  
  47.     if eof(#data) <> 0 then close #data : return
  48.  
  49.     while eof(#data) = 0 and cardLimit < 100 and line$ <> "EOF"
  50.         card$ = ""
  51.         line$ = ""
  52.         while line$ <> "EOC"  and line$ <> "EOF"   ' End Of Card
  53.             line input #data, line$
  54.             if line$ <> "EOC" then card$ = card$ + line$ + chr$(13)
  55.         wend
  56.         if line$ <> "EOF" then cards$(cardLimit) = card$  : cardLimit = cardLimit + 1
  57.     wend
  58.  
  59.     close #data
  60.  
  61.     return
  62.  
  63.  
  64.  
  65. [next]     ' >> was pressed. move foreward to the next card and display it
  66.  
  67.     if cardNumber + 1 >= cardLimit then [mainLoop]
  68.  
  69.     gosub [cardRead]
  70.  
  71.     cardNumber = cardNumber + 1
  72.     print #rolo.text, "!cls";
  73.     print #rolo.text, cards$(cardNumber);
  74.  
  75.     goto [mainLoop]
  76.  
  77.  
  78.  
  79. [previous]      ' << was pressed. back up to the previous card and display it
  80.  
  81.     if cardNumber <= 0 then [mainLoop]
  82.  
  83.     gosub [cardRead]
  84.  
  85.     cardNumber = cardNumber - 1
  86.     print #rolo.text, "!cls";
  87.     print #rolo.text, cards$(cardNumber);
  88.  
  89.     goto [mainLoop]
  90.  
  91.  
  92. [find]     ' Find was pressed. find and display the card containing findString$
  93.  
  94.     prompt "Find what?"; findString$
  95.  
  96.     for searchIndex = 0 to cardLimit - 1
  97.         matchIndex =  instr(cards$(searchIndex), findString$)
  98.         if matchIndex > 0 then cardNumber = searchIndex
  99.     next searchIndex
  100.  
  101.     print #rolo.text, "!cls";
  102.     print #rolo.text, cards$(cardNumber);
  103.  
  104.     goto [mainLoop]
  105.  
  106.  
  107. [add]     ' Add was pressed. add a new card to the end of the deck
  108.  
  109.     if cards$(cardNumber) = "" then [mainLoop]
  110.     if cardLimit >= 99 then [mainLoop]
  111.  
  112.     cardNumber = cardLimit
  113.  
  114.     print #rolo.text, "!cls";
  115.     print #rolo.text, "New Card."
  116.     print #rolo.text, "Click on Save When Done."
  117.     print #rolo.text, "!selectall"
  118.  
  119.     goto [mainLoop]
  120.  
  121.  
  122. [del]     ' Del was pressed. delete the currently displayed card
  123.  
  124.     if cardNumber = cardLimit then [mainLoop]
  125.  
  126.     confirm "Delete: Are you sure?" ; answer$
  127.     if answer$ = "no" then [mainLoop]
  128.  
  129.     for index = cardNumber + 1 to cardLimit
  130.         cards$(index-1) = cards$(index)
  131.     next index
  132.  
  133.     cardLimit = cardLimit - 1
  134.     if cardNumber = cardLimit and cardNumber > 0 then cardNumber = cardNumber - 1
  135.     if cardLimit = 0 then cardLimit = 1
  136.  
  137.     print #rolo.text, "!cls";
  138.     print #rolo.text, cards$(cardNumber);
  139.  
  140.     goto [mainLoop]
  141.  
  142.  
  143.  
  144. [save]     ' Save was pressed. save the entire deck of cards
  145.  
  146.     gosub [cardRead]
  147.     if cardNumber = cardLimit then cardLimit = cardLimit + 1
  148.  
  149.     ' save each card into rolodeck.dat ending each card with EOC
  150.     ' and ending the file in EOF
  151.     open "rolodeck.dat" for output as #data
  152.  
  153.     for index = 0 to cardLimit - 1
  154.         print #data, cards$(index); "EOC"
  155.     next index
  156.     print #data, "EOF"
  157.  
  158.     close #data
  159.  
  160.     goto [mainLoop]
  161.  
  162.  
  163. [quit]     ' close event occurred.. save the entire deck of cards
  164.  
  165.     confirm "Quit Rolodex?"; r$
  166.     if r$ = "no" then [mainLoop]
  167.  
  168.     gosub [cardRead]
  169.     if cardNumber = cardLimit then cardLimit = cardLimit + 1
  170.  
  171.     ' save each card into rolodeck.dat ending each card with EOC
  172.     ' and ending the file in EOF
  173.  
  174.     print #rolo.text, "!cls";
  175.     print #rolo.text, "Saving data..."
  176.  
  177.     open "rolodeck.dat" for output as #data
  178.  
  179.     for index = 0 to cardLimit - 1
  180.         print #data, cards$(index); "EOC"
  181.     next index
  182.     print #data, "EOF"
  183.  
  184.     close #data
  185.  
  186.     close #rolo
  187.  
  188.     end
  189.  
  190.  
  191. [cardRead]    ' read the contents of the window into the current card slot
  192.  
  193.  
  194.     print #rolo.text, "!modified?"
  195.     input #rolo.text, m$
  196.     if m$ = "false" then return
  197.  
  198.     ' find out how many lines of text are displayed
  199.     print #rolo.text, "!lines"
  200.     input #rolo.text, size
  201.  
  202.     ' place the contents of #rolo into card$
  203.     card$ = ""
  204.     for index = 1 to size
  205.         print #rolo.text, "!line "; index ;
  206.         input #rolo.text, line$
  207.         card$ = card$ + line$ + chr$(13)
  208.     next index
  209.  
  210.     ' remove extra blank lines from end of card
  211.     while right$(card$, 2) = chr$(13) + chr$(13)
  212.         card$ = left$(card$, len(card$) - 1)
  213.     wend
  214.  
  215.     cards$(cardNumber) = card$
  216.  
  217.     return
  218.