The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Links in Cells and String Registers Issue

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
cdrozdowski111 Posted - 02/11/2013 : 07:37:56 AM
OriginPro 9.0.0 SR1, Win7 64-bit, running in VMware Fusion 5.0.2

Is there any way to prevent the expansion of string registers when a link is added to a cell? If you run the code below, you should see what I mean.

(Test project has three simple workbooks whose long names are "Book1", "Book2 %H Test" and "Book3")



// Code

StringArray saTest;

// Loop over every workbook in project
doc -e W {

// Create string as link whose display is current page.longname$
string strLink$ = "range://[%(page.name$)] %(page.longname$)";

// Add to string array
saTest.Add(strLink$);
}

// Create a basic workbook
newbook;

// Assign string array to column 1
range rngCol1 = col(1);
saTest.CopyTo(rngCol1);
3   L A T E S T    R E P L I E S    (Newest First)
Penn Posted - 02/17/2013 : 8:36:14 PM
Hi,

Yes, you can write the find/insert code in Origin C, please refer to string class in Origin C.

Penn
cdrozdowski111 Posted - 02/17/2013 : 09:01:31 AM
Thanks Penn,

I was able to come up with an (albeit slow and convoluted yet more thorough) solution. I bet the char finding/inserting could be written in Origin C and run faster and have cleaner LT code.

----------------


StringArray saTest;

// Loop over every workbook in project
doc -e W {


	// Put page.longname$ into a string
	string strPLN$ = page.longname$;

	// Is there a % char in string?
	if (strPLN.Find("%"))
	{

		// Loop through string from end to beginning looking for % characters. We can ignore last char.
		int nLen = strPLN.GetLength();
		for (int ii = nLen - 1; ii > 0; ii--)
		{
			// Get current char as ASCII
			int nCurrChar = strPLN.GetAt(ii);

			// ASCII codes for relevant chars- % = 37, A-Z = 65-90, a-z = 97-122

			// Is current = %?
			if (nCurrChar == 37)
			{
				// Get next char as ASCII
				int nNextChar = strPLN.GetAt(ii + 1);
			
				// Is next char in A-Z or a-z?
				if (
						( (nNextChar >= 65) && (nNextChar <= 90) )
						||
						( (nNextChar >= 97) && (nNextChar <= 122) )
					)
				{
					// Insert another % char after found % char
					strPLN.Insert(ii + 1, "%");
				}
			}
		}
	
	}


	// Create string as link whose display is strPLN$
	string strLink$ = "range://[%(page.name$)] %(strPLN$)";

	// Add to string array
	saTest.Add(strLink$);
}

// Create a basic workbook
newbook;

// Assign string array to column 1
range rngCol1 = col(1);
saTest.CopyTo(rngCol1);
Penn Posted - 02/17/2013 : 12:15:12 AM
Hi,

Add one more %, that will prevent the expansion of string register, such as %%H. For the simple testing case, you can try the following script. Note, this simple script cannot handle the case in which there are more than one % in the string.

StringArray saTest;
// Loop over every workbook in project
doc -e W {
	// Create string as link whose display is current page.longname$
	string strLink$ = "range://[%(page.name$)] %(page.longname$)";
	// if there is %, note that the long name may be much more
	// complicated, and need much more codes to handle
	int ii = strLink.Find('%');
	if(ii != 0)
		strLink.Insert(ii, "%");  // insert one more %
	// Add to string array
	saTest.Add(strLink$);
}
// Create a basic workbook
newbook;
// Assign string array to column 1
range rngCol1 = col(1);
saTest.CopyTo(rngCol1);


Penn

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000