比较多个文本框中的值 [英] Compare value from multiple textboxes

查看:89
本文介绍了比较多个文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何将panel6中所有可见文本框的值与textbox1中的值进行比较?



谢谢



我尝试过:



我尝试了这个编辑过的代码,但在这部分没有任何反应。

Hello,

How can I compare value from all visible textboxes in panel6 with value in textbox1?

thank you

What I have tried:

I tried this edited code but in this part nothing happen.

If ctl.Text = TextBox1.Text Then
                        ctl.BackColor = Color.LimeGreen













Dim EmptyTextBoxFound As Boolean = False 'Boolean flag for empty textbox
     Dim EmptyTextBoxName As String = ""
     For Each ctl As Control In Panel6.Controls
         If TypeOf ctl Is TextBox AndAlso ctl.Visible AndAlso ctl.Text.Length > 6 Then
             EmptyTextBoxName = ctl.Name
             EmptyTextBoxFound = True
             Exit For

             If EmptyTextBoxFound = True Then
                 If ctl.Text = TextBox1.Text Then
                     ctl.BackColor = Color.LimeGreen
                 Else
                     ctl.Select()
                     ctl.BackColor = Color.LightSalmon
                 End If

             End If
             End If

     Next

推荐答案

我们分不清楚 - 我们在运行时无法访问您的应用。

所以,这取决于您。

幸运的是,您有一个可用的工具你将帮助你找出发生了什么:调试器。

在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但是我们不能为你做到这一点 - 时间让你学习一种新的(非常非常有用的)技能:调试!



但请注意两个事物:

1)如果TextBox1在你的表单上,它将在Controls集合中,所以如果文本超过6个字符,你可以保证匹配。

2)你的循环不会拾取面板,TabPages或任何其他容器中的TextBox - 只有直接在窗体上的控件才会出现在它的Controls集合中。
We can't tell - we don't have any access to your app while it is running.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

But do note two things:
1) If TextBox1 is on your form, it will be in the Controls collection, so you are guaranteed a match provided the text is longer than 6 characters.
2) Your loop will not pick up TextBoxes which are in panels, TabPages, or any other container - only controls with are directly onto the form will appear in it's Controls collection.


我已经向你解释了你的另一个问题是什么问题 -

控制空文本框 [ ^ ]



我甚至包含了一篇文章的链接,该文章将向您展示如何使用调试器在Visual Studio 2010中进行调试 - 初学者指南 [ ^ ]



即使您只是阅读代码,很明显您所引用的代码永远不会被执行,因为退出



I have already explained to you what the problem is on your other question -
Control empty textboxes[^]

I even included a link to an article that will show you how to use the debugger Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Even if you simply read the code it is obvious that the code you refer to can never be executed because of the Exit For

Dim EmptyTextBoxFound As Boolean = False 'Boolean flag for empty textbox
     Dim EmptyTextBoxName As String = ""
     For Each ctl As Control In Panel6.Controls
         If TypeOf ctl Is TextBox AndAlso ctl.Visible AndAlso ctl.Text.Length > 6 Then
             EmptyTextBoxName = ctl.Name
             EmptyTextBoxFound = True
             Exit For  '<<<<<<<<<<<<<<<<<<<< THIS LINE HERE JUMPS EXECUTION TO . . .             
             
             If EmptyTextBoxFound = True Then                                   V
                 If ctl.Text = TextBox1.Text Then                               |
                     ctl.BackColor = Color.LimeGreen                            |
                 Else                                                           |
                     ctl.Select()                                               |
                     ctl.BackColor = Color.LightSalmon                          |
                 End If                                                         |
                                                                                |
             End If                                                             |
             End If                                                             V

     Next                      
'<<<<<<<<<<<<<<<<<<< THIS LINE HERE 


这篇关于比较多个文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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