home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / os2 / etelr212 / etsrch.vrm < prev    next >
Text File  |  1994-09-13  |  12KB  |  409 lines

  1. /* Custom mainline for macro */
  2.  
  3.     call RXFuncAdd "VRLoadFuncs", "VROBJ", "VRLoadFuncs"
  4.     call VRLoadFuncs
  5.  
  6.     _VREVersion = SubWord( VRVersion( "VRObj" ), 1, 1 )
  7.     if( _VREVersion < 2.10 )then do
  8.         call VRMessage "", "This program requires VX-REXX version 2.1 to run.", "Error!"
  9.         return 32000
  10.     end
  11.  
  12.     signal on SYNTAX name _VRESyntax
  13.     signal _VREMain
  14.  
  15. _VRESyntax:
  16.     parse source . . _VRESourceSpec
  17.     call VRMessage "", "Syntax error in" _VRESourceSpec "line" SIGL":" ErrorText(rc), "Error!"
  18.     call VRFini
  19.     exit 32000
  20.  
  21. _VREMain:
  22. /*:VRX         Main
  23. */
  24. /*  Main
  25. */
  26. Main:
  27. /*  Process the arguments.
  28.     Get the parent window.
  29. */
  30.     parse source . calledAs .
  31.     parent = ""
  32.     argCount = arg()
  33.     argOff = 0
  34.     if( calledAs \= "COMMAND" )then do
  35.         if argCount >= 1 then do
  36.             parent = arg(1)
  37.             argCount = argCount - 1
  38.             argOff = 1
  39.         end
  40.     end
  41.     InitArgs.0 = argCount
  42.     if( argCount > 0 )then do i = 1 to argCount
  43.         InitArgs.i = arg( i + argOff )
  44.     end
  45.     drop calledAs argCount argOff
  46.  
  47. /*  Load the windows
  48. */
  49.     call VRInit
  50.     parse source . . spec
  51.     _VREPrimaryWindowPath = ,
  52.         VRParseFileName( spec, "dpn" ) || ".VRW"
  53.     _VREPrimaryWindow = ,
  54.         VRLoad( parent, _VREPrimaryWindowPath )
  55.     drop parent spec
  56.     if( _VREPrimaryWindow == "" )then do
  57.         call VRMessage "", "Cannot load window:" VRError(), ,
  58.             "Error!"
  59.         _VREReturnValue = 32000
  60.         signal _VRELeaveMain
  61.     end
  62.  
  63. /*  Process events
  64. */
  65.     call Init
  66.     signal on halt
  67.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  68.         _VREEvent = VREvent()
  69.         interpret _VREEvent
  70.     end
  71. _VREHalt:
  72.     _VREReturnValue = Fini()
  73.     call VRDestroy _VREPrimaryWindow
  74. _VRELeaveMain:
  75.     call VRFini
  76. exit _VREReturnValue
  77.  
  78. VRLoadSecondary: procedure
  79.     name = arg( 1 )
  80.  
  81.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  82.     call VRMethod window, "CenterWindow"
  83.     call VRSet window, "Visible", 1
  84.     call VRMethod window, "Activate"
  85. return window
  86.  
  87. /*:VRX         EFValue_KeyPress
  88. */
  89. EFValue_KeyPress:
  90. if( VRGet( 'EFValue', 'KeyString' ) = '{Newline}' )then
  91.     call PBIns_Click
  92. return
  93.  
  94. /*:VRX         Fini
  95. */
  96. Fini:
  97.     window = VRWindow()
  98.     call VRSet window, "Visible", 0
  99.     drop window
  100. return 0
  101.  
  102. /*:VRX         Halt
  103. */
  104. Halt:
  105.     signal _VREHalt
  106. return
  107.  
  108. /*:VRX         Init
  109. */
  110. Init:
  111.     call VRMethod 'Application', 'GetVar', 'args.'
  112.     tID = args.1
  113.     AcctDir = args.2
  114.     window = VRWindow()
  115.     call VRMethod window, "CenterWindow"
  116.     call VRSet window, "Visible", 1
  117.     call VRMethod window, "Activate"
  118.     drop window
  119. return
  120.  
  121. /*:VRX         LBFields_DoubleClick
  122. */
  123. LBFields_DoubleClick:
  124. call VRMethod "LBFields", "GetSelectedStringList", "sel."
  125. if sel.0 = 0 then
  126.     return
  127. call VRMethod "MLESearch", "Insert", sel.1||' '
  128. call VRMethod 'PBContains', 'SetFocus'
  129. return
  130.  
  131. /*:VRX         MLESearch_KeyPress
  132. */
  133. MLESearch_KeyPress:
  134. if( VRGet( 'MLESearch', 'KeyString' ) = '{Newline}' )then do
  135.     call VRMethod 'PBSearch', 'SetFocus'
  136.     call PBSearch_Click
  137.     call VRSet 'MLESearch', 'KeyString', ''
  138. end
  139. return
  140.  
  141. /*:VRX         PBAnd_Click
  142. */
  143. PBAnd_Click:
  144. call VRMethod "MLESearch", "Insert", "& "
  145. call VRMethod 'EFValue', 'SetFocus'
  146. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  147. return
  148.  
  149. /*:VRX         PBCats_Click
  150. */
  151. PBCats_Click:
  152. if( \VRFileExists( AcctDir||'\category.dat' ) )then do
  153.     call VRMessage 'Screen', 'Category file not found.  ', 'Information'
  154.     call VRSet 'PBCats', 'Enabled', 0
  155.     return
  156. end
  157. DatFile = AcctDir||'\category.dat'
  158. if( vrfileexists( DatFile ) )then do
  159.     call stream DatFile, 'c', 'close'
  160.     call stream DatFile, 'c', 'open'
  161.     call stream DatFile, 'c', 'seek =1'
  162.     cats.0 = 0
  163.     count = 1
  164.     do forever
  165.         if( Lines( DatFile ) = 0 )then
  166.             leave
  167.         line = linein( DatFile )
  168.         if line <> '' then do
  169.             cats.count = line
  170.             cats.0 = count
  171.             count = count + 1
  172.         end
  173.     end
  174.     call stream DatFile, 'c', 'close'
  175. end
  176. drop count appval lineval
  177. if cats.0 = 0 then do
  178.     call VRMessage VRWindow(), 'Categories were not found.  ', 'Information'
  179.     return
  180. end
  181. call VRMethod 'Application', 'PutVar', 'cats.'
  182. call 'macros\etcat.VRM'
  183. call VRMethod 'Application', 'GetVar', 'rc'
  184. if rc <> 'ERROR' then
  185.     ok = VRMethod( "MLESearch", "Insert", '"'||rc||'" ' )
  186. drop rc cats.
  187. return
  188.  
  189. /*:VRX         PBClear_Click
  190. */
  191. PBClear_Click:
  192. call VRSet 'MLESearch', 'Value', '', 'UserData', ''
  193. return
  194.  
  195. /*:VRX         PBContains_Click
  196. */
  197. PBContains_Click:
  198. call VRMethod "MLESearch", "Insert", "? "
  199. call VRMethod 'EFValue', 'SetFocus'
  200. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  201. return
  202.  
  203. /*:VRX         PBEquals_Click
  204. */
  205. PBEquals_Click:
  206. call VRMethod "MLESearch", "Insert", "= "
  207. call VRMethod 'EFValue', 'SetFocus'
  208. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  209. return
  210.  
  211. /*:VRX         PBGreater_Click
  212. */
  213. PBGreater_Click:
  214. call VRMethod "MLESearch", "Insert", "> "
  215. call VRMethod 'EFValue', 'SetFocus'
  216. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  217. return
  218.  
  219. /*:VRX         PBIns_Click
  220. */
  221. PBIns_Click:
  222. call VRMethod "MLESearch", "Insert", '"'||Translate( VRGet( "EFValue", "Value" ) )||'" '
  223. call VRMethod 'PBSearch', 'SetFocus'
  224. return
  225.  
  226. /*:VRX         PBLess_Click
  227. */
  228. PBLess_Click:
  229. call VRMethod "MLESearch", "Insert", "< "
  230. call VRMethod 'EFValue', 'SetFocus'
  231. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  232. return
  233.  
  234. /*:VRX         PBNotContains_Click
  235. */
  236. PBNotContains_Click:
  237. call VRMethod "MLESearch", "Insert", "! "
  238. call VRMethod 'EFValue', 'SetFocus'
  239. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  240. return
  241.  
  242. /*:VRX         PBNotEquals_Click
  243. */
  244. PBNotEquals_Click:
  245. call VRMethod "MLESearch", "Insert", "<> "
  246. call VRMethod 'EFValue', 'SetFocus'
  247. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  248. return
  249.  
  250. /*:VRX         PBOr_Click
  251. */
  252. PBOr_Click:
  253. call VRMethod "MLESearch", "Insert", "| "
  254. call VRMethod 'EFValue', 'SetFocus'
  255. call VRSet 'EFValue', 'SelectedStart', 1, 'SelectedEnd', Length( VRGet( 'EFValue', 'Value' ) ) + 1
  256. return
  257.  
  258. /*:VRX         PBSearch_Click
  259. */
  260. PBSearch_Click:
  261. /*
  262.  * Check criteria syntax
  263.  */
  264. Search = Translate( VRGet( 'MLESearch', 'Value' ) )
  265. if Search = '' then do
  266.     call VRMessage 'Screen', 'Search criterion not defined.  Nothing to do.  ', 'Information'
  267.     return
  268. end
  269. pos = POS( '"0"', search )
  270. if pos <> 0 then 
  271.     do until pos = 0
  272.         search = DelStr( search, pos + 1, 1 )
  273.         pos = POS( '"0"', search )
  274.     end
  275. pos = POS( '"0.0"', search )
  276. if pos <> 0 then
  277.     do until pos = 0
  278.         search = DelStr( search, pos + 1, 3 )
  279.         pos = POS( '"0.0"', search )
  280.     end
  281. pos = POS( '"0.00"', search )
  282. if pos <> 0 then
  283.     do until pos = 0
  284.         search = DelStr( search, pos + 1, 4 )
  285.         pos = POS( '"0.00"', search )
  286.     end
  287. pos = POS( '"0,0"', search )
  288. if pos <> 0 then
  289.     do until pos = 0
  290.         search = DelStr( search, pos + 1, 3 )
  291.         pos = POS( '"0,0"', search )
  292.     end
  293. pos = POS( '"0,00"', search )
  294. if pos <> 0 then
  295.     do until pos = 0
  296.         search = DelStr( search, pos + 1, 4 )
  297.         pos = POS( '"0,00"', search )
  298.     end
  299. drop pos
  300. call VRSet 'MLESearch', 'Value', Search
  301. /*
  302.  * Build formatted MLE string
  303.  */
  304. tmpSearch = Search
  305. newSearch = ''
  306. do until tmpSearch = ''
  307.     didContains = 0
  308.     word  = Translate( Word( tmpSearch, 1 ) )
  309.     if word = '' then
  310.         leave
  311.     if( word <> 'DATE' & word <> 'NUMBER' & word <> 'PARTICULARS' & word <> 'CREDIT' & word <> 'DEBIT' & word <> 'BALANCE' & word <> 'MEMO' & word <> 'CATEGORY' & word <> 'MULTICATEGORY' & word <> '|' & word <> '&' & word <> '!' )then do
  312.         call VRMessage 'SWSearch', 'Syntax error:  field not found.  ', 'Error'
  313.         return
  314.     end
  315.     if( word = 'DATE' | word = 'NUMBER' | word = 'PARTICULARS' | word = 'CREDIT' | word = 'DEBIT' | word = 'BALANCE' | word = 'MEMO' | word = 'CATEGORY' | word = 'MULTICATEGORY' )then do
  316.             val = 'Translate( rec.i.!'||word' )'
  317.         tmpSearch = DelWord( tmpSearch, 1, 1 )
  318.         word = Word( tmpSearch, 1 )
  319.         if( word <> '?' & word <> '>' & word <> '<' & word <> '<>' & word <> '=' & word <> '!' )then do
  320.             call VRMessage 'SWSearch', 'Syntax error:  symbol not found.  ', 'Error'
  321.             return
  322.         end
  323.         if( word = '?' | word = '!' )then do
  324.             didContains = 1
  325.             tmpSearch = DelWord( tmpSearch, 1, 1 )
  326.             tmpword = word
  327.             word = ''
  328.             if( Left( tmpSearch, 1 ) <> '"' )then do
  329.                 call VRMessage 'SWSearch', 'Syntax error:  start quote not found.  ', 'Error'
  330.                 return
  331.             end; else do
  332.                 position  = Pos( '"', tmpSearch, 2 )
  333.                 if position = 0 then do
  334.                     call VRMessage 'SWSearch', 'Syntax error:  end quote not found.  ', 'Error'
  335.                     return
  336.                 end
  337.                 if tmpword = '?' then
  338.                     newSearch = newSearch||' POS( '||SubStr( tmpSearch, 1, position + 1 )||', '||val||' ) <> 0'
  339.                 else
  340.                     newSearch = newSearch||' POS( '||SubStr( tmpSearch, 1, position + 1 )||', '||val||' ) = 0'
  341.                 drop tmpword
  342.                 tmpSearch = DelStr( tmpSearch, 1, position + 1 )
  343.             end            
  344.         end
  345.         if( word = '>' | word = '<' | word = '<>' | word = '=' )then do
  346.             key = word
  347.             tmpSearch = DelWord( tmpSearch, 1, 1 )
  348.             word = ''
  349.         end
  350.         if didContains = 0 then do
  351.             if( Left( tmpSearch, 1 ) <> '"' )then do
  352.                 call VRMessage 'SWSearch', 'Syntax error:  start quote not found.  ', 'Error'
  353.                 return
  354.             end; else do
  355.                 position  = Pos( '"', tmpSearch, 2 )
  356.                 if position = 0 then do
  357.                     call VRMessage 'SWSearch', 'Syntax error:  end quote not found.  ', 'Error'
  358.                     return
  359.                 end
  360.                 string = SubStr( tmpSearch, 1, position + 1 )
  361.                 tmpSearch = DelStr( tmpSearch, 1, position + 1 )
  362.             end            
  363.             newSearch = newSearch||' '||val||' '||key||' '||string
  364.         end
  365.     end
  366.     if( word = '|' | word = '&' )then do
  367.         newSearch = newSearch||' '||word
  368.         tmpSearch = DelWord( tmpSearch, 1, 1 )
  369.     end
  370. end
  371. newSearch = Strip( newSearch, 'L', ' ' )
  372. newSearch = Strip( newSearch, 'T', ' ' )
  373. call VRSet 'MLESearch', 'UserData', newSearch
  374. rc = newSearch
  375. call VRMethod 'Application', 'PutVar', 'rc'
  376. call VRSet 'PBUndo', 'Enabled', 1
  377. call VRMethod 'Application', 'PostQueue', tID, 1, 'call PerformSearch'
  378. drop search field key tmpSearch didContains string newSearch
  379. return
  380.  
  381. /*:VRX         PBUndo_Click
  382. */
  383. PBUndo_Click:
  384. call VRMethod 'Application', 'PostQueue', tID, 1, 'call UndoSearch'
  385. call VRSet 'PBUndo', 'Enabled', 0
  386. return
  387.  
  388. /*:VRX         Quit
  389. */
  390. Quit:
  391.     call VRMethod 'Application', 'PostQueue', tID, 1, 'call UndoSearch'
  392.     window = VRWindow()
  393.     call VRSet window, "Shutdown", 1
  394.     drop window
  395. return
  396.  
  397. /*:VRX         Window1_Close
  398. */
  399. Window1_Close:
  400.     call Quit
  401. return
  402.  
  403. /*:VRX         Window1_Help
  404. */
  405. Window1_Help: 
  406. address cmd 'view e-teller Search Feature'
  407. return
  408.  
  409.