这个问题需要很少的帮助vb 2010 [英] little help needed in this problem vb 2010
问题描述
我在三个文本框中输入了一个文本3个文本框和一个按钮
DOB如ex:21 07 1993格式文本框4,5, 6我将得出2 + 1 + 0 + 7 + 1 + 9 + 9 + 3 = 34> 3 + 4 = 7,这意味着7将作为第7个文本框中的输出。我的问题如果输入b''day喜欢:1 3 1986> 1 + 3 + 1 + 9 + 8 + 6 = 28> 2 + 8 = 10这里10显示在第7个文本框中。但我希望输出为1 + 0 = 1即1作为输出(如果是两位数字)我该怎么办呢请告诉我
i试过这个
i made a text 3 text boxes and one button in that three text boxes i enter
DOB like ex:21 07 1993 format in textboxes 4,5,6 i will get out put as 2+1+0+7+1+9+9+3=34>3+4=7 in that means 7 will come as output in 7th text box. my problem if enter b''day like :1 3 1986 > 1+3+1+9+8+6=28 > 2+8=10 here "10" is displayed in 7th text box. but i want output as 1+0= 1 i.e "1" as output(in case to two digit numbers) how can i do that please tell me
i tried this
Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
Dim i As Integer = 0
Dim l As Integer = 0
Dim lcn As String
If TextBox4.Text = "" And TextBox5.Text = "" Then
MessageBox.Show("Please Enter Date of Birth!!!")
End If
For Each digit In (TextBox4.Text + TextBox5.Text + TextBox6.Text)
i += Val(digit)
Next
lcn = i.ToString
For Each digit In lcn
l += Val(digit)
Next
TextBox7.Text = l.ToString
End Sub
请在回答所有人之前再次仔细阅读:圣诞快乐!!!
please help me read carefully once again before answering thanks to all:Merry Christmas!!!
推荐答案
For Each digit In (TextBox4.Text + TextBox5.Text + TextBox6.Text).ToCharArray()
i += CInt(digit)
首先将它转换为CharArray
Convert it to a CharArray first
我会创建一个函数,它接受一个字符串作为参数,并返回一个加在一起的数字值。
I would create a function, that took a string as it''s parameter, and returned a value that was the digits added together.
Private Function AddDigits(s As String) As Integer
Dim result As Integer = 0
For Each c As Char In s
If [Char].IsDigit(c) Then
result += AscW(c - "0"C)
End If
Next
Return result
End Function
然后我会使用循环来调用它,直到我只剩下一位数:
I would then use a loop to call this until I had only one digit left:
Dim str As String = "123324::34"
Dim res As Integer = 0
Do
res = AddDigits(str)
str = res.ToString()
Loop While res >= 10
myTextBox.Text = str
试试这个:
Hi,
Try this:
Private Sub KryptonButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
Dim i As Integer = 0
Dim l As Integer = 0
Dim lcn As String = ""
If String.IsNullOrEmpty(textBox4.Text) AndAlso String.IsNullOrEmpty(textBox5.Text) AndAlso String.IsNullOrEmpty(textBox6.Text) Then
MessageBox.Show("Please Enter Date of Birth!!!")
Return
End If
Dim dateOfBirthWithoutSpaces As String = (TextBox4.Text + TextBox5.Text + TextBox6.Text).Replace(" ", "")
For Each c As Char In dateOfBirthWithoutSpaces
i += (Convert.ToInt32(c.ToString()))
Next
lcn = i.ToString()
While lcn.Length > 1
l = 0
For Each c As Char In lcn
l += (Convert.ToInt32(c.ToString()))
Next
lcn = l.ToString()
End While
TextBox7.Text = lcn
End Sub
希望这有帮助。
Hope this helps.
这篇关于这个问题需要很少的帮助vb 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!