Hello everyone, again me, with new project. Just to remind you, I am still in Gymnasium and I learn everything by my self so please explain any possible solution as much as you can. Thanks
So here is the thing, I imported some (random) Excell file in VB and imported specific Cell in Textbox. Now I want to split one Textbox in two or more Textboxes. Example:
I did it this way:Code:Textbox1.Text = "John<br />Peter" Textbox2.Text = "John" Textbox1.Text = "Peter"
But the thing is I have to do this for at least 44 Cells and for up to 6 names so it would be preety hard and long to write this kind of code for all Cells. So I have an idea how to make it short and simple:Code:Textbox1.Text = ws.Cells(6,6).value 'So textbox1.Text = "John<br />Peter" TextBox2.Text = TextBox1.Text.Substring(TextBox1.Text.IndexOf("/>")) 'So textbox2.text = "/>Peter" TextBox1.Text = TextBox1.Text.Replace("<br ", "") 'So textbox1.Text = "John/>Peter" TextBox1.Text = TextBox1.Text.Replace(TextBox2.Text, "") 'So textbox1.Text = "John" TextBox2.Text = TextBox2.Text.Substring(2) 'So textbox2.Text = "Peter"
And so on (reason why I made n = 7 is to "book" 6 labels for first Cell), for as many Cells I need. The problem is that textbox(n).text and textbox(n+1).text doesn't work for me, so anyone can help me out here?Code:Private Function Separate(ByVal x As Integer, ByVal y As String) As String While a > n textbox(n+1).text = textbox(n).text.Substring(textbox(n).text.IndexOf("/>")) textbox(n).text = textbox(n).text.replace(textbox(n+1),"") textbox(n).text = textbox(n).text.replace("<br ","") textbox(n+1).text = textbox(n+1).text.Sunbstring(2) n=n+1 Dim stgSearch As String Dim stgCount() As String Dim a, n As Integer TextBox1.Text = ws.Cells(6, 6).value n=1 stgSearch = Textbox1.text stgCount = Split(stgSearch, "<br" , -1) a = UBound(stgCount) + n Call Separate Textbox7.Text = ws.Cells(11,6).value n=7 stgSearch = Textbox7.text stgCount = Split(stgSearch, "<br" , -1) a = UBound(stgCount) + n Call Separate
Thanks alot! Bezzi94
p.s.: I apologise for possible grammar and code mistakes![]()



Reply With Quote
Bookmarks