Hi Paul,
Please do not misunderstand me. I really appreciate any advice that I get. Even more, I appreciate the fact that you, Mack and others take the time to respond to novices queries.
Thanks for the Tutorial on Loops. My mental block is that I (think) I understand the basics on how to do these, but am lost as to when to do these. My application does not require a lot of loops.
When I think that a loop would result in more efficient coding, suddenly I am at a loss on how to implement this.
Take the following example; I am sure that a loop would have provided more efficient coding.
Code:
Kpress = "0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,"
len = Kpress.length
Debug.trace(len+"\n")
var itemdesc = new String(Kpress);
var myArray = itemdesc.split(",");
if(len < 3)
var item1 = "00";
var item2 = "00";
var item3 = "00";
var item4 = "00";
var item5 = "00";
var item6 = "00";
var item7 = "00";
var item8 = "00";
var item9 = "00";
//1
if((len >= 3 )&&(len < 7)){
var item1 = myArray[0]+ myArray[1];
var item2 = "00";
var item3 = "00";
var item4 = "00";
var item5 = "00";
var item6 = "00";
var item7 = "00";
var item8 = "00";
var item9 = "00";
}
//2
if((len >= 7 )&&(len < 11)){
var item1 = myArray[0]+ myArray[1];
var item2 = myArray[2]+ myArray[3];
var item3 = "00";
var item4 = "00";
var item5 = "00";
var item6 = "00";
var item7 = "00";
var item8 = "00";
var item9 = "00";
}
//3
if((len >= 11 )&&(len < 15)){
var item1 = myArray[0]+ myArray[1];
var item2 = myArray[2]+ myArray[3];
var item3 = myArray[4]+ myArray[5];
var item4 = "00";
var item5 = "00";
var item6 = "00";
var item7 = "00";
var item8 = "00";
var item9 = "00";
}
//etc
Full details on Post:
viewtopic.php?t=2828&highlight=This should probably have looked something like:
Code:
Kpress = "0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,"
len = Kpress.length
Debug.trace(len+"\n")
var itemdesc = new String(Kpress);
var myArray = itemdesc.split(",");
var itemArray
If (len < 3) {
for (i=1;i<=9;i++){
var itemArray[i] = “00”
}
}
if((len >= 3 )&&(len < 7)){
for (i=2;i<=9;i++){
var itemArray[1] = myArray[0]+ myArray[1];
var itemArray[i] = “00”
}
}
if((len >= 7 )&&(len < 11)){
for (i=3;i<=9;i++){
var itemArray[1] = myArray[0]+ myArray[1];
var itemArray[2] = myArray[1]+ myArray[2];
var itemArray[i] = “00”
}
}
//Etc…
I am not sure how to create a blank array.
My guess would be:
Code:
var item = new string()
var itemArray = item.split(“,”)
I am not sure if this would work, I am just trying to get past my mental block on loops. When I have tried to impliment these in the past, I have had problems.
Thanks again for your input. It really is appreciated!
Regards
Neil