Stepping through Fields in a .DBF 
Author Message
 Stepping through Fields in a .DBF

If I have a table with the following data in 12 fields called: Name, F1,
F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
Jim     10    5     7     9     6     8     4     7     3     5       64
Mark    9     7     9     4     8     7     3     0     5     4       59

Q. How do I step through the fields of each record in a table???

I want to create a program to step through each record in the table above
and bracket off the four lowest numbers in each record.

Below is the result I want to get.

Name    1     2     3     4     5     6     7     8     9     10      Total
Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47

Can anyone help me out with this??? I'm Stuck!!



Fri, 21 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:

>If I have a table with the following data in 12 fields called: Name, F1,
>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
>Jim     10    5     7     9     6     8     4     7     3     5       64
>Mark    9     7     9     4     8     7     3     0     5     4       59

>Q. How do I step through the fields of each record in a table???

>I want to create a program to step through each record in the table above
>and bracket off the four lowest numbers in each record.

>Below is the result I want to get.

>Name    1     2     3     4     5     6     7     8     9     10      Total
>Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
>Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47

>Can anyone help me out with this??? I'm Stuck!!

Try

FOR i=1 TO FCOUNT()
        _fname=FIELD(i)
        ....................
ENDFOR

Inside the FOR...ENDFOR  &_fname will give you value of ith field.



Fri, 21 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

B>If I have a table with the following data in 12 fields called: Name,
B>F1, F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

B>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10
B>Total Jim     10    5     7     9     6     8     4     7     3     5
B>64 Mark    9     7     9     4     8     7     3     0     5     4
B>59
B>Q. How do I step through the fields of each record in a table???

B>I want to create a program to step through each record in the table
B>above and bracket off the four lowest numbers in each record.

B>Below is the result I want to get.

B>Name    1     2     3     4     5     6     7     8     9     10
B>Total Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)
B>48 Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)
B>47
B>Can anyone help me out with this??? I'm Stuck!!

Since you want to add brackets to the fields I assume that the F1 to F10
fields are character fields since brackets are not valid characters for
numeric fields.

I also assumed that the F1 to F10 fields are fields numbers 2 to 11 in
the file structure.  If they are not you will have to adjust the
temp(x,2)= line in the code below.

The code scatters the fields (F1 to F10) to an array (temp1) and then
assigns the value of the numbers along with their corresponding fields
numbers to another array (temp).  The second array is then sorted on the
values from the field.  Since the sort is in ascending order the first 4
rows of the array now contain the four lowest numbers and their field
numbers.

The fields are then replace with the values converted to strings and
surrounded by brackets.

The if code in the first for loop is to remove any existing brackets in
the F1 to F10 fields, otherwise the character strings cannot be
converted to numeric values.

dime temp(10,2)
go top
scan
        scatter fields like F* to temp1
        for x =1 to 10
                if left(temp1(x),1)='('
                  *removes left bracket if it exits
                  temp1(x)=right(temp1(x),len(temp1(x))-1)
                endif
                temp(x,1) =val(temp1(x))
                temp(x,2)=x+1
        next
        =asort(temp)
        for x = 1 to 4
                replace (field(temp(x,2))) with ;
                  '('+alltrim(str(temp(x,1)))+')'
        next
ENDSCAN

Brian Copeland



Fri, 21 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:
>If I have a table with the following data in 12 fields called: Name, F1,
>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.
>Q. How do I step through the fields of each record in a table???

My first suggestion would be to split off your numbered fields to a seperate table with a
linking ID code to the 'names' table, a number for each F, and the value. Failing that, you
could either use AFIELDS() (look in the manual) to stuff an array with the names, or since you
know the names already, you could use straight name replacement and/or EVAL in a FOR loop:

E.g. this will replace all the Fn fields in the current record with 5 if they are less than 5.

FOR n=1 TO 10
   cField="F"+LTRIM(STR(n))    && creates a string like "F1", "F2" etc.
   IF EVAL(cField)<5
       REPLACE (cField) WITH 5
   ENDIF
ENDFOR

Note the use of EVAL() and the brackets around the name expression in the REPLACE.

______________________________________________________________________
   Alex D. Baxter of the Asymptomatic Carotid Surgery Trial (ACST).
        Administered from St. Mary's Hospital Medical School,
 a constituent college of Imperial College, University of London, UK.



Sat, 22 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:




Quote:
> Pidgeon) says:

