Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: In VB-6 to put text boxes data in a array  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

lohani

    Topic Starter


    Rookie

    In VB-6 to put text boxes data in a array
    « on: October 25, 2009, 11:30:23 AM »
    Sir,
    In VB-6 application, there are 15 text boxes and these get data from mdb file. I want to use the data of these text boxes in a array, how can I ?
    Example
                text1.text=100, text2.text=200 and so on upto text15.text
               Dim test(15),
    To put these value in a array
               for i = 1 to 15 
                     test(i)=val(text(i).text))  ' so that test(i) may contain data of text1.text
               next
    This is not working, why? Please tell me reason or solution

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: In VB-6 to put text boxes data in a array
    « Reply #1 on: October 25, 2009, 11:35:52 AM »
    create a control array.

    Or you could create a property procedure in your form, for example:

    Code: [Select]
    Public Property Tbox(Byval Index as Long) as TextBox
    if index=1 then set TBox = Text1
    if index=2 then set TBox = Text2
    if index=3 then set TBox = Text3
     ' and so on...

    End Property

    a Control array is created by copy-pasting the same control, or a control with the same name as a control on the form.
    I was trying to dereference Null Pointers before it was cool.

    lohani

      Topic Starter


      Rookie

      Re: In VB-6 to put text boxes data in a array
      « Reply #2 on: October 25, 2009, 12:07:31 PM »
      Sir,
      In reference to my querry, what has been suggested still carry on my problem ie I do not want to use text1 or text2 . In place of it, I want to input data through Loop
               for i = 1 to 15 
                       test(i)=val(text(i).text))  ' so that test(i) may contain data of text1.text
                 next
      My purpose is to minimise my code, If I have to use 50 text boxes then ? will I have3 to write 50 lines ?
      Please solve my problem this way.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: In VB-6 to put text boxes data in a array
      « Reply #3 on: October 25, 2009, 12:33:30 PM »
      use control arrays. It's your problem, not mine, remember?


      Set the Index property on the textboxes and give them the same Name.
      I was trying to dereference Null Pointers before it was cool.

      lohani

        Topic Starter


        Rookie

        Re: In VB-6 to put text boxes data in a array
        « Reply #4 on: October 25, 2009, 12:58:37 PM »
        My dear friend,

        what you mean by Remember? or it is your problem not mine.

        I had not compelled you to solve my problem. I know solution of my problem but in a lengthy way. If you cann't solve my problem in shorter way, you need not to answer but not in a such a way.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: In VB-6 to put text boxes data in a array
        « Reply #5 on: October 25, 2009, 01:08:13 PM »
        Use a control array. I already said this. this is what you need to do.
        I was trying to dereference Null Pointers before it was cool.