GUI textbox's accepting array number and string

i am try to let textbox in gui to accept array number and string
it acepting Number only
i add (GuiSetText ) but not working

for array i do not know

i have the error here

function SetNumber(idEdit, Value, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    GuiSetValue(idEdit, Value ); 
    GuiSetText(idEdit, Value ); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
   
    return Value;
}

this is full code



procedure SetOrigin(x0, y0) {
	global _x0, _y0;
	_x0 = x0; _y0 = y0;
}


_cursorMouseButtons = GetCursorMouseButtons();
DT_CENTER = 1; DT_VCENTER = 4 | 32; 

procedure GfxSetColors(fgColor, bgColor) {
	GfxSetTextColor(fgColor); GfxSetBkColor(bgColor); 
	GfxSelectPen(fgColor); GfxSelectSolidBrush(bgColor);
}



// format: 0 left, 1 center, 2 right
procedure GfxLabel(text, x, y, width, height, format) {
	global _x0, _y0;
	x = x+_x0; y = y+_y0;
	GfxDrawText( text, x, y, x+width, y+height, format | DT_VCENTER ); 
}


function GfxGetState(id) {
	return Nz(StaticVarGet("GfxState"+id+GetChartID()), 0);
}
function PointInside(x0, y0, x, y, width, height) {
    global _x0, _y0;
	x = x+_x0; y = y+_y0;
    x0 = x0+_x0; y0 = y0+_y0;
	return ((x0 >= x) && (y0 >= y) && (x0 <= (x+width)) && (y0 <= (y+height)));
}

function LeftClickInside(x, y, width, height) {
	global _cursorMouseButtons, _x0, _y0;
	local px, py, res;
	
	// x = x+_x0; y = y+_y0;
	res = False;
	if (_cursorMouseButtons & 8) { // click
		px = GetCursorXPosition(1); 
		py = GetCursorYPosition(1); 
		res = PointInside(px, py, x, y, width, height);
	}
	return res;
}

procedure GfxSetState(id, val) {
	StaticVarSet("GfxState"+id+GetChartID(), val);
}
function SetNumber(idEdit, Value, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    GuiSetValue(idEdit, Value ); 
    GuiSetText(idEdit, Value ); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
   
    return Value;
}

function EditNumber( idEdit, initialValue, x, y, width, height, textColor, bgColor )
{  // this function hold the text for the next restart of Amibroker
    global _x0, _y0;
    local rc ;

    x = x + _x0;     y = y + _y0;
    rc = GuiEdit( idEdit, x, y, width, height, notifyHitReturn ); //

    ID = GuiGetEvent( 0, 0 );     event = GuiGetEvent( 0, 1 );
    if( ID == idEdit ) StaticVarSetText( "sV" + idEdit,  GuiGetText( idEdit ), 1 );

    if( rc == guiNew )
    {  // after restart Amibroker read FIRST these Static Line
        txt = StaticVarGettext( "sV" + idEdit );
        GuiSetText( txt, idEdit );
    }

    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor );

    return GuiGetValue( idEdit );
}
function GfxHTabs(id, headers, headheight, x, y, width, height, colorfg, colorbg) {
	global _x0, _y0;
	local px,choice,na,i,G,header,w, wi, prevwi;
	
	x = x+_x0; y = y+_y0; choice = GfxGetState(id);
	GfxSetColors(colorfg, colorbg);
	
	for(G = 0; (header = StrExtract(headers,G)) != ""; ++G) {};
	w = width/G; wi = x; prevwi = x;
	if (LeftClickInside(x,y,width,headheight)) {
		px = GetCursorXPosition( 1 );
		// choice = floor((px - x)/w);
		// wi = x; prevwi = x;
		for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
			wi = wi + 1.32*GfxGetTextWidth(header);
			if ((px > prevwi) && (px < wi))  { choice = i; break; }
		}
		GfxSetState(id, choice); // StaticVarSet(na, choice);
	}

	GfxSetBkMode(1);
	// Draw Zone & Tabs
	wi = x; prevwi = x;
	for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
		wi = wi + 1.32*GfxGetTextWidth(header);

		// GfxSelectSolidBrush(colorbg); 
		GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5); 
		if (i != choice) {
			GfxSelectHatchBrush(colorfg,3); 
			GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5); 
			GfxSelectSolidBrush( colorbg );
		} else {
			wic = wi; prevwic = prevwi;
		}
		GfxDrawText(header, prevwi, y, wi, y+headheight+5, 1|4|32);
		prevwi = wi;
	}
	GfxRectangle(x,y+headheight,x+width,y+height);
	GfxSelectPen(colorbg,1); GfxMoveTo(prevwic, y+headheight); GfxLineTo(wic, y+headheight); 
	
	return choice;
}
procedure GfxDemos(x,y) {

local  n,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,
	      n12,n13,n14,n15,n16,n17,n18,n19,n20
	      ,n21,n22,txt,Prefix,Xpx,Flags;

	SetOrigin(x,y);
	
	dd=IIf(MACD(12,26)>0,1,0);
	
	G = GfxHTabs("HTab1", "Stocks,Currencies,Bonds,News", 30, 100, 100, 400, 200, colorBlue, colorLavender); 
	
	switch(G) {
		case 0: 
		n3 = SetNumber(3,dd, 180, 150, 80, 25, colorBlue, colorYellow); 
		n4 = SetNumber(4, (10)/2, 280, 150, 80, 25, colorBlue, colorYellow);
		n5 = SetNumber(5, (10)/2, 380, 150, 80, 25, colorBlue, colorYellow); break;
		
		case 1:  
		 break;
		
		case 2:  
		n7 = SetNumber(7,(100)/2 , 180, 240, 80, 25, colorBlue, colorYellow); 
	    n8 = SetNumber(8, (10)/3, 280, 240, 80, 25, colorBlue, colorYellow);
	     n9 = SetNumber(9, (10)/3, 380, 240, 80, 25, colorBlue, colorYellow);break;
		case 3:  break;
	}
	

			
	
		
	
	

   
}


