Computing.Net > Forums > Programming > Visual Basic ListBox format, module

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Visual Basic ListBox format, module

Reply to Message Icon

Name: ZLO
Date: December 8, 2002 at 03:04:30 Pacific
OS: winXP
CPU/Ram: 512
Comment:

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...




Sponsored Link
Ads by Google

Response Number 1
Name: rob0787
Date: December 8, 2002 at 06:32:55 Pacific
Reply:

you need a loop to add data one at a time.

for i=0 to 50
Mychart.additem datatoadd(i+1)
next i

Hope 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


0

Response Number 2
Name: HiJinx
Date: December 8, 2002 at 10:58:41 Pacific
Reply:

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.


0

Response Number 3
Name: ZLO
Date: December 8, 2002 at 16:01:16 Pacific
Reply:

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,


0

Response Number 4
Name: HiJinx
Date: December 8, 2002 at 19:16:32 Pacific
Reply:

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.


0

Response Number 5
Name: ZLO
Date: December 9, 2002 at 00:05:49 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: ZLO
Date: December 9, 2002 at 00:20:28 Pacific
Reply:

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


0

Response Number 7
Name: HiJinx
Date: December 9, 2002 at 09:53:01 Pacific
Reply:

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), " ") & strVariation

Output.AddItem strAdd



0

Response Number 8
Name: ZLO
Date: December 10, 2002 at 06:26:40 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

latex & vim Multiplication of vectors...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Visual Basic ListBox format, module

Visual Basic for Excel97 www.computing.net/answers/programming/visual-basic-for-excel97/9351.html

Visual Basic Code for Parallel port www.computing.net/answers/programming/visual-basic-code-for-parallel-port/9535.html

Visual Basic 2 .EXE www.computing.net/answers/programming/visual-basic-2-exe/6686.html