Solved

Listviews and keeping info on same line

Posted on 1998-10-12
16
182 Views
Last Modified: 2010-04-30
This is the code I use to get my listview populated from just the text boxes on the page this has nothing to do with databases just moving info in text boxes to listview:
 
     Do While j < 8
     If chksize(j).Value= 1 Then
         Set Order= lvOrder.ListItems.Add(, ,cboNumber.Text)
         lvOrder.ListItems.Add.SubItems(1) = strsize(j)
         lvOrder.ListItems.Add.SubItems(2) =                   Val(txtQuantity(j).Text) & "@" & Format _              (sngprice(j), "Currency")
         lvOrder.L.ListItems.Add.SubItems(3)=          cboSubject.Text
     End If
     j= j+1
     Loop
     End Sub

     However, the problems with this is that it puts the four items that I want to add in the correct columns, but all on different lines.  I have tried _ and + and ; but
none of them work.  It doesn't put all i want on one line, it puts the four things on four different lines but in the correct columns, can you tell me how to do this please????

Also, above, strsize(j) and sngprice(j) come from the sub procedure when I load the file they are in.  I get an error because they are not declared, but when I declare them, it still doesn't work, so I assume that in the above sub
procedure I need to do something like
    Private Sub Add_To_Order_Click( strsize(j), sngprice(j))  or something like that to identify that it is getting called from another procedure, but that doesn't seem to work.   I am sorry for all the questions, but I don't what to do??
Thanks ,Amy



0
Comment
Question by:amy420
  • 5
  • 4
  • 4
  • +2
16 Comments
 
LVL 4

Expert Comment

by:mcix
Comment Utility
For the first part of your question try:

Dim Order As ListItem
      
Set Order= lvOrder.ListItems.Add(, ,cboNumber.Text)
Order.SubItems(1) = strsize(j)
Order.SubItems(2) = Val(txtQuantity(j).Text) & "@" & Format sngprice(j), "Currency")
Order.SubItems(3) = cboSubject.Text

0
 
LVL 2

Expert Comment

by:shchuka
Comment Utility
mcix's comment should help you with the first question - I've been doing this, and it works just fine.

For the second question, can you explain a little more on what these subroutines are?  Where are they defined?  In a .bas file or in the form or where?  You say, they are in when you load the file.  "They" means these functions themselves or the calls to them?
0
 
LVL 2

Expert Comment

by:kswinney
Comment Utility
Amy420, the subitems collection is a property of the original "Order" item you added.

Try this:

Do While j < 8
    If chksize(j).Value= 1 Then
        Set Order = lvOrder.ListItems.Add(, ,cboNumber.Text)
        Order.SubItems(1) = strsize(j)
        Order.SubItems(2) = Val(txtQuantity(j).Text) & _
            "@" & Format(sngprice(j), "Currency")
        Order.SubItems(3) = cboSubject.Text
    End If
    j= j+1
Loop

0
 
LVL 2

Expert Comment

by:shchuka
Comment Utility
kswinney,

I think it's unethical to copy someone else's answer from a comment and lock it as your answer.  I hope amy420 will reject this answer, and will give the points to mcix.
0
 

Author Comment

by:amy420
Comment Utility
Mcix answered it

0
 

Author Comment

by:amy420
Comment Utility
I load a file named prices.txt and in this there are two columns, the first column is named sngprice and I named the second column strsize, that is it.  They are loaded and sitting somewhere until I access them.  I am trying to access them in the procedure to load listview, but since I do not define them in this procedure, I get an error so .......... Does that help at all????
0
 
LVL 2

Expert Comment

by:shchuka
Comment Utility
Ok, so those two "functions" are not really functions.  What do you mean by "Loading the file" with two columns?  Can you describe or post your code on how you load the file and store its contents in memory?
0
 
LVL 4

Expert Comment

by:mcix
Comment Utility
Amy,

Post your code that loads them from the file into the array...


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:kswinney
Comment Utility
Before you accuse someone of being unethical, you might entertain the notion that it was a simple mistake.

Aside from being the most ethical person I know, I genuinely try to help these people... rather than getting on here begging for points.
0
 

Author Comment

by:amy420
Comment Utility
Here is the code that loads them from the file into the array:

Private Sub Load_Prices()
Dim sngprice(1 To 8) As Integer, strsize(1 To 8) As String
Dim j As Integer
Open App.Path & "\Price.Txt" For Input As #2

Do While Not EOF(2)
For j = 1 To 8
Input #2, sngprice(j), strsize(j)
Next
Loop

Close #1
End Sub

How do I use sngprice and strsize in another procedure??
0
 

Author Comment

by:amy420
Comment Utility
Here is the code that loads them from the file into the array:

Private Sub Load_Prices()
Dim sngprice(1 To 8) As Integer, strsize(1 To 8) As String
Dim j As Integer
Open App.Path & "\Price.Txt" For Input As #2

Do While Not EOF(2)
For j = 1 To 8
Input #2, sngprice(j), strsize(j)
Next
Loop

Close #1
End Sub

How do I use sngprice and strsize in another procedure??
0
 
LVL 1

Expert Comment

by:wford
Comment Utility
YOu can declare these arrays at the form or global level in which case you can access them anywhere.

you may also want to check that you do not have j = 0 in your listview loader, since these two are declared as 1 to 8, thus 0 will be out of bounds.

To declare at the form level, place the Dim statments at the top of your code in the declare area of the form code, or for global, but them in a module with the keword Global in place of dim

0
 
LVL 2

Expert Comment

by:shchuka
Comment Utility
Kswinney,
I apologize if I affended you, but it just looked a little strange to me:  Here I am reading the question and a comment, a second later I reload the page - and I see someone else's answer basically copying the above comment...

Amy420, as wford pointed out, you should declare these arrays in the form's Declare section or with 'global' keyword in a module.  This should do the trick.
0
 
LVL 4

Expert Comment

by:mcix
Comment Utility
As mentioned above, you need the variables defined with a global or Public scope.  

If you are using VB5, you can declare them as:

Public sngprice(1 To 8) As Integer
Public strsize(1 To 8) As String

This can be done in the Form Declaration(s) Section or
a Code Module.

In previous versions of VB, you would use Global in a Code Module.

If you are using VB5, it might be worth looking into developing a Class Module that encapsulates this logic for you.

If you can e-mail me a sample of your data file, I would be willing to help you accomplish that.

Let me know,

marko_justus@hotmail.com
0
 

Author Comment

by:amy420
Comment Utility
Thanks mcix, how do I give you these points, I have no option...
Amy
0
 
LVL 4

Accepted Solution

by:
mcix earned 50 total points
Comment Utility
Amy, I was glad to help...

Email me with any further problem @ mcix@geocities.com

Mark
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now