Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm doing some VB monthly Sales chart, which is printed in listbox. Everything works fine except few things :). First I put all my subprocedures and functions in module. But in those functions I have myChart.AddItem statement (myChart listbox object is in my form), and when i'm trying to run the program it gives me error message that Object's required. I know that the it's looking for listbox object and alos i've should not specify the object's name in module. Is there any way to add something to listbox, on my from from subprocedure or function located in module? My second question is about formatting listbox's items ;). How do i specify how many characters should be reserved for the entry in listbox? I could look it up in the book, but since I don't have it... ;). Thanks, this forum rocks...

you need a loop to add data one at a time.
for i=0 to 50
Mychart.additem datatoadd(i+1)
next iHope that is what you mean?? This will add fifty items for you
the "datatoadd" is where your info is coming from. So I'm thinking you have to tell where to pull the data from...
Rob

You would pass the listbox into the mod procedure as an argument. So in the module you would have something like...
Public Sub ListAdd(lb As ListBox, strAdd As String)lb.AddItem strAdd
End Sub
and then in your form code have something like...
Private Sub Command1_Click()ListAdd List1, Text1.Text
End Sub
Not sure what you mean by the second question. You could use string functions to limit what goes into the ListAdd's text parameter or some code to limit how many entries are entered.

Thx guys,
thx for loop sequence rob0787, and
HiJinx that worked great (1st question). Second question is about the space reserved in listbox for entry, like 20 chars, and if i only add string of 4 , the rest 16 will all be spaces, and next entry in the same line will start after 20 chars even there will be 16 spaces following the last entry. Do u know what i mean? Thx again,

I'm still not entirely sure what you're referring to... unless what you're actually talking about is not a ListBox, but a ListView with its View property set to lvwList. If that's the case, I don't think there's a way to play with the column widths. Depending on what you're trying to do, you may be better off just using the simpler ListBox or using the Report view for the ListView to give you better control over the positioning of columns.

OK wait I'm just gonna copy the code
Output.AddItem Format$(ArrayMonth(c), "Currency") & vbTab & Format$(ArrayAverage(c), "Currency") & vbTab & Format$(ArrayVariation(c), "Currency")
i want to add 3 items in row , but i want to be able to reserve 10 chars for first entry, 6 for 2nd and 3rd.
example
January___(3spaces after)$450__$45___
i want to format the items so it will look like it's in columns.

OK I think this is it
Output.AddItem Format$(Format$(ArrayMonth(c), "Currency"), String$(15, "@")) & vbTab & Format$(Format$(ArrayAverage(c), "Currency"), String$(9, "@")) & vbTab & Format$(Format$(ArrayVariation(c), "Currency"), String$(9, "@"))
the only thing i want to change is position of months in the column, the are all in the center if i use
Format$(Format$(ArrayMonth(c), "Currency"), String$(15, "@"))
and i'd like them to be right justyfied. Any ideas? I 've tried doing this but it's not displaying anything at all ;/
Format$(Format$(ArrayMonth(c), "Currency"), String$(15, "!@")) <~~ is ! forcing it to be right justyfied?thnaks

Ok, I'm a little clearer, but in response 5, you have the month left justified, then in response 6, you're wanting it right justified (it would probably look best if you had the month left justified and the dollars right). Also, when you're formatting to currency, it adds a decimal, two zeros, and a dollar sign - which only leaves you room for double-digit amounts if you only want to reserve six spaces.
If I were doing this, I'd do away with the format calls and build everything myself. For example, the following code would give you left justified months and right justified numbers, but it shouldn't be hard for you to figure out how to change it to meet your needs. (I've also broken it up into separate statements to make it a little clearer.)
strMonth = ArrayMonth(c)
strAverage = "$" & CStr(ArrayAverage(c))
strVariation = "$" & CStr(ArrayVariation(c))strAdd = strMonth & String(10 - Len(strMonth), " ") & _
String(6 - Len(strAverage), " ") & strAverage & _
String(6 - Len(strVariation), " ") & strVariationOutput.AddItem strAdd

Thx HiJinx,
It works, the only thing is that I need those variables as Currency (teacher wants it as $;), but the rest works great. Thanks again HiJinx,
ZLO
Computing.net roxxxxxxxxxx

![]() |
latex & vim
|
Multiplication of vectors...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |