程序循环-布尔不起作用 [英] Program Looping - Boolean not working

查看:79
本文介绍了程序循环-布尔不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序填写了一个网络表单并提交.问题在于,即使在新加载的页面上,它也会继续提交.我正在使用布尔值尝试阻止程序再次提交,但无法正常工作.有谁知道一种更好的编码方式或一种更好的方式使其停止提交?谢谢你.

My program fills out a web form and submits it. The problem is that it keeps submitting even on the newly loaded page. I was using a Boolean to try to stop the program from submitting again but it''s not working. Does anyone know a better way to code this or a better way to get it to stop submitting? Thank You.

Public Class Form1
    
    Dim firstSubmit As Boolean = True
    Dim firstButton As Boolean = True
    Dim firstImage As Boolean = True

theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
    
        If firstSubmit = True Then
        ElseIf firstButton = True Then
        ElseIf firstImage = True Then
            For Each curElement As HtmlElement In theElementCollection
                If curElement.GetAttribute("name").Equals("button") Then
                    curElement.InvokeMember("click")
                ElseIf curElement.GetAttribute("type").Equals("image") Then
                    curElement.InvokeMember("click")
                ElseIf curElement.GetAttribute("type").Equals("submit") Then
                    curElement.InvokeMember("click")

                    
                    firstSubmit = False
                    firstButton = False
                    firstImage = False

推荐答案

,您可以尝试逐渐增加冲突,然后在循环中递增var.一旦达到总数,便会中断循环并退出该函数.
you could try grathering the number of Elements that are in the collrction ,then as you go through the loop increment the var. once you reach the total then break out the loop and drop out of the function.


我之前已经做过类似的事情.基本上,我创建了几个类,并以某种脚本"形式表达了自己的行为.因此,我创建了一个Site类,其中包含另一个名为Step的类的列表.每个步骤都有一个动作列表,这是要执行的实际动作,以及一个事件,当该步骤完成时将触发该事件.

因此,当WebBrowser控件加载其第一页时,它开始循环浏览步骤列表,然后循环遍历该步骤的每个Action,激发Completed事件,而Completed事件开始下一个步骤,执行完成直到那里''没有更多的步骤.
I''ve done something similar to this before. Basically I created a couple of classes and sort of "scripted" out my actions. So I created a Site class containing a List of another class called Step. Each Step has a List of Actions which is the actual action to be performed and an event which will fire when the Step has been completed.

So when the WebBrowser control loads its first page it starts looping through the list of Steps, which then loops through each Action for the Step, fires the Completed event, and the Completed event kicks off the next Step and the execution completes until there''s no more Steps.


这篇关于程序循环-布尔不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