Solved

Listviews and keeping info on same line

Posted on 1998-10-12
16
185 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
ID: 1439456
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
ID: 1439457
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
ID: 1439458
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:shchuka
ID: 1439459
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
ID: 1439460
Mcix answered it

0
 

Author Comment

by:amy420
ID: 1439461
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
ID: 1439462
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
ID: 1439463
Amy,

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


0
 
LVL 2

Expert Comment

by:kswinney
ID: 1439464
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
ID: 1439465
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
ID: 1439466
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
ID: 1439467
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
ID: 1439468
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
ID: 1439469
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
ID: 1439470
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
ID: 1439471
Amy, I was glad to help...

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

Mark
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

831 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