vba 在 Visual Basic 中将文本添加到文本框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16451592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add Text Into Textbox's in Visual Basic
提问by Melternet
Ok, so im trying to make this program and i need this: "Melternet Hello [email protected] 5/7/2013" to be in different textbox's like this
好的,所以我正在尝试制作这个程序,我需要这个:“Melternet Hello [email protected] 5/7/2013”像这样在不同的文本框中
"Textbox1 = Melternet"
“Textbox1 = Melternet”
"Textbox2 = Hello"
“Textbox2 = 你好”
"Textbox3 = [email protected]"
“Textbox3 = [email protected]”
"Textbox4 = 5/7/2013"
“文本框 4 = 5/7/2013”
So pretty much every space is a cut off line to add that text to a textbox and then it does the rest like the first one
所以几乎每个空格都是一条分割线,用于将该文本添加到文本框,然后它像第一个一样完成其余的工作
How would i do something like that, thanks in advance.
我将如何做这样的事情,提前致谢。
Please Answer Back If Anyone Can Figure This Out Or Help Me, NEED THIS QUICK...
如果有人能解决这个问题或帮助我,请回复,需要这个快速...
BTW: i'm using Visual Basic 2008.
顺便说一句:我使用的是 Visual Basic 2008。
回答by Idle_Mind
Without more info...something like:
没有更多信息......类似:
Dim data As String = "Melternet Hello [email protected] 5/7/2013"
Dim values() As String = data.Split(" ")
If values.Length >= 4 Then
TextBox1.Text = values(0)
TextBox2.Text = values(1)
TextBox3.Text = values(2)
TextBox4.Text = values(3)
End If
回答by Idle_Mind
It looks like you are simply splitting the entire input text string: "Melternet Hello [email protected] 5/7/2013" wherever a space occurs, yes(?)
看起来您只是在拆分整个输入文本字符串:“Melternet Hello [email protected] 5/7/2013” 出现空格的任何地方,是(?)
If your string has a variable number of words, then fill up textboxes programmatically, like, e.g.:
如果您的字符串具有可变数量的单词,则以编程方式填充文本框,例如:
Dim mystr as String
mystr = "hello world I want to paste this to multiple textboxes"
Dim Buff() as String
Buff = Split(mystr," ")
For i As Integer = 0 to UBound(Buff)
Dim tb As New TextBox
str = Buff(i)
tb.Name = str
tb.Text = str
tb.Left = 50
tb.Top = 50 + 25 * i
tb.Width = 50
tb.TextAlign = HorizontalAlignment.Right
Me.Controls.Add(tb)
Next
In the above fashion, no matter what the value of mystr, or how many words are in the string (mystr), you can write them all to new textboxes that are created/placed dynamically on Form1, i.e. "Me".
以上述方式,无论 mystr 的值是多少,或者字符串 (mystr) 中有多少个单词,您都可以将它们全部写入在 Form1 上动态创建/放置的新文本框,即“我”。