Home AMX User Forum NetLinx Studio

Better Way to Write this

Define_Function Update_Panel(Integer Index)
{
    Stack_Var Integer x
    
    If(Debug_State)
	debug("'Line # ',Itoa(__Line__),' Updating Touch Panel With Info Parsed Info!!!'")
    
    If(nIndex = 1)
    {
	For(x=1;x<7;x++)
	{
	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[x].Article_Title,40))"
	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[x].Article_Title,41,40))"
	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[x].Article_Description,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,101,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,201,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,301,100))"
	    Send_Command dvPanel,"'!T',12+x,sNews[x].Article_Author"
	    Send_Command dvPanel,"'!T',18+x,sNews[x].Article_PubDate"
	}
    }
    If(nIndex = 2)
    {
	For(x=1;x<7;x++)
	{
	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[x+6].Article_Title,40))"
	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[x+6].Article_Title,41,40))"
	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[x+6].Article_Description,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+6].Article_Description,101,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+6].Article_Description,201,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+6].Article_Description,301,100))"
	    Send_Command dvPanel,"'!T',12+x,sNews[x+6].Article_Author"
	    Send_Command dvPanel,"'!T',18+x,sNews[x+6].Article_PubDate"
	}
    }
    If(nIndex = 3)
    {
	For(x=1;x<7;x++)
	{
	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[x+12].Article_Title,40))"
	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[x+12].Article_Title,41,40))"
	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[x+12].Article_Description,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+12].Article_Description,101,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+12].Article_Description,201,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+12].Article_Description,301,100))"
	    Send_Command dvPanel,"'!T',12+x,sNews[x+12].Article_Author"
	    Send_Command dvPanel,"'!T',18+x,sNews[x+12].Article_PubDate"
	}
    }
    If(nIndex = 4)
    {
	For(x=1;x<7;x++)
	{
	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[x+18].Article_Title,40))"
	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[x+18].Article_Title,41,40))"
	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[x+18].Article_Description,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+18].Article_Description,101,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+18].Article_Description,201,100))"
	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x+18].Article_Description,301,100))"
	    Send_Command dvPanel,"'!T',12+x,sNews[x+18].Article_Author"
	    Send_Command dvPanel,"'!T',18+x,sNews[x+18].Article_PubDate"
	}
    }
}

Was wondering if someone could make some suggestions to make this more efficient

Thanks

Comments

  • Like this:
    For(x=1;x<7;x++)
    	{
    	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[x].Article_Title,40))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[x].Article_Title,41,40))"
    	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[x].Article_Description,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,101,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,201,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[x].Article_Description,301,100))"
    	    Send_Command dvPanel,"'!T',12+x,sNews[((index-1)*6)+x].Article_Author"
    	    Send_Command dvPanel,"'!T',18+x,sNews[((index-1)*6)+x].Article_PubDate"
    	}
    
    
  • Thanks for this
  • Almost... it would actually be (borrowing Tony's code)
    For(x=1;x<7;x++)
    	{
    	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(sNews[((index-1)*6)+x].Article_Title,40))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(0+x),',0,',(Mid_String(sNews[((index-1)*6)+x].Article_Title,41,40))"
    	    Send_Command dvPanel,"'^TXT-',Itoa(6+x),',0,',(Left_String(sNews[((index-1)*6)+x].Article_Description,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[((index-1)*6)+x].Article_Description,101,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[((index-1)*6)+x].Article_Description,201,100))"
    	    Send_Command dvPanel,"'^BAT-',Itoa(6+x),',0,',(Mid_String(sNews[((index-1)*6)+x].Article_Description,301,100))"
    	    Send_Command dvPanel,"'!T',12+x,sNews[((index-1)*6)+x].Article_Author"
    	    Send_Command dvPanel,"'!T',18+x,sNews[((index-1)*6)+x].Article_PubDate"
    	}
    

    Alternately, define a STACK_VAR with your structure type and assign it before the loop:
    article = sNews[((index-1)*6)+x]
    For(x=1;x<7;x++)
    	{
    	    Send_Command dvPanel,"'^TXT-',Itoa(0+x),',0,',(Left_String(article.Article_Title,40))"
    etc...
    
Sign In or Register to comment.