?
Solved

Listviews and keeping info on same line

Posted on 1998-10-12
16
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 total points
ID: 1439471
Amy, I was glad to help...

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

Mark
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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