VB.net重复的文本框输入验证

编程入门 行业动态 更新时间:2024-10-24 08:23:51
本文介绍了VB重复的文本框输入验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我需要帮助VB中的一个功能。

我有6个文本框仅限于数字,仅限于1-25的用户必须填写的数字我需要一种方式来检查文本框中的重复数字,当我点击按钮。

这是我的代码到目前为止:

Private Sub validate_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理validate.Click 对于每个t在textBox中如果String .IsNullOrEmpty(t.Text)然后 nr1.Text = nr2.Text = nr3.Text = nr4.Text = nr5.Text = nr6.Text = nr1.Focus()退出子退出结束如果下一步t Dim rand = GetRandom(1,1715) Dim miliseconds = CLng(DateTime.Now.Subtract(New DateTime(1970,1,1))。TotalMilliseconds) strSQL = xxxxxxxx D im da As New MySqlDataAdapter(strSQL,CONNECTION) da.Fill(ds) nr1.Text = nr2.Text = nr3.Text = nr4.Text = nr5.Text = nr6.Text = value.Text =1 broj1.Focus() list() End Sub

谢谢:)

好的,我设法让它工作,这里是代码:

好的,谢谢你们回答我。

我已经找到解决方案,如果有人需要,我会在这里发布:

Dim textBoxes As TextBox()= New TextBox(){nr1,nr2,nr3,nr4,nr5,nr6} 对于i As Integer = 0到textBoxes.Length - 2 对于j As Integer = i + 1 To textBoxes.Length - 1 如果textBoxes(i).Text = textBoxes(j).Text然后 //无法执行,找到重复 MessageBox.Show(Me,Duplicate value) textBoxes(j).Focus()返回结束如果下一个下一个 // sucessful

解决方案

如果有一些重复,这意味着至少有2个。

你必须这样做这样的事情

(int i = 1;

I&10 6; i ++) for(int j = i + 1; j< = 6; j ++) { if(名称为nr + i的控件的值与控制名称为nr + j) { //有一个重复的} }

要获取VB中的名称控件 - 如何通过名称引用Windows窗体控件(C#/ VB)

我希望你可以在VB中翻译。

I need help with one function in VB.

I have 6 textboxes limited only to numbers and only to numbers from 1-25 which user must fill in. I need a way to check for duplicate numbers in textboxes when i click button.

Here is my code so far:

Private Sub validate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles validate.Click For Each t In textBoxes If String.IsNullOrEmpty(t.Text) Then nr1.Text = "" nr2.Text = "" nr3.Text = "" nr4.Text = "" nr5.Text = "" nr6.Text = "" nr1.Focus() Exit Sub Exit For End If Next t Dim rand = GetRandom(1, 1715) Dim miliseconds = CLng(DateTime.Now.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds) strSQL = xxxxxxxx Dim da As New MySqlDataAdapter(strSQL, CONNECTION) da.Fill(ds) nr1.Text = "" nr2.Text = "" nr3.Text = "" nr4.Text = "" nr5.Text = "" nr6.Text = "" value.Text = "1" broj1.Focus() list() End Sub

Thank you :)

Ok, i managed to get it working, here is the code:

Ok, thank you guys for answering me.

I have found solution and if anyone needs it i will post it here:

Dim textBoxes As TextBox() = New TextBox() {nr1, nr2, nr3, nr4, nr5, nr6} For i As Integer = 0 To textBoxes.Length - 2 For j As Integer = i + 1 To textBoxes.Length - 1 If textBoxes(i).Text = textBoxes(j).Text Then //failed to execute, found duplicates MessageBox.Show(Me, "Duplicate value.") textBoxes(j).Focus() Return End If Next Next //sucessful

解决方案

Well if there is some duplicate, it means that there are at least 2.

You have to do something like this

for(int i=1; i<6; i++) for(int j=i+1; j<=6; j++) { if(the value of the control with the name nr+i has the same value as the control with the name nr+j) { // there is a duplicate } }

To get a control by name in VB - How do I refer to a windows form control by name (C# / VB)

I hope you can translate this in VB.

更多推荐

VB.net重复的文本框输入验证

本文发布于:2023-11-03 20:34:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556022.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   VB   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!