How To Use Loops In CC

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Alright all you programming wizards out there (Shade) maybe you can help this newbie to C how to do this. As we know, dynamically created document addresses are a pain in the ass. Combine that with a site that has to use emulations to fill in text before a button is available and we have the ultimate monster for making a template.

Here's the dilemma. How do you use a counter in CC as a variable to input into a document address?

Код:
// Setting value [this is cr...] to the element with tag [textarea]
			he = instance.GetTabByAddress("page").GetDocumentByAddress("0;_13").FindElementByTag("form", 0).FindChildByName("text_text");
			if (he.IsVoid) {
				he = instance.GetTabByAddress("page").GetDocumentByAddress("0;_13").FindElementByTag("form", 0).FindChildByAttribute("textarea", "fulltag", "textarea", "text", 0);
			}
			if (he.IsVoid) return -1;
Without having to copy and paste each line with a different document address, is there a way to create a variable that is input into the document address and if so, how would you go about looping it back up if it returns -1 to add another number to the counter and try it. I've been looking at HeadFirst's tutorials on C# and can't seem to wrap my head around it. Do you use a 'while' loop or if;else.

Help me out here please.
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Bump
 

shade

Client
Регистрация
19.11.2010
Сообщения
580
Благодарностей
346
Баллы
63
Alright all you programming wizards out there (Shade) maybe you can help this newbie to C how to do this. As we know, dynamically created document addresses are a pain in the ass. Combine that with a site that has to use emulations to fill in text before a button is available and we have the ultimate monster for making a template.

Here's the dilemma. How do you use a counter in CC as a variable to input into a document address?

Код:
// Setting value [this is cr...] to the element with tag [textarea]
            he = instance.GetTabByAddress("page").GetDocumentByAddress("0;_13").FindElementByTag("form", 0).FindChildByName("text_text");
            if (he.IsVoid) {
                he = instance.GetTabByAddress("page").GetDocumentByAddress("0;_13").FindElementByTag("form", 0).FindChildByAttribute("textarea", "fulltag", "textarea", "text", 0);
            }
            if (he.IsVoid) return -1;
Without having to copy and paste each line with a different document address, is there a way to create a variable that is input into the document address and if so, how would you go about looping it back up if it returns -1 to add another number to the counter and try it. I've been looking at HeadFirst's tutorials on C# and can't seem to wrap my head around it. Do you use a 'while' loop or if;else.

Help me out here please.
Hi bigcajones.

I hope that I correctly understand you. So, my answer:

Of course for loop would be better to use "while" or "for" or "foreach". By the way, almost any duplication of code is better to replace by loops. For your problem I think it should be like this:
JavaScript:
            // review all addresses from "0" to "2"
            for (int i = 0; i < 3; i++)
            {
                he = instance.GetTabByAddress("page").GetDocumentByAddress(i.ToString()).FindElementByTag("form", 0).FindChildByName("text");
                if (he.IsVoid) {
                    he = instance.GetTabByAddress("page").GetDocumentByAddress(i.ToString()).FindElementByTag("form", 0).FindChildById("text");
                }
                if (he.IsVoid) {
                    he = instance.GetTabByAddress("page").GetDocumentByAddress(i.ToString()).FindElementByTag("form", 0).FindChildByAttribute("input:text", "fulltag", "input:text", "text", 0);
                }
                if (he.IsVoid) 
                {
                    // if did not watch all addresses then go to the next iteration of the loop
                    if (i != 2) continue;
// if watched all addresses then return -1
                    else return -1;
                }
                // if the html element was found then break loop and go to next block of code
                else break;
            }
But I think that this example is not useful. So, it will be better if you write me url of site and point me where is a problem.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)