Jump to content
Developer Wiki and Function Reference Links ×

check field name


michaelk

Recommended Posts

I'd like to look at a field name and see if just the first character = a specified character.

My best idea is this:

CurrentFieldName:= GetFldName(CurrentRecord,FieldIndex);

IF Pos('~',CurrentFieldName) <> 1 THEN

blahblahblah

I'm assuming it doesn't work because CurrentFieldName is a String and not a DYNARRAY OF CHAR

Is there a way to convert a string to an array? What does the variable declaration look like?

Is there a better way to do this?

Thanks!

mk

Link to comment

A string variable is defined as a character array of 255 maximum, so any where there is a Dynarray variable a string can be used.

This is the same case with integers & longint which can be interchangeable as long as the longint values is not greater than the integer maximum but an integer can always be used for a longint.

In the programming lingo, this is commonly called typecasting.

Link to comment

I've been doing a little experimenting. It turns out that IF Pos('~',CurrentFieldName) <> 1 THEN is working. (Or at least Pos('~','~fieldname') = 1)

Perhaps it's my scripting knowledge that isn't!

I'll attach the script. Can you see what I'm doing wrong?

Thanks

MK

Edited by michaelk
Link to comment

You could try use 'COPY' to get the first chr of the string.

Use AlrtDialog to help you see what the actual string is your getting

Then use your logic IF...

ie

TestString:=Copy(CurrentFieldName,1,1);

AlrtDialog(TestString);{This will alert you to what the actual value is for testing}

IF (TestString='~') THEN

Link to comment

Michael,

???Your loop counters are going from 1 to 0; i.e., not looping. The variables QtyRecordFormats and QtyFields are uninitialized, so they are 0 at the start of the loop.

Change QtyRecordFormats to NumRecords(OldSym)

and QtyFields to NumFields(CurrentRecord)

But I have a question about your record copying, aren't all the records being duplicated with hDuplicate()? And they stay intact after SetHDef(). What are you trying to copy that isn't already there?

Raymond

Link to comment

One more thing before I quit for the night, LObject points to the last object in the drawing, which is always on the topmost layer. LActLayer points to the last object on the active layer, which is what I'm guessing you want.

If you are working in a one layer drawing or you are on the top layer, they will be equivalent. But what are the odds that will work to your favor?

Raymond

Link to comment
Michael,

???Your loop counters are going from 1 to 0; i.e., not looping. The variables QtyRecordFormats and QtyFields are uninitialized, so they are 0 at the start of the loop.

Change QtyRecordFormats to NumRecords(OldSym)

and QtyFields to NumFields(CurrentRecord)

But I have a question about your record copying, aren't all the records being duplicated with hDuplicate()? And they stay intact after SetHDef(). What are you trying to copy that isn't already there?

Raymond

Actually, it works! I've tested with 2 record formats attached to symbols and every field in every record is transferred.

Duplicating the symbol does preserve the data.

But, SetHDef(), like Replace in the OIP, replaces the symbol but does not transfer the data - all the data reverts to the default values.

The reason for for duplicating and then replacing the duplicate is so I could have both the original and the new present at the same time. In my little brain it seemed easier to transfer the data one field at a time than capture all the data in every record, hold it while the replacement took place and then write all the data.

I'm hoping to create something like Replace with Active Instrument in Spotlight, but for any user created symbol w/ data.

The whole thing works -too well. I would like to have some fields that don't get transferred. My thinking was that I could use a ~ in the name of the field, test for that field, and skip those fields.

So Pos('~',CurrentFieldName) should be 1 when the field name is ~xxxxx.

But the script just happily goes along and replaces all the fields in all the records....

I'll have to clean up my test file and post it. That might make more sense....

stumped. And grateful.

mk

Edited by michaelk
Link to comment

Michael,

As Raymond said, you never set a value for QtyRecordFormats. I don't think your Pos call is the problem. Try using {$DEBUG} to step through your code and see what is going on.

I think SetHDef actually DOES preserve records, so basically your script is "working" because the records are already there. I think what you really want to do is step through the fields and set those starting with ~ to blank or the value from the symbol definition.

-Josh

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...