x = Param("x_origin", 20, 0, 1980, 20);
y = Param("y_origin", 20, 0, 1024, 20);
demo = ParamToggle("Show Demo", "No|Yes", 1);

if (demo) {
	
	 GfxDemos(x,y);
	
}

procedure SetOrigin(x0, y0) {
	global _x0, _y0;
	_x0 = x0; _y0 = y0;
}


_cursorMouseButtons = GetCursorMouseButtons();
DT_CENTER = 1; DT_VCENTER = 4 | 32; 

procedure GfxSetColors(fgColor, bgColor) {
	GfxSetTextColor(fgColor); GfxSetBkColor(bgColor); 
	GfxSelectPen(fgColor); GfxSelectSolidBrush(bgColor);
}



// format: 0 left, 1 center, 2 right
procedure GfxLabel(text, x, y, width, height, format) {
	global _x0, _y0;
	x = x+_x0; y = y+_y0;
	GfxDrawText( text, x, y, x+width, y+height, format | DT_VCENTER ); 
}


function GfxGetState(id) {
	return Nz(StaticVarGet("GfxState"+id+GetChartID()), 0);
}
function PointInside(x0, y0, x, y, width, height) {
    global _x0, _y0;
	x = x+_x0; y = y+_y0;
    x0 = x0+_x0; y0 = y0+_y0;
	return ((x0 >= x) && (y0 >= y) && (x0 <= (x+width)) && (y0 <= (y+height)));
}

function LeftClickInside(x, y, width, height) {
	global _cursorMouseButtons, _x0, _y0;
	local px, py, res;
	
	// x = x+_x0; y = y+_y0;
	res = False;
	if (_cursorMouseButtons & 8) { // click
		px = GetCursorXPosition(1); 
		py = GetCursorYPosition(1); 
		res = PointInside(px, py, x, y, width, height);
	}
	return res;
}

procedure GfxSetState(id, val) {
	StaticVarSet("GfxState"+id+GetChartID(), val);
}
function SetNumber(idEdit, Value, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    GuiSetValue(idEdit, Value ); 
    GuiSetText(idEdit, Value ); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
   
    return Value;
}

