michaelk Posted August 19, 2012 Share Posted August 19, 2012 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 Quote Link to comment
MullinRJ Posted August 19, 2012 Share Posted August 19, 2012 Michael, ???Have you tried using STRING data? It very well could work. I often use Strings and Dynarray of Chars interchangeably. Raymond Quote Link to comment
michaelk Posted August 19, 2012 Author Share Posted August 19, 2012 Yes, I've tried using STRING. No luck. MK Quote Link to comment
Miguel Barrera Posted August 19, 2012 Share Posted August 19, 2012 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. Quote Link to comment
michaelk Posted August 19, 2012 Author Share Posted August 19, 2012 (edited) 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 August 19, 2012 by michaelk Quote Link to comment
Assembly Posted August 20, 2012 Share Posted August 20, 2012 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 Quote Link to comment
Miguel Barrera Posted August 20, 2012 Share Posted August 20, 2012 You are missing the HANDLE type in the VAR declarations Quote Link to comment
MullinRJ Posted August 20, 2012 Share Posted August 20, 2012 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 Quote Link to comment
MullinRJ Posted August 20, 2012 Share Posted August 20, 2012 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 Quote Link to comment
michaelk Posted August 20, 2012 Author Share Posted August 20, 2012 (edited) 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 August 20, 2012 by michaelk Quote Link to comment
JBenghiat Posted August 20, 2012 Share Posted August 20, 2012 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 Quote Link to comment
michaelk Posted August 20, 2012 Author Share Posted August 20, 2012 Thanks for all your help, guys. I'll go back to the drawing board! mk Quote Link to comment
michaelk Posted August 21, 2012 Author Share Posted August 21, 2012 You guys were right. Thanks again. Script is working! mk Quote Link to comment
Recommended Posts
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.