Jump to content

Problem with examining all the fields in a file


This topic is 7829 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I need to search through a rather lengthy record (200 fields) looking for a special embedded delimiter character (hex FD). I thought this would be a straightforward script where I would set a variable to the first field name, examine the data in that field for my special character with the PatternCount function, and then simply

Link to comment
Share on other sites

You really don't tell those of us who arent' xBase literate what the "macro substitution" function is. If all you want to do is set a global field (variable) to the value of a field, this can be done with the "Set Field" script step. You can also use the "Go to Field" script step to eliminate the need to depend upon the tab order and the "Go to Next Field" script step.

You can do this task a couple of other ways. One way is to create a calculation field that marks a record when the hex FD appears in any of the fields, i.e.

Mark (calculation, number) =

Pattern Count(field 1, HexFD) or

Pattern Count(field 2, HexFD) or

.

.

.

Pattern Count(field n, HexFD)

and then just find the marked records.

FM calculation and scripting are quite powerful. Unfortuantely knowledge of more traditional programming enviornments often leaves you looking in the wrong place for how to do things in FM. It's a little different paradigm.

-bd

Link to comment
Share on other sites

I apologize for perhaps not explaining my problem very well. Here's another shot at it:

Problem with examining all the fields in a record

I need to search through a rather lengthy record (200 fields) looking for a special embedded delimiter character (hex FD). When this special character is detected, I need to execute a few script steps to replace it with a paragraph mark (carriage return/line feed characters).

I thought this would be a straightforward script where I would set a variable to the first field name, examine the data in that field for my special character with the PatternCount function, and, if found, run my substitution routine. I (naively) assumed I could simply

Link to comment
Share on other sites

Man, I thought I had problems. I believe that if you use the "set field" command to store a value in your variable, instead of copy paste, your cursor will stay put. The only way to "go to field" is to specify the field, not use a field value, which is very frustrating.

I had to use the same workaround:

Store the (current field name), (current portal row) in global fields, perform the script (which required going to another database and pulled me out of the field I was in) then go back to the first field and "next field" until I was in the proper field as defined by my "current" variables.

A goofy workaround until Filemaker 6.

I think databasepros.com has something similar you can download.

Link to comment
Share on other sites

How about creating a Standard layout with all of the fields you need to test. Use the standard layout for the script. Freeze the window as a first step in your script (before going to the Standard layout), and a return to the previous layout at the end. Going to next field is straightforward as all fields are in the tab order. Use Set Field instead of copy and paste.

If this process needs to be done only once, to clean up data, I agree with Live Oak about exporting the data to a word processor and letting it do the work, then re-importing. No scripting required, it's fast, and you can get on to other stuff. Just make sure you have a backup, just in case.

Link to comment
Share on other sites

Thanks for the reply, but I still think I have a problem with getting to the actual data into each field to process it. The processing involves using the Middle function to find my special character (hex FD) and then replacing it with a special character string concatenated with the original data. If I setup the Middle function to operate on my variable named Current Field, this field has to contain the actual data from the various fields on my layout, not just the names of these fields. I can't seem to find a way to get the actual data in the Current Field variable so that I can operate on it with the Middle function. If you know of a way, I'd sure like to see it. Thanks.

Link to comment
Share on other sites

Here is a technique which may not be fast, but will be faster than doing it by hand.

First make some globals as working variables to do your text operations. You then create a script that sequentially copies the data from the next data field into the globals where it's processed and then back again. The trick of course is how to get back to the field you were in. Here's how:

code:


# MyFirstField is the name of the first field to be processed

go to field MyFirstField

set field FieldCount = 1

loop

Exit loop if FieldCount=FieldNumber

go to next field

set field FieldCount = FieldCount + 1

end loop

# You are now on the desired field.


Make the above into a subscript called GoToFieldByNumber

Now your main script will be something like this:

code:


go to field MyFirstField

set FieldNumber = 1

loop

Exit loop if FieldNumber > 200

# Just in case you need to know which field you are in:

Set Field CurFieldName Status(CurrentFieldName)

# now get the contents

copy [select]

paste [select, myWorkingGlobal]

# now do your text processing on the global field

.

.

.

# now copy the result

copy [select, myWorkingGlobal]

# go to the original field

Perform Script GoToFieldByNumber

# ok we are back, so paste the result

Paste [select]

# Now go to the next field and process it

Go to next field

Set Field FieldNumber = FieldNumber + 1

End loop

# All done


[This message has been edited by BobWeaver (edited March 01, 2001).]

Link to comment
Share on other sites

OK, Bob's got the right idea. Now to the details of your processing. I think the problem is trying to deal with the contents of a field all at once. You need to create a text processing procedure that doesn't care how many HexFD's are in the field. The way to do this is to use several global fields to process the text.

1) Copy (I'd use a SetField[]) the contents of a field to a global text field (gTemp1). Clear a second global text field (gTemp2).

2) Set gTemp2 to gTemp2 & the text up to the first HexFD (or end of field). A Set Field and a Case statement would work fine here.

3) Set gTemp2 to gTemp2 & "Your Sequence". increment your sequence.

4) Wipe out the first HexFD (use substitute) in gTemp1.

5) Exit if gTemp1 is empty

6) Loop back to 2)

By doing this, rather than trying to invent a single statement to deal with any number of HexFD's, you should be able to do what you wish. -bd

Link to comment
Share on other sites

In this case you have to use Copy rather than Set Field to get the field contents, because there's no way to tell the Set Field command what field you want to get. Of course once you have the data in the global field you can use Set Field all you want, in order to process the text. smile.gif

Link to comment
Share on other sites

As I tried to explain in my later postings, my actual requirement is not a simple substitution of a character when I detect the hex FD character. In actuality, what I must do is this: I must examine each of 200 fields in the record. As I examine each field, depending on the particular occurence (first, second, third, etc.) of the hex character in the field being examined, I must substitute a sequence number (1,2,3, etc.) for the hex character and then concatenate the remaining characters in that field until I detect the next hex character, or the end of the field, whichever comes first. I then move on to the next field until I've exhausted them.

If you think the Substitute function is the way to do this, I'm all for it and will pursue it further. Sorry about not fully explaining my requirement in the first posting. Any help would be greatly appreciated.

Link to comment
Share on other sites

This topic is 7829 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.