function EditNumber( idEdit, initialValue, x, y, width, height, textColor, bgColor )
{  // this function hold the text for the next restart of Amibroker
    global _x0, _y0;
    local rc ;

    x = x + _x0;     y = y + _y0;
    rc = GuiEdit( idEdit, x, y, width, height, notifyHitReturn ); //

    ID = GuiGetEvent( 0, 0 );     event = GuiGetEvent( 0, 1 );
    if( ID == idEdit ) StaticVarSetText( "sV" + idEdit,  GuiGetText( idEdit ), 1 );

    if( rc == guiNew )
    {  // after restart Amibroker read FIRST these Static Line
        txt = StaticVarGettext( "sV" + idEdit );
        GuiSetText( txt, idEdit );
    }

    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor );

    return GuiGetValue( idEdit );
}
function GfxHTabs(id, headers, headheight, x, y, width, height, colorfg, colorbg) {
	global _x0, _y0;
	local px,choice,na,i,G,header,w, wi, prevwi;
	
	x = x+_x0; y = y+_y0; choice = GfxGetState(id);
	GfxSetColors(colorfg, colorbg);
	
	for(G = 0; (header = StrExtract(headers,G)) != ""; ++G) {};
	w = width/G; wi = x; prevwi = x;
	if (LeftClickInside(x,y,width,headheight)) {
		px = GetCursorXPosition( 1 );
		// choice = floor((px - x)/w);
		// wi = x; prevwi = x;
		for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
			wi = wi + 1.32*GfxGetTextWidth(header);
			if ((px > prevwi) && (px < wi))  { choice = i; break; }
		}
		GfxSetState(id, choice); // StaticVarSet(na, choice);
	}

	GfxSetBkMode(1);
	// Draw Zone & Tabs
	wi = x; prevwi = x;
	for(i = 0; (header = StrExtract(headers,i)) != ""; ++i) {
		wi = wi + 1.32*GfxGetTextWidth(header);

		// GfxSelectSolidBrush(colorbg); 
		GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5); 
		if (i != choice) {
			GfxSelectHatchBrush(colorfg,3); 
			GfxRoundRect(prevwi,y,wi,y+headheight+5,5,5); 
			GfxSelectSolidBrush( colorbg );
		} else {
			wic = wi; prevwic = prevwi;
		}
		GfxDrawText(header, prevwi, y, wi, y+headheight+5, 1|4|32);
		prevwi = wi;
	}
	GfxRectangle(x,y+headheight,x+width,y+height);
	GfxSelectPen(colorbg,1); GfxMoveTo(prevwic, y+headheight); GfxLineTo(wic, y+headheight); 
	
	return choice;
}
procedure GfxDemos(x,y) {

local  n,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,
	      n12,n13,n14,n15,n16,n17,n18,n19,n20
	      ,n21,n22,txt,Prefix,Xpx,Flags;

	SetOrigin(x,y);
	
	dd=IIf(MACD(12,26)>0,1,0);
	
	G = GfxHTabs("HTab1", "Stocks,Currencies,Bonds,News", 30, 100, 100, 400, 200, colorBlue, colorLavender); 
	
	switch(G) {
		case 0: 
		n3 = SetNumber(3,dd, 180, 150, 80, 25, colorBlue, colorYellow); 
		n4 = SetNumber(4, (10)/2, 280, 150, 80, 25, colorBlue, colorYellow);
		n5 = SetNumber(5, (10)/2, 380, 150, 80, 25, colorBlue, colorYellow); break;
		
		case 1:  
		 break;
		
		case 2:  
		n7 = SetNumber(7,(100)/2 , 180, 240, 80, 25, colorBlue, colorYellow); 
	    n8 = SetNumber(8, (10)/3, 280, 240, 80, 25, colorBlue, colorYellow);
	     n9 = SetNumber(9, (10)/3, 380, 240, 80, 25, colorBlue, colorYellow);break;
		case 3:  break;
	}
	

			
	
		
	
	

   
}


x = Param("x_origin", 20, 0, 1980, 20);
y = Param("y_origin", 20, 0, 1024, 20);
demo = ParamToggle("Show Demo", "No|Yes", 1);

if (demo) {
	
	 GfxDemos(x,y);
	
}

thank you

for string i find it

function EditText(idEdit, defaultText, x, y, width, height, textColor, bgColor) {
    global _x0, _y0;
	local rc;
	
    x = x+_x0; y = y+_y0;
    rc = GuiEdit( idEdit, x, y, width, height, 0); 
    if( rc == guiNew ) GuiSetText(defaultText, idEdit); 
    GuiSetColors( idEdit, idEdit, 1, textColor, bgColor, textColor);
    
    return GuiGetText(idEdit);
}

and i change the target to
ff=WriteIf(RSI(14)>0,"Buy","Sell");
n3 = EditText(3,ff, 180, 150, 80, 25, colorBlue, colorYellow);

i need the array

for array

gg=MACD(12.26);
SetNumber(4, SelectedValue(Prec(gg, 2 )), 280, 150, 80, 25, colorBlue, colorYellow);

if there is better code

now how to control the color for the text box

thank you

now how to control the color for the text box

to gui

like buy text box become green
and MACD below 0 become red (-19.6)
thank you

For text boxes, you receive a STRING (always), not number.
To convert string to number use StrToNum() function.

Number (scalar) can be used anywhere where you need a scalar OR array.

For more information:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.