>>If I have a table with the following data in 12 fields called: Name,
F1,
>>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

>>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      
Total
>>Jim     10    5     7     9     6     8     4     7     3     5      
64
>>Mark    9     7     9     4     8     7     3     0     5     4      
59

>>Q. How do I step through the fields of each record in a table???

>>I want to create a program to step through each record in the table
above
>>and bracket off the four lowest numbers in each record.

>>Below is the result I want to get.

>>Name    1     2     3     4     5     6     7     8     9     10      
Total
>>Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      
48
>>Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      
47

>>Can anyone help me out with this??? I'm Stuck!!

>Try

>FOR i=1 TO FCOUNT()
>        _fname=FIELD(i)
>        ....................
>ENDFOR

>Inside the FOR...ENDFOR  &_fname will give you value of ith field.

You may want to try EVAL(_fname) instead of the macro as it may be a
little faster
--
......................................................................

Technical Services Specialist              tel: 614-891-3442
Patriot Healthcare Development, Inc.       fax: 614-891-3444
Westerville  Ohio                          http://205.101.133.3/scheah
----------------------------------------------------------------------


Mon, 24 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:
>If I have a table with the following data in 12 fields called: Name, F1,
>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.
>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
>Jim     10    5     7     9     6     8     4     7     3     5       64
>Mark    9     7     9     4     8     7     3     0     5     4       59
>Q. How do I step through the fields of each record in a table???
>I want to create a program to step through each record in the table above
>and bracket off the four lowest numbers in each record.
>Below is the result I want to get.
>Name    1     2     3     4     5     6     7     8     9     10      Total
>Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
>Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47
>Can anyone help me out with this??? I'm Stuck!!

Hi, the problem you created is due to the table configuration.
It's easier to create the following table:
         NAME           F        Count
        Mark            1       9
        Mark            2       7 etc.
This way it's a piece of cake to solve your problem.                    

Leo van de Vorst
The Netherlands



Mon, 24 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF
B>Can anyone help me out with this??? I'm Stuck!!

Quote:

> Since you want to add brackets to the fields I assume that the F1 to F10
> fields are character fields since brackets are not valid characters for
> numeric fields.

> I also assumed that the F1 to F10 fields are fields numbers 2 to 11 in
> the file structure.  If they are not you will have to adjust the
> temp(x,2)= line in the code below.

> The code scatters the fields (F1 to F10) to an array (temp1) and then
> assigns the value of the numbers along with their corresponding fields
> numbers to another array (temp).  The second array is then sorted on the
> values from the field.  Since the sort is in ascending order the first 4
> rows of the array now contain the four lowest numbers and their field
> numbers.

> The fields are then replace with the values converted to strings and
> surrounded by brackets.

> The if code in the first for loop is to remove any existing brackets in
> the F1 to F10 fields, otherwise the character strings cannot be
> converted to numeric values.

> dime temp(10,2)
> go top
> scan
>    scatter fields like F* to temp1
>    for x =1 to 10
>                    if left(temp1(x),1)='('
>                      *removes left bracket if it exits
>                      temp1(x)=right(temp1(x),len(temp1(x))-1)
>                    endif
>                    temp(x,1) =val(temp1(x))
>                    temp(x,2)=x+1
>    next
>    =asort(temp)
>    for x = 1 to 4
>                    replace (field(temp(x,2))) with ;
>                   '('+alltrim(str(temp(x,1)))+')'
>    next
> ENDSCAN

> Brian Copeland


Thanks Brian,

It was perfect!!!

--
Cheers

Ian E Pidgeon
Sydney, Australia



Mon, 24 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:
>If I have a table with the following data in 12 fields called: Name, F1,
>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.
>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
>Jim     10    5     7     9     6     8     4     7     3     5       64
>Mark    9     7     9     4     8     7     3     0     5     4       59
>Q. How do I step through the fields of each record in a table???
>I want to create a program to step through each record in the table above
>and bracket off the four lowest numbers in each record.
>Below is the result I want to get.
>Name    1     2     3     4     5     6     7     8     9     10      Total
>Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
>Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47
>Can anyone help me out with this??? I'm Stuck!!

Your problem is due to the table structure.
You could use the next structure:
        NAME            F               COUNT
        Mark            1               9
        Mark            2               7 etc.

This way solving your problem is a piece of cake.

Leo van de Vorst
Maarheeze, The Netherlands



Tue, 25 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:

