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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Links in Cells and String Registers Issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cdrozdowski111

USA
247 Posts

Posted - 02/11/2013 :  07:37:56 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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);

Penn

China
644 Posts

Posted - 02/17/2013 :  12:15:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 02/17/2013 :  09:01:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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);
Go to Top of Page

Penn

China
644 Posts

Posted - 02/17/2013 :  8:36:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

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

Penn
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000