Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a single UDF be used to put values in Diff. Variables

Status
Not open for further replies.

rskomal

Programmer
Feb 2, 2003
13
IN
Is it possible to repalce value of different variales with one database in a say/get system. Say I have 5/6 var. like

@ row, col get a valid MyPickListPrg()
@ row, col get b valid MyPickListPrg()
@ row, col get c valid MyPickListPrg()
@ row, col get d valid MyPickListPrg()
@ row, col get e valid MyPickListPrg()


Read

How should i use the function to pick a value from my database for a,b,c or d...While using function key.Please Help.

Thanks
Rs


 
i would store the items in a simple array and use achoice to each var, this way your not loading the get system.

bobby
 
You can pass the variable as a reference. In your example what you really should have done was:
@ row, col get a valid MyPickListPrg(a)
That way MyPickListPrg() receives the value of a to do its function. If you use @a thus:
@ row, col get a valid MyPickListPrg(@a)
Then you pass the actual (well a reference to the actual) variable so you can modify it within the function and it will modify the actual value.
Example:
@ 5,5 say 'Enter a number' get nNum valid AddTwoToIt(@nNum)

Function AddTwoToIt(nData)
nData += 2
Return .t.

Whatever number you enter, 2 gets added to it.

If you choose to use arrays then you could do a similar thing but arrays are always passed by reference (ie they don't need the @ in front of them) but you would need to pass the element number.
@ row, col get aData valid MyPickListPrg(aData,1)
Ian Boys
DTE Systems Ltd
 
Or something like:

Code:
local rv := ReadVar()

  if rv = "A"
    // check contents of a
  else
  if rv = "B"
    // check contents of b
..

Just very simple example, but has worked for me for years ;-)

HTH
TonHu
 
TonHu,
Doing that does tend to make functions a little less generic and it makes the function do more work. I do like to try to write "black box" functions wherever possible which should make them more reusable. Ian Boys
DTE Systems Ltd
 
But this not-so-'black-box' function is limited to 1 module of my app (1 data entry screen usually) so that is no problem.
For generic validations, I have my own screen-entry library, that handles default validations and datalookup the way I had in mind, as I developed it myself... ;-D

HTH
TonHu
 
It probably depends a lot on what you are doing. If somebody asks you to write a function to lookup data on a database and return a key then the black box approach is good. In reality, when you write a function to do something for your own system then you know more about it and it often ends up more "intelligent". Ian Boys
DTE Systems Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top