CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Location
    New England
    Posts
    2

    dump array in text box

    Hello
    I have an array MyArray( 127,8)
    I need to place this array on to a text box with the correct columns headings and row count heading. EXample col1 col2

    row 1 75 81 83 etc.
    I have seen it done by using a listbox but our professor wants us to use a textbox .Please help last project.
    Here is what I have for the array
    dim Myarray (127,8) as integer
    i = 0
    For x = LBound(MyArray) To UBound(MyArray)
    For y = LBound(MyArray, 2) To UBound(MyArray, 2)
    MyArray(x, y) = arrHeads(i) ' call to funtion that holds other data
    i = i + 1
    Next y
    Next x


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: dump array in text box

    Try:
    '(set your text1 multiline property to true)
    dim Myarray (127,8) as integer
    for x = 1 to 8
    text1.text = text1.text & "col" & x & space(1)
    next x

    i = 0
    For x = LBound(MyArray) To UBound(MyArray)
    For y = LBound(MyArray, 2) To UBound(MyArray, 2)
    MyArray(x, y) = arrHeads(i) ' call to funtion that holds other data
    if x < 10 then
    text1.text = text1.text & MyArray(x, y) & space(3)
    elseif x < 100 then
    text1.text = text1.text & MyArray(x, y) & space(2)
    else
    text1.text = text1.text & MyArray(x, y) & space(1)
    end if
    i = i + 1
    Next y

    text1.text = text1.text & vbcrlf
    Next x






    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: dump array in text box

    Here's a demonstration of aligning values in a textbox. You should be able to add the column and row headings for yourself. The only restriction is that the textbox font must be monospaced(such as Courier) and not proportional



    private Sub Command1_Click()
    Dim myArray(20, 10) as Integer
    Dim i as Integer, j as Integer
    Dim OneLine as string * 150
    for j = 0 to 10
    for i = 0 to 20
    myArray(i, j) = Rnd() * 1000
    next
    next

    for j = 0 to 10
    OneLine = Space(150)
    for i = 0 to 20
    mid$(OneLine, i * 5 + 1) = myArray(i, j)
    next
    Text1.Text = Text1.Text & OneLine & vbCrLf
    next

    End Sub






Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured