%ver 2.0
%decimale
srt=0;
miss=0;
srtvl=0;
ltperc=0;
if ncase
	h_1  = WndCreat ([], "Gentab", [NaN,NaN,320,434], 2);
	h_2  = CtrCreat (h_1, 110, [249,381,59,23], "Paste","paste");
	h_3  = CtrCreat (h_1, 110, [183,381,59,23], "Cancel","WndClose(h_1)");
	h_4  = CtrCreat (h_1, 110, [117,381,59,23], "OK","ok");
	
	CtrCreat (h_1, 510, [11,11,144,13], "All varaibles in file:");
	h_5  = CtrCreat (h_1, 320, [8,25,113,186], lcase(GetVarName(1:nvar)));
	CtrCreat (h_1, 510, [196,11,100,13], "Varaible(s):");
	h_6  = CtrCreat (h_1, 320, [193,25,113,82], "");
	CtrCreat (h_1, 510, [196,115,100,13], "Columns:");
	h_7  = CtrCreat (h_1, 320, [193,129,113,82], "");
	
	h_8 = CtrCreat (h_1, 150, [136,053,41,23], "","");
	h_9 = CtrCreat (h_1, 150, [136,153,41,23], "","");
	
	CtrConect(h_8,h_5,h_6);
	CtrConect(h_9,h_5,h_7);
	
	
	CtrCreat (h_1, 140, [187,221,121,69], "Number of decimals","");
	CtrCreat (h_1, 510, [195,240, 80,13], "First column:");
	h_19 = CtrCreat (h_1, 410, [275,237,21,19], "1");
	CtrCreat (h_1, 510, [195,264, 80,13], "Other columns:");
	h_20 = CtrCreat (h_1, 410, [275,261,21,19], "0");
	
	
	CtrCreat (h_1, 140, [9,221,169,69], "Sort","");
	h_11 = CtrCreat (h_1, 130, [21,241,109,13], "Sort descending","srt=~srt;");
	h_13 = CtrCreat (h_1, 130, [21,263,97,17], "Do not sort from","srtvl=~srtvl;if (srtvl);Enable(h_14);else;Disable(h_14);end");
	h_14 = CtrCreat (h_1, 410, [121,261,49,19], "9998");
		
	CtrCreat (h_1, 140, [9,292,300,85], "Parameters","");
	h_12 = CtrCreat (h_1, 130, [21,310,169,17], "Show missing values in output","miss=~miss;");
	h_16 = CtrCreat (h_1, 130, [21,332,149,13], "All percentages less then","ltperc=~ltperc;if (ltperc);Enable(h_17);Enable(h_18);else;Disable(h_17);Disable(h_18);end");
	h_17 = CtrCreat (h_1, 410, [165,328,21,19], "3");
	CtrCreat (h_1, 510, [195,332,100,13], "recode into");
	h_18 = CtrCreat (h_1, 410, [262,328,40,19], "9995");
	CtrCreat (h_1, 510, [ 21,354,240,13], "Number of significant levels for coloring (1, 2 or 3):");
	h_15 = CtrCreat (h_1, 410, [262,352,40,19], "2");
	Disable(h_14)
	Disable(h_17)
	Disable(h_18)
else
	MsgBox([],"Morate prvo ucitati SPSS podatke");
end

macro paste
	vars=CtrGet(h_6);
	if size(vars,1)==0
		MsgBox(h_1,"Fale varijable za obradu!",1);
		return;
	end
	kol1=CtrGet(h_7);
	str = "\n\n!gentab vars=";
	for i=1:max(size(vars))
		str = str+" "+vars(i);
	end
	if size(kol1,1)
		str = str+"/\n        kol1=";
		for i=1:max(size(kol1))
			str = str+" "+kol1(i);
		end
	end
	if srt
		str = str+"/\n        sort= yes";
	end
	if miss
		str = str+"/\n        miss= yes";
	end
	if srtvl
		srtvl = CtrGet(h_14);
		str = str+"/\n        srtvl= "+srtvl;
	end
	color = CtrGet(h_15);
	if size(color,1)
		if strcmp("3",color)
			str = str+"/\n        color= "+color;
		end
	else
		str = str+"/\n        color= 3";
	end
	if ltperc
		ltperc = [CtrGet(h_17), CtrGet(h_18)];
		str = str+"/\n        ltperc= "+ltperc(1)+" "+ltperc(2);
	end
	str = str + "/\n        decimal= " + CtrGet(h_19) + " " + CtrGet(h_20);
	str = str+" .";
	syntax(str);
	WndClose(h_1);
end

macro ok
	vars=CtrGet(h_6);
	if size(vars,1)==0
		MsgBox(h_1,"Fale varijable za obradu!",1);
		return;
	end
	kol1=CtrGet(h_7);
	if srt
		srt = "YES";
	else
		srt="NO";
	end
	if miss
		miss = "YES";
	else
		miss = "NO";
	end
	if srtvl
		srtval = CtrGet(h_14);
	end
	color = CtrGet(h_15);
	decimal= [CtrGet(h_19),CtrGet(h_20)];
	if ltperc
		ltperc = [CtrGet(h_17), CtrGet(h_18)];
	else
		ltperc = [];
	end
	WndClose(h_1);
	if srtvl
		gentab(vars,kol1,[],[],srt,miss,color,decimal,ltperc,srtval);
	else
		gentab(vars,kol1,[],[],srt,miss,color,decimal,ltperc);
	end
end