need help for translating xTalk-like script (from LiveCode into AS)

Hi,

I scripted a short (25 lines) script that reads the clipboard with table data from Excel and puts it into a variable. It then replaces some tabs, commas, strings and stuff and finally copies the var back into the clipboard.

Can anybody help me translating the following almost HyperTalk-like code into AS syntax?

on startup
put the clipboardData into vD
put “” into ArrayName
ask “Array Name”
put it into ArrayName

put “” into p1
put ArrayName & " = new Array();" into p2
put " [" into p3
put “] = [” into p4
put “];” into p5

replace “.” with “” in vD – entferne Punkt
replace “,” with “.” in vD – tausche Komma gegen Punkt
replace tab with “,” in vD – tausche Tab gegen Komma

repeat with i = 1 to the number of lines in vD
if char 1 of line i of vD is comma then put 0 before line i of vD
end repeat

repeat with i = 1 to the number of lines in vD
put ArrayName & p3 & i-1 & p4 before line i of vD
put p5 after line i of vD
end repeat

replace " - € " with 0 in vD
put p1 & p2 & cr before line 1 of vD

set the clipboardData to vD
end startup

Thanx a million,
Ralf

Something like this.

NOTE: maybe, you need instead of linefeed some other character from the following set: {return & linefeed, return, character id 8233, character id 8232}. Find correct character yourself.


-- on startup
on run
	-- put the clipboardData into vD
	set vD to the clipboard as text
	-- put "" into ArrayName
	set ArrayName to ""
	-- ask "Array Name"
	display dialog "Please, indicate the Array Name" default answer ""
	-- put it into ArrayName
	set ArrayName to text returned of result
	-- put "" into p1
	set p1 to ""
	-- put ArrayName & " = new Array();" into p2
	set p2 to ArrayName & " = new Array();"
	-- put " [" into p3
	set p3 to " ["
	-- put "] = [" into p4
	set p4 to "] = ["
	-- put "];" into p5
	set p5 to "];"
	
	-- replace "." with "" in vD  -- entferne Punkt
	set vD to my replace(".", "", vD)
	-- replace "," with "." in vD -- tausche Komma gegen Punkt
	set vD to my replace(",", ".", vD)
	-- replace tab with "," in vD -- tausche Tab gegen Komma
	set vD to my replace(tab, ",", vD)
	
	-- repeat with i = 1 to the number of lines in vD
	repeat with i from 1 to count of (paragraphs of vD)
		-- if char 1 of line i of vD is comma then put 0 before line i of vD
		if character 1 of paragraph i of vD is "," then set paragraph i of vD to "0" & paragraph i of vD
		-- end repeat
	end repeat
	
	-- repeat with i = 1 to the number of lines in vD
	repeat with i from 1 to count of (paragraphs of vD)
		-- put ArrayName & p3 & i-1 & p4 before line i of vD
		set paragraph i of vD to ArrayName & p3 & i - 1 & p4 & paragraph i of vD
		-- put p5 after line i of vD
		set paragraph i of vD to paragraph i of vD & p5
		-- end repeat
	end repeat
	
	-- replace " -   € " with 0 in vD
	set vD to my replace(" -   € ", "0", vD)
	-- put p1 & p2 & cr before line 1 of vD
	set paragraph i of vD to p1 & p2 & linefeed & paragraph i of vD
	-- set the clipboardData to vD
	set the clipboard to vD
	
	-- end startup
end run

on replace(inChar, outChar, theText)
	set ATID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to inChar
	set temp to text items of theText
	set AppleScript's text item delimiters to outChar
	set theText to temp as text
	set AppleScript's text item delimiters to ATID
	return theText
end replace

Efcharisto poli KniazidisR,

looks really good. Thank you so much
I’ll give that closer look tonight.

Regards,
Ralf