VB.NET 中的输入框到数组
我这里有一个程序可以解决表达式...
首先我需要在文本框中输入表达式。它将存储在 CharArray 中,然后使用输入框将变量替换为整数...
我的问题是:如何将整数存储到数组中并存储操作?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr() As Char = TextBox1.Text.ToCharArray
Dim aChar As Char
Dim a As String
Dim calc() as String
'Me.Height = Me.Height + 90
Me.Button1.Enabled = False
Me.TextBox1.Enabled = False
For i = 0 To TextBox1.Text.Length() - 1
aChar = arr.ElementAt(i)
If Char.IsLetter(aChar) Then
a = InputBox("Enter value for " & aChar, "Expression")
'Here what code?
' Try
' calc(i) = a
' Catch ex As Exception
' MsgBox("eee")
' End Try
'Else
End If
Next i
End Sub
I have a program here that will solve an expression...
First I need to input the expression in a textbox. That will be stored in a CharArray and then substitute the variables to integer by using input boxes...
My problem is: How can I store the integer to an array and also store the operation?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim arr() As Char = TextBox1.Text.ToCharArray
Dim aChar As Char
Dim a As String
Dim calc() as String
'Me.Height = Me.Height + 90
Me.Button1.Enabled = False
Me.TextBox1.Enabled = False
For i = 0 To TextBox1.Text.Length() - 1
aChar = arr.ElementAt(i)
If Char.IsLetter(aChar) Then
a = InputBox("Enter value for " & aChar, "Expression")
'Here what code?
' Try
' calc(i) = a
' Catch ex As Exception
' MsgBox("eee")
' End Try
'Else
End If
Next i
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常更喜欢使用通用列表,它们使添加和删除项目变得更加容易。下面的代码应该可以满足您的需要:
I generally prefer to work with generic Lists, they make adding and removing items much easier. The code below should do what you need:
我还没有测试过这个或任何东西,但我认为稍微重构一下它以使用 For Each 循环,并且确定范围或摆脱 a 和 aChar 变量将是一个更好的方法:
I haven't tested this or anything, but I think refactoring this a tad to use the For Each loop and either scoping or get rid of the a and aChar variables would be a little nicer approach: