home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / devtools / files / lb202win.exe / LB202W.EXE / ROLODEX1.BAS < prev    next >
Encoding:
BASIC Source File  |  2001-05-31  |  5.3 KB  |  202 lines

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