home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / linkdemo / linkdemo.frm (.txt) next >
Visual Basic Form  |  1992-01-05  |  14KB  |  298 lines

  1. Form1
  2. Linking/SmartFill Demo
  3. Form1
  4. Text1
  5. Command1
  6. List1
  7. Command2
  8.     Demo Info
  9. Command3
  10. Cancel
  11. txtEntry_Change
  12. String2Find!
  13. TxtEntry
  14. wIndex
  15. LstFindEntry
  16. Result
  17. SendMessage
  18. GetFocus
  19. LB_SELECTSTRINGq
  20. cmdClear_Click^
  21.     DropCombo
  22. AutoRedraw
  23. start
  24. LB_RESETCONTENT
  25. CurrentXj
  26. CmdClear
  27. CurrentY
  28. Height
  29. Totalz
  30. cmdOk
  31. cmdClearVB_Click
  32. whiel
  33.     ListCount
  34. cmdLoad_ClickL
  35. AddStr
  36. cmdOK_Click
  37. LstFindEntry_ClickS
  38.     SPEEDTYPE-
  39. SelStart
  40. List'
  41.     SelLength|
  42. Cbo_Last`
  43. SelectionStart
  44. txtEntry_KeyPress
  45. KeyAscii
  46. TxtLen
  47. txtEntry_KeyUp
  48. KeyCode
  49. Shift
  50. DontSearch"
  51. FALSE
  52. txtEntry_KeyDown
  53.     ListIndex
  54. Index
  55. LstFindIndex
  56. Lindexx
  57. STARTSPEEDTYPING
  58. Lscroll
  59.     TxtEntrly1
  60. LoadSampleDataV
  61. Form_Click
  62. @    Form_Load
  63. window_
  64. state
  65. LoadSomeSampleData
  66. WindowState
  67. Txt_Text1_Change"
  68.     Txt_Text1.
  69. Txt_Text1_KeyDownB
  70.     Lst_Link1N
  71. Lst_Link1_Click
  72. Cmd_Command1_Click
  73. SearchString
  74. StartSearch;
  75. TxtText1_Change
  76. TxtText1
  77. TxtText1_KeyDowni
  78. LstLink1`
  79. LstLink1_Click
  80. List1
  81. List1_Click3
  82. Text1
  83. Text1_Change
  84. Text1_KeyDownd
  85. Command1_Click
  86. wParm
  87. lparamU
  88. NewListIndex
  89. StartSmartFill
  90. NORMAL
  91. KEY_BACK
  92. KEY_DELETE?
  93. KEY_PGUPI
  94. KEY_PGDN
  95. KEY_UP
  96. KEY_DOWN
  97. Text1_KeyUp
  98. Command2_Click
  99.     Microsoft
  100. there
  101. product
  102. give[
  103. users
  104. Command3_Click
  105. MB_YESNO2
  106. ID_YESD
  107. MB_YESCANCEL
  108. IDYES
  109. andIf
  110. MB_OKCANCEL
  111. AText1
  112. sTemp
  113. lTemp
  114. characters
  115.     SmartFill
  116. typed
  117. enough
  118. MB_ICONINFORMATION
  119.      Title: LINKDEMO.FRM
  120.  Version: 1.0
  121.  Project: LINKDEMO.MAK
  122.    Description: Demonstration of Linked Text/ListBoxes and SmartFill Demo '
  123.  Author: Jack Presley
  124.  Created: Jan 4, 1992
  125.  Last Revision: Jan 4, 1992 23:00
  126.  Click on "Demo Info" for more information about this demonstration.
  127.  API Function Declarations.n
  128.  GetFocus returns hWnd% for the control with the
  129.  current focus.  VB's hWnd% only returns a value
  130.  for forms, not controls.d
  131.  This function does all the work of selecting thet
  132.  matching element in our linked list box.  It will do 
  133.  much more, such as clear a listbox with one call.  SeeS
  134.  the January 1992 "Inside Visual Basic" journal forf
  135.  more details.
  136.  Change this value to determine when to start filling in
  137.  text box with data from list box.  If the value is 2,
  138.  and a link exists, when the user types the 3rd character
  139.  the remaining characters will be filled in.
  140. LoadSampleData
  141.  Just some junk mail to put in our list box...
  142. Ralph"
  143. Janet"
  144. Lloyd"
  145. Thomas
  146. Andrew
  147. Anderson
  148. Anderman
  149. Beeson
  150. Martin
  151. McAngus"
  152. Caroline
  153. Joseph
  154. Steven
  155. Robert
  156. Sarah"
  157. Cindy"
  158. Karen"
  159. Dennis
  160. Gladys
  161. Form_Load
  162.  This is explained in Text1_Change
  163. List1_Click
  164.  This routine places the item which was clicked upon
  165.  into the Text box.  This in turn causes a Text1_Changen
  166.  event to occur, which resets the focus to the linkedk
  167.  text box.
  168. Text1_Change
  169.  If certain keys are pressed we do not want to searchr
  170.  the linked list box.  'DontSearch' is set in thet
  171.  Text1_KeyUp procedure.  See it for more info.
  172.  Can't pass Text1.Text "ByVal" so assign it to a
  173.  normal string variable...
  174.  Save our position in the text box
  175.  This is where our SmartFill will begin...
  176.  Start our search at the beginning...w
  177.  Set the focus to the linked list so we can geth
  178.  it's "hWnd%" value with GetFocust
  179.  Make the call...t
  180.  If we found a match and we want to search and we have
  181.  typed enough characters to start SmartFill...
  182.  restore the insertion point and selection...t
  183.  we had to change it to the list box, remember?!
  184. Command1_Click
  185. You did not select anyone.
  186. Link Demonstration
  187.  Nothing in the text box, leave...
  188.  We've hit the list
  189.  Test for a match...
  190. You have selected 
  191.  for updating.
  192. Link Demonstration
  193.  Exit now to avoid next test...s
  194.  The selection has failed both previous tests, must be
  195.  a new guy.  Do we add him/her or move on?
  196.  is not in the list.
  197. Would you like to add them to the list?"
  198. Link Demonstration
  199.  Add the item...
  200.  Highlight the new guy in the text and list boxes...
  201.  Let them start over
  202. Text1_KeyDown
  203.  This routine allows the user to scroll through the list box
  204.  while the focus is in the text box.  This simulates a link.
  205.  This routine needs to be in the KeyDown vs. KeyUp to allowl
  206.  the user to hold a key down and scroll.  You may experiment
  207.  and replace the work KeyDown with KeyUp in the Sub statemente
  208.  above and watch what happens when you press and hold the up
  209.  or down arrow, or PgUp/PgDn.D
  210.  If there is nothing in the list, leave...
  211.  A temp variable because I'm a lazy typer...
  212.  Determine how much to scroll with a PgUp or PgDnh
  213.  minimum
  214.  will use 1/10 of the total...
  215.  If the user presses the backspace or delete key, we don't want'
  216.  to search for a match in our linked listbox on this pass.  If
  217.  we did the search we would find a match and probably replace thea
  218.  text he just deleted with the same text.  The user could keep
  219.  typing, but could never back up or erase the selected text.  Yout
  220.  may change the TRUE (below) to FALSE to see what happens.
  221.  These lines do the scrolling in the list box.  The "KeyCode = 0" 
  222.  statement, effectively erases the keystroke so the text box is notn
  223.  affected.
  224.  Don't Change anything
  225.  Make sure the new ListIndex value is legal...
  226.  Set the new value...s
  227. Command2_Click
  228.  Define All messages first for a little faster response...
  229.    Linked Text/List Box and SmartFill Demonstration"
  230.                                    Jack Presley"
  231.                                     Version  1
  232.                                  January  4, 1992 
  233. This program demonstrates two effective tools which you may use 
  234. in your Visual Basic Applications.  The first is the Linked Text "
  235. and List box.  Although I had previously accomplished this "
  236. without any API calls by trapping keys, the recent article "
  237. 'Creating a new control--the Combo Dropdown List box' in 'Inside "
  238. Visual Basic' Vol. 2 No. 1 (January 1992) provided me with a "
  239. better and faster way to make the link. 
  240. As the user types in the text box, a 'greater than or equal to' 
  241. search is performed on the linked list box using whatever has 
  242. been typed into the text box as the key.  When the user presses 
  243. OK to confirm his choice, a simple comparison of the Text box 
  244. text and the Listbox index text will tell you if the text is in 
  245. the list box or not.  There's more... 
  246. I use this 'modified' control regularly in my database "
  247. applications.  I put the key field in a linked text/list box.  "
  248. When the user makes a selection in this control I can either "
  249. update the form with that records data or query the user if they "
  250. would like to add this as a new record.  I've got to admit that 
  251. the side affect I like the most is NO SCROLL controls are on my 
  252. forms!  The linked list/text box IS the scroll bar.  On small 
  253. forms I update the form with every Link_Change.  This makes  "
  254. scrolling a little slower, but lets the user browse through the 
  255. records.  On large forms I update the form with Link_DoubleClick "
  256. or Command1_Click, unless the user selects a browse option.  This 
  257. is just one example of the way I put Linked Text/List boxes to "
  258. use.  Click OK for information on SpeedFill... "
  259. SpeedFill is a real time saver.  It uses the match found in the 
  260. Linked List box to 'fill in' the remainder of the selection being 
  261. made in the Linked Text box.  You may  change the number of 
  262. keystrokes required to 'kick in' SpeedFill.  Normally you don't 
  263. want to start it until  after the second keystroke or so. 
  264. The way SpeedFill works is really pretty simple.  When a key is 
  265. pressed the program records how may characters are in the Text "
  266. box text.  If a match is found in the Linked list box, that text "
  267. is assigned to the Text box text.   Here's the magic:  Assign the 
  268. previous text length to the SelStart property and SelLength to "
  269. the length of the new Text box text.  Everything in the new 
  270. SUGGESTED text that was NOT typed by the user is highlighted.  "
  271. Since Windows replaces highlighted text with the next keystroke, "
  272. the user can simply keep typing until a match is made or the text 
  273. is complete.  I make this an option in all my apps."
  274. If you use the Linked Text/List box, SpeedFill is an easy option to give your users.
  275. This snippet of code and unsolicited advice is free. Please feel "
  276. free to use it as you wish.  BUT if you decide to upload it with "
  277. *ANY* changes, PLEASE, PLEASE remove my name and address from all the modules.
  278. Thanks, and good luck. "
  279. Jack Presley
  280. CIS: 70700,166  BIX: JackPresley
  281. Presley Computing"
  282. Route 4, Box 4171 Boerne, TX 78006
  283. (512) 755-9018
  284. (512) 977-0650 (FAX)
  285. I'm rarely on Bix and my presence on Compuserve is somewhat 
  286. inconsistent.  If you really need to get in touch, call or fax."
  287. P.S.  I will have a new address and phone numbers February 1, 1992."
  288. Link Demonstration
  289. Link Demonstration
  290. SpeedFill"
  291. Link Demonstration
  292. Command3_Click
  293.  Hopefully this isn't the end.  If you improve these
  294.  procedures, please let me and others know about it.
  295.  Everyone needs feedback; good or bad.
  296.  Thanks,
  297.  Jack Presley 
  298.