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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread184-1249771 Hi, What I did

Status
Not open for further replies.

MagnusRon

Programmer
Nov 4, 2021
1
0
0
PH
thread184-1249771
Hi,
What I did was use the Select statement to create a cursor to get the structure of the table, append a blank record, go through the fields and identify their types. If a field is numeric, store the value 1.77777777 and then read the value of the field. If the field yields a 2, that numeric field has 0 decimals. If it yields 1.8, it has one decimal place. If 1.78, it has two decimals, etc.
Hope this helps. Warm Greetings from the Philippines!
 
MagnusRon,

Welcome to the forum. What you wrote is interesting, but did you realise that that thread is more than 15 years old, and was answered satisfactorily at the time?

By all means, post new information if you think it would be useful to other forum visitors. But it would be more helpful if you gave your post a meaningful title: one that will immediately indicate the subject of the thread, and one that people would be likely to find if they are using a search engine.

With that in mind, feel free to start a thread at any time, to post any tips you might want to share or to ask a question about VFP.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
MagnusRon,
I agree with Mike, to give a post a meaningful title.

It is of no use if you write something in a title whose meaning only you can immediately recognize yourself.
In most cases it helps if you start your query with

"How to ....".


Here are some examples:

How to import or insert a *.jpg file into a binary memo field
How to avoid wrong input in a text-field
How to find an error in a form
How to run a VFP9 exe on a Computer that has not VFP installed


As you can see, everyone in the forum then knows what is being asked.
Welcome to the forum.

Klaus






Peace worldwide - it starts here...
 
I wonder how you got there. Maybe you had the same problem, found this thread, but are not satisfied with what AFIELDS() tells?

You also have to know what N(n,m) means. n is the number of total places available, not only digits before the decimal point, but all places including the minus sign for negative numbers and the decimal point.

So an N(4,1) field allows a range of -9.9 to 99.9 and whenever you try to create a field with n<=m this will raise the error 1713.

Chriss
 
A good candidate for a new function:

Code:
FsizeEx(FieldName, 1)  && Returns FSIZE() equivalent
FsizeEx(FieldName, 2)  && Returns decimals
FsizeEx(FieldName, 3)  && Returns physical size stored in table

--
Rick C. Hodgin
 
Mike Lewis said:
I would suggest an optional third parameter:
Code:
FsizeEx(FieldName, 1[, nWorkArea | cTableAlias])

I don't see a way to do that with the exposed API we have from FoxPro. I could receive an nWorkArea and allow that if the parameter is present, and default to the current work area if not provided, but I don't see where I could take an alias and obtain the work area from it.

The user would have to do this:
Code:
FsizeEx(FieldName, 1, SELECT("cTableAlias"))

I think that's the only way I could get it to work. If anyone has suggestions I'm all ears.

--
Rick C. Hodgin
 
Rick, look at the definition of _FindVar. Notice the Nametable VFP maintains is both about variables and fields. There is a parameter where, that is essential..



Chriss
 
Yes. That's where I was looking. I saw where it takes parameters, but I don't see where I can get a work area number from an alias name.

From the VFP9 help:
[tt]_FindVar() fills in the passed Locator with information about a variable or field named nti that exists in a work area specified by where.

If where is –1, nti is assumed to be a memory variable.
If where is 1 – 225, nti is assumed to be a field in the work area of the specified number.
If where is 0, _FindVar first checks to see if nti is a memory variable. If it's not a memory variable, the current work area is checked for a field with the specified NTI.

_FindVar( ) returns True (an integer other than 0) if a variable or field nti is found in where; otherwise, _FindVar( ) returns False (0).[/tt]

I see it searches for:
1. A memory variable
2. An explicit work area number
3. Searches by name in order:
3a. A memory variable
3b. A field name in the current work area

But I don't see how to look it up by alias. Am I missing something?

--
Rick C. Hodgin
 
Rick,

Aliases are stored in the Name Table, too, and you can find them with _NameTableIndex( ) which gives you their nti and then you should get at information like their workarea number. I wonder if that's really just using a byte sd where 1-255 implies. You can easily check that by explicitly opening an alias in workarea 256 or higher. In general the nti is 16 bit.



Chriss
 
Rick,

When I suggested adding that third parameter, I must admit that I hadn't looked at the source, and I had no idea how feasible it would be. It was just a throw-away remark on my part.

But I see that Chris has already flagged up a possible approach.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I noticed the references to _Findvar() and other functions. And I can see the reference to _Findvar in the VFP9 help, which mentions that you need to :

SET LIBARY TO FINDVAR

But I find that this instruction results in File 'findvar.prg' does not exist. How do I get past this point? Would be grateful.

Thanks. Andrew

 
No, Andrew,

SET LIBRARY TO FINDVAR would only work if you compile a FLL from the sample code given in _FindVar. All this is for C/C++ programmers extending the VFP language by FLLs.
VFPs only given FLL is foxtools.fll in Home() and that doesn't have the FINDVAR function. It's also not a very useful function, just a demonstration for programmers how to work with _FindVar() of the library coming in the LCK.

You might get hands on what Rick is doing by getting his FLL, for now that contains all functionality of Christian Ehlscheid's FLL extended with an AdirEx recurse option.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top