[RESOLVED] Using textbox as variable
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] Using textbox as variable

  1. #1
    Join Date
    Jan 2013

    [RESOLVED] Using textbox as variable

    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:
    Textbox1.Text = "John<br />Peter"
    Textbox2.Text = "John"
    Textbox1.Text = "Peter"
    I did it this way:
    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"
    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:
    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)
    Dim stgSearch As String
    Dim stgCount() As String
    Dim a, n As Integer
    TextBox1.Text = ws.Cells(6, 6).value
    stgSearch = Textbox1.text
    stgCount = Split(stgSearch, "<br" , -1)
    a = UBound(stgCount) + n
    Call Separate
    Textbox7.Text = ws.Cells(11,6).value
    stgSearch = Textbox7.text
    stgCount = Split(stgSearch, "<br" , -1)
    a = UBound(stgCount) + n
    Call Separate
    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?

    Thanks alot! Bezzi94

    p.s.: I apologise for possible grammar and code mistakes

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: [RESOLVED] Using textbox as variable

    Try recording a Macro, to do everything EXCEPT the split, and work for ALL the rows, you can edit that code to add the SPLIT in the right place. (It should create a loop, or something you can convert INTO a loop.

    Edit: Also, use [Resolved] in the title only to tell us that you do not need any more help for the thread... It's like CLOSING it]
    Last edited by dglienna; February 5th, 2013 at 06:25 PM.

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center