5 Replies Latest reply on Mar 17, 2015 10:50 AM by Zantcor

    Statis text not updating

    Zantcor Level 1

      I've been looking through the forusm for a while and I can't find my answer.  User inputs text in text box, his the "Check Item" button then if its found the 'statictext' should update as its text is var veritemnum but I can't get it to update.

       

      //Created by  Daryl R. Smith
      //Simply takes the artwork and places it on the three up template, then saves the file with the option to resize
      
      #target illustrator;
      
      var veritemnum = "Item Not Found"
      
         //size one hats are 4.5"w x 2"h
         var size1 = [7752, 8645, 7550, 7310, 7365, 7362, 7360, 7317, 7315,8630,7370,7320,7340,7220,7221,8329,8326,8331,8303,8309,8305,8300,8333,8332,
         8352,];
         
         //size 4 hats are 4"w x2.5"H
         var size4 = [8311,];
         
         //size 2 hats are 4"W x 2"h
         var size2 = [7313, 8266, 8635, 8615, ];
            
         //size 8 hats are 3.5"w x 2.5"h
         var size8 = [7366,];
         
         //size 3 hats are 3.5"W x 2"h
         var size3 = [7700, 8330, ];
         
         //size 5 visors are 3"w x 1.25"h
         var size5 = [7375,];
         
         //size 6 visors are 3.5"w x 1.25"h
         var size6 = [8307,];
         
         //size 7 visors are 4"w x 1.25"h
         var size7 = [7754, 7754,7460,];
      
      var w = new Window ('dialog', "Imprint Size Search");
          w.orientation = "row";
          w.size = [300,150];
          
          var rsizegroup = w.add ('group', undefined, undefined);
          rsizegroup.orientation = "column";
          rsizegroup.alignChildren = "left";
          
         
          var textgroup = w.add ("group", undefined, "");
          textgroup.orientation = "column";
          
          rsizegroup.add ("statictext", undefined, "Item Number:");
          
          var itmgrp = rsizegroup.add ('group',undefined, "");
          itmgrp.orientation = "row";
          
          var itemNum = itmgrp.add ("edittext", undefined, "");
          itemNum.size = [40,20];
          itemNum.active = true;
          
          itemNum.onChange = function() 
          {  itemNum = this.text 
          itemNum.characters = 7;
          itemNum.active = true;
          }
      
      
          var checkitem = itmgrp.add ('button', undefined, "Check item");
          checkitem.onClick = function (veritemnum)
          {  
              //size one hats are 4.5"w x 2"h
                  for (i=0;i<size1.length;i++)
                  {
                      if (itemNum == size1[i])
                        {
                         
      alert ("size 1 made it");      
      
                         return "Item Found s1";
                         
                        }//end if size 1
                 }//end for size 1   
             
                  //size 2 hats are 4"W x 2"h
                  for (j=0;j<size2.length;j++)
                  {
                      if (itemNum == size2[j])
                        {
                        
      alert ("size 2 made it");     
      
                        return "Item Found s2";
                        
                        }//end size 2
                  }//end for size 2
              
                   //size 3 hats are 3.5"W x 2"h      
                   for (k=0;k<size3.length;k++)
                   {
                      if (itemNum == size3[k])
                        {
                        
      alert ("size 3 made it");    
      
                        return "Item Found s3";
                        
                        }//end size 3
                }//end for size 3
            
                    //size 4 hats are 4"w x2.5"H
                    for (h=0;h<size4.length;h++)
                    {
                      if (itemNum == size4[h])
                         {
                        
      alert ("size 4 made it");      
      
                      return "Item Found s4";
                        
                        }//end if size 4
                    }//end for size 4
                    
                     //size 5 visors are 3"w x 1.25"h   
                      for (j=0;j<size5.length;j++)
                      {
                      if (itemNum == size5[j]) 
                        {
                     var  veritemnum = "Item Found s5";
                       
                        
      alert ("size 5 made it");
      
                        return ("Item Found s5");
                        
                        }//end if size 5
                    }//end for size 5
                
                    //size 6 visors are 3.5"w x 1.25"h     
                    for (j=0;j<size6.length;j++)
                    {
                      if (itemNum == size6[j])
                      {
                    
      alert ("size 6 made it");      
      
                   return "Item Found s6";
                    
                    }//end if size 6
                }//end for size 6
                
                    //size 7 visors are 4"w x 1.25"h    
                    for (j=0;j<size7.length;j++)
                    {
                      if (itemNum == size7[j])
                        {                  
                                        
      alert ("size 7 made it");      
                   
                   return "Item Found s7";
                       
                         }//end if size 7
                    }// end for size 7
                
                    //size 8 hats are 3.5"w x 2.5"h
                    for (j=0;j<size8.length;j++)
                    {
                      if (itemNum == size8[j])
                         {                 
                        
      alert ("size 8 made it");                
      
                        return ("Item Found s8");
                        
                          }//end if size 8
                      }//end for size 8
              
              }//end on check item click  
          
        var selecteditem = rsizegroup.add('statictext', undefined, veritemnum);
          
          var rsizequestion = rsizegroup.add('button', undefined, "Resize Artwork");
         
         
      rsizequestion.onClick = function()  
      {  
          
           findImprintSize();
           resizeart()
      };
              
         var breakPanel2 = w.add ("panel", [0,0,2,64]);////////////////////////// Break Panel
         
         bttngrp = w.add ('group',undefined,undefined);
         bttngrp.orientation = "column";
         
              
          bttngrp.add ("button", undefined, "OK");
          bttngrp.add ("button", undefined, "Cancel");
          //itemNum = itemNum.text;
          
          if (w.show () == 1)
          {
              allstuff ()
          
           }/*end if ok button*/ else
       {
           
           }
      

       

      If you put in 7375 an alert will pop up letting you know it made it through size 5 which is correct but the static text never changes.  What am I missing?

        • 1. Re: Statis text not updating
          W_J_T Level 4

          Zantcor wrote:

           

          If you put in 7375 an alert will pop up letting you know it made it through size 5 which is correct but the static text never changes.  What am I missing?

           

          You need to target the static text like this using the ".text" property of that instance:

           

          // either like this
          selecteditem.text = "Item Found s5";
          // or like this
          veritemnum = "Item Found s5";
          selecteditem.text = veritemnum;
          // and the same for all the other instances s1, s2, s3, ..., s8 etc...
          
          

           

          Hope it helps your efforts.

          • 2. Re: Statis text not updating
            Zantcor Level 1

            That is what it was, I was targeting the variable without ever targeting the object.

             

            Thanks W_J_T, Digital High Five!

            • 3. Re: Statis text not updating
              Zantcor Level 1

              I changed the section that checks to make sure that the text is a match to the below;

               

              var checkitem = itmgrp.add ('button', undefined, "Check item");
                  checkitem.onClick = function ()
                  { 
                      //size one hats are 4.5"w x 2"h
                          for (i=0;i<size1.length;i++)
                          {
                              if (itemNum == size1[i])
                                {
                                   
                                    selecteditem.text = "Item Found s1";
                                   
                                
              //alert ("size 1 made it");     
                              
                                }//end if size 1
                         }//end for size 1  
                    
                          //size 2 hats are 4"W x 2"h
                          for (j=0;j<size2.length;j++)
                          {
                              if (itemNum == size2[j])
                                {
                                   
                                    selecteditem.text = "Item Found s2";
                                   
                               
              //alert ("size 2 made it");    
                              
                                }//end size 2
                          }//end for size 2
                     
                           //size 3 hats are 3.5"W x 2"h     
                           for (k=0;k<size3.length;k++)
                           {
                              if (itemNum == size3[k])
                                {
                                   
                                    selecteditem.text = "Item Found s3";
                                    
                               
              //alert ("size 3 made it");   
                              
                                }//end size 3
                        }//end for size 3
                   
                            //size 4 hats are 4"w x2.5"H
                            for (h=0;h<size4.length;h++)
                            {
                              if (itemNum == size4[h])
                                 {
                                     selecteditem.text = "Item Found s4";
                                    
                               
              //alert ("size 4 made it");     
              
                               
                                }//end if size 4
                            }//end for size 4
                           
                             //size 5 visors are 3"w x 1.25"h  
                              for (j=0;j<size5.length;j++)
                              {
                              if (itemNum == size5[j])
                                {
                             selecteditem.text = "Item Found s5";
                            
                              
                               
              //alert ("size 5 made it");
                               
                                }//end if size 5
                            }//end for size 5
                       
                            //size 6 visors are 3.5"w x 1.25"h    
                            for (j=0;j<size6.length;j++)
                            {
                              if (itemNum == size6[j])
                              {
                                 
                                  selecteditem.text = "Item Found s6";
                           
              //alert ("size 6 made it");     
                           
                            }//end if size 6
                        }//end for size 6
                       
                            //size 7 visors are 4"w x 1.25"h   
                            for (j=0;j<size7.length;j++)
                            {
                              if (itemNum == size7[j])
                                {       
                                    selecteditem.text = "Item Found s7";
                                   
                                               
              //alert ("size 7 made it");     
                             
                                 }//end if size 7
                            }// end for size 7
                       
                            //size 8 hats are 3.5"w x 2.5"h
                            for (j=0;j<size8.length;j++)
                            {
                              if (itemNum == size8[j])
                                 {                
                                     selecteditem.text = "Item Found s8";
                                    
                               
              //alert ("size 8 made it");               
              
                                  }//end if size 8
                              }//end for size 8
                     
                      }//end on check item click 
                 
                var selecteditem = rsizegroup.add('statictext', undefined, "Item Not Found");
              
              

               

              but is there a way to compare the value entered against all the arrays like below?

               

              if (itemNum == size1[j] || size2[j] || size3[j] || size4[j] || size5[j] || size6[j] || size7[j] || size8[j])
              {
              selecteditem.text = "item Found" + ""MATCHED SIZE"";
              } else
              {
              selecteditem.text = "Item Not Found";
              
              

               

              how would I make the ""MATCHED SIZE"" show the one that the item number ended up matching since the if statement would return true but have all the sizes[j] saved as the answer? I may be misunderstanding it but doesn't the || mean "or" so the if would work but wouldn't return the value that is correct.  Also since size1[] has more values than any of the other sizes would it throw up an error once it reaches the third value since there isn't a second value for size5[], size6[], and size8[]? I've just recently started using arrays more and I'm not a hundred percent sure on how they compare in if statements.

              • 4. Re: Statis text not updating
                W_J_T Level 4

                Zantcor wrote:

                 

                Is there a way to compare the value entered against all the arrays like below?


                if (itemNum == size1[j] || size2[j] || size3[j] || size4[j] || size5[j] || size6[j] || size7[j] || size8[j]) {


                since size1[] has more values than any of the other sizes would it throw up an error once it reaches the third value since there isn't a second value for size5[], size6[], and size8[]? I've just recently started using arrays more and I'm not a hundred percent sure on how they compare in if statements.

                 

                You could do something like the following (as one alternative) to consolidate things into a single loop:

                 

                var maxPossible = size1.length;
                checkitem.onClick = function(veritemnum) {
                    for (var i = 0, l = maxPossible; i < l; i++) {
                        if (itemNum == size1[i]) {
                            selecteditem.text = "Item Found s1";
                        } else if (itemNum == size2[i]) {
                            selecteditem.text = "Item Found s2";
                        } else if (itemNum == size3[i]) {
                            selecteditem.text = "Item Found s3";
                        } else if (itemNum == size4[i]) {
                            selecteditem.text = "Item Found s4";
                        } else if (itemNum == size5[i]) {
                            selecteditem.text = "Item Found s5";
                        } else if (itemNum == size6[i]) {
                            selecteditem.text = "Item Found s6";
                        } else if (itemNum == size7[i]) {
                            selecteditem.text = "Item Found s7";
                        } else if (itemNum == size8[i]) {
                            selecteditem.text = "Item Found s8";
                        }
                    }
                };
                
                

                 

                However: The other option would be to change the entire approach and look into implementing the use of one of the following: listbox, dropdownlist or treeview for your interaction instead of using edittext input. If your arrays are hard coded with the possible choices then any of those alternatives would allow a more direct way to chose the desired item, at least in regards to how I understand your desired outcome.

                • 5. Re: Statis text not updating
                  Zantcor Level 1

                  That worked to consolidate and I added breaks and one more else to the end.

                   

                  
                  
                  
                  
                  var checkitem = itmgrp.add ('button', undefined, "Check item");
                  
                  
                  
                    
                  
                  
                  
                  
                  var maxPossible = size1.length;
                  
                  
                  
                  checkitem.onClick = function() {
                  
                  
                  
                  for (var i = 0, l = maxPossible; i < l; i++) {
                  
                  
                  
                  if (itemNum == size1[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s1";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size2[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s2";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size3[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s3";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size4[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s4";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size5[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s5";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size6[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s6";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size7[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s7";
                  
                  
                  
                  break;
                  
                  
                  
                  } else if (itemNum == size8[i]) {
                  
                  
                  
                  selecteditem.text = "Item Found s8";
                  
                  
                  
                  break;
                  
                  
                  
                  } else { selecteditem.text = "Item Not Found"; }
                  
                  
                  
                  }
                  
                  
                  
                  };
                  
                  
                  
                    
                    var selecteditem = rsizegroup.add('statictext', undefined, "Item Not Found");
                  
                  
                  

                   

                   

                  the people who will be using this already have a piece of paper in front of them with the item number so they can just type it in and go, the numbers change from time to time with old ones being removed and new ones being added, this is mainly there so people can check to make sure that the item they need is enabled in the script before hitting the resize button because if the item doesn't exist in any of the arrays it locks up when they resize.

                   

                  Thank you for all your help W_J_T, and have a Happy Saint Patrick's day!

                   

                   

                  EDIT1: Not sure why my code has all the extra spacing, I can't remove it from here for some reason it only shows when I hit reply...