Search the web
Sign In
New User? Sign Up
vbhelp · Visual Basic Help Center Forum
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
How to Format items from an Array into Neat Compact Columns?   Message List  
Reply | Forward Message #15792 of 15862 |
Re: How to Format items from an Array into Neat Compact Columns?

--- In vbhelp@yahoogroups.com, "jim8440" <james8570@...> wrote:
>
> Suppose I have some numbers from 1 to 10 in an array (but it could be
> of any size). I want them to be formatted into 3 columns (but it could
> be of any # of columns), but in a particular way.
>
> Array is:
> xyz[1] =1
> xyz[2] =2
> xyz[3] =3
>
> and so on....
>
> Example:
>
> Instead of this format (I've figured out how to format this
> programatically) :
> 1 5 9
> 2 6 10
> 3 7
> 4 8
>
> I would prefer it this way:
> 1 5 8
> 2 6 9
> 3 7 10
> 4
>
>
> Thank you in advance for your help!
>

This code sample assumes you have a textbox
and a flexgrid on your form that "each" takes
up roughly half of the height of the form and
the width of each is roughly the width of the
form.

'Be aware of possible line-wrapping.
'Be aware of possible unwanted space(s).
'Adjust to suit your needs.

'Start of Code
Private Sub Form_Load()
Dim i As Long, n As Long, r As Long, c As Long

For i = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.ColWidth(i) = 922
Next
For i = 0 To MSFlexGrid1.Rows - 1
MSFlexGrid1.RowHeight(i) = 300
Next

Dim ma As Long
ma = 16 'ubound of numeric array (randomly chosen for this
demo. adjust flexgrid accordingly if changed.)
Dim mf As Long
mf = 4 'maximum number of items in the first column
Dim mr As Long
mr = 3 'maximum number of items in the remaining columns

ReDim NumArray(ma) As Long
'fill the numeric array for this demo
For i = 0 To UBound(NumArray) - 1
NumArray(i) = i + 1
Next

'for textbox (or richeditbox) it's easier to create strings
'that can be used to display the numeric array as formatted
ReDim StrArray(mf) As String
For i = 0 To UBound(NumArray) - 1
If i < mf Then
StrArray(i) = Format(NumArray(i), "00")
Else
n = (i - mf) Mod mr
StrArray(n) = StrArray(n) + Chr(9) + Format(NumArray(i), "00")
End If
Next
Text1.Text = ""
For i = 0 To UBound(StrArray) - 1
Text1.Text = Text1.Text & StrArray(i) & vbCrLf
Next

'for flexgrid (or listview) it's easier to just
'figure out where the data should be displayed
c = 0
For i = 0 To UBound(NumArray) - 1
If i < mf Then
MSFlexGrid1.TextMatrix(i, c) = Format(NumArray(i), "00")
Else
r = ((i - mf) Mod mr)
If r = 0 Then c = c + 1
MSFlexGrid1.TextMatrix(r, c) = Format(NumArray(i), "00")
End If
Next
End Sub
'End Of Code

David





Wed Oct 15, 2008 10:56 pm

burkleyd
Offline Offline
Send Email Send Email

Forward
Message #15792 of 15862 |
Expand Messages Author Sort by Date

Suppose I have some numbers from 1 to 10 in an array (but it could be of any size). I want them to be formatted into 3 columns (but it could be of any # of...
jim8440
Offline Send Email
Oct 12, 2008
9:20 pm

I think the spaces got removed in your post. Why not use a char like * to illustrate your needs. Where is the output going to appear ? Is there an exact Column...
Rob
crombierob
Offline Send Email
Oct 13, 2008
7:42 am

... This code sample assumes you have a textbox and a flexgrid on your form that "each" takes up roughly half of the height of the form and the width of each...
burkleyd
Offline Send Email
Oct 16, 2008
12:50 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help