> >If I have a table with the following data in 12 fields called: Name, F1,
> >F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

> >Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
> >Jim     10    5     7     9     6     8     4     7     3     5       64
> >Mark    9     7     9     4     8     7     3     0     5     4       59

> >Q. How do I step through the fields of each record in a table???

> >I want to create a program to step through each record in the table above
> >and bracket off the four lowest numbers in each record.

> >Below is the result I want to get.

> >Name    1     2     3     4     5     6     7     8     9     10      Total
> >Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
> >Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47

> >Can anyone help me out with this??? I'm Stuck!!

> Hi, the problem you created is due to the table configuration.
> It's easier to create the following table:
>     NAME           F        Count
>    Mark            1       9
>    Mark            2       7 etc.
> This way it's a piece of cake to solve your problem.                      

> Leo van de Vorst

Leo is correct, in that yours is not the best table organization.  But,
sticking w/ yours, you can easily use the BROWSE command to do the things
you requested:

BROWSE Mytable FIELDS ;
myf1=lowerone(f1) :H="F1" :4, ;
etc.
myf10=lowerone(f10) :H="F10" :4, ;
mytotal=totalem() :H="TOTAL" :4

The UDF lowerone(fieldname) would, of course, return
"("+STR(fieldname,2,0)+")" if the value is one of the lower 4,
blanks in place of parens otherwise.
The UDF totalem() would be just
RETURN STR(f1+f2+...+f10,3,0)

Hope this helps,
-mark



Tue, 25 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF

Quote:
>If I have a table with the following data in 12 fields called: Name, F1,
>F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.
>Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
>Jim     10    5     7     9     6     8     4     7     3     5       64
>Mark    9     7     9     4     8     7     3     0     5     4       59
>Q. How do I step through the fields of each record in a table???
>I want to create a program to step through each record in the table above
>and bracket off the four lowest numbers in each record.
>Below is the result I want to get.
>Name    1     2     3     4     5     6     7     8     9     10      Total
>Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
>Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47
>Can anyone help me out with this??? I'm Stuck!!

Your problem is due to the database structure.
You could try the following structure:
        NAME            F               COUNT
        Mark            1               9
        Mark            2               7 etc.
This way the solution is a piece of cake.

L.G. van de Vorst
Maarheeze, Holland



Fri, 28 Nov 1997 03:00:00 GMT  
 Stepping through Fields in a .DBF


: >If I have a table with the following data in 12 fields called: Name, F1,
: >F2, F3, F4 F5, F6 ,F7 ,F8, F9, F10 & Total.

: >Name    F1   F2    F3    F4    F5    F6    F7    F8    F9    F10      Total
: >Jim     10    5     7     9     6     8     4     7     3     5       64
: >Mark    9     7     9     4     8     7     3     0     5     4       59

: >Q. How do I step through the fields of each record in a table???

: >I want to create a program to step through each record in the table above
: >and bracket off the four lowest numbers in each record.

: >Below is the result I want to get.

: >Name    1     2     3     4     5     6     7     8     9     10      Total
: >Mark    9     7     9    (4)    8     7    (3)   (0)    5    (4)      48
: >Jim     10   (5)    7     9     6     8    (4)    7    (3)   (5)      47

: >Can anyone help me out with this??? I'm Stuck!!

: Your problem is due to the database structure.
: You could try the following structure:
:       NAME            F               COUNT
:       Mark            1               9
:       Mark            2               7 etc.
: This way the solution is a piece of cake.

True, but if you have your heart set on there original data structure,
you can use macro substitution:

select yourdb
for x = 1 to 10
   var = "F" + alltrim(str(x))
   ? &var
endfor

That should print out all of the numbered "F" fields in the current
record.

- Steve  



Fri, 28 Nov 1997 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. VFP3 for Windows Step by Step

2. Visual FoxPro 3 For Windows Step by Step

3. VFP50a - SET STEP ON / SET STEP OFF?

4. Any other step by step example for Web Connection

5. BOOK: Visual Foxpro 3 Step by Step

6. BOOK: Visual Foxpro 3 Step by Step

7. Step by step book for Macintosh

8. WTB: MS Visual Foxpro 3.0 Step-by-step

9. How : Multi-value Fields in DBF??

10. Indexing on a Field in a Different DBF

11. encrypting a field in a dbf file

12. exporting SQL 2000 data into FoxPro dbf containing memo field with DTS

 

 
Powered by phpBB® Forum Software