[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Listviews and keeping info on same line

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
amy420
Asked:
amy420
  • 5
  • 4
  • 4
  • +2
1 Solution
 
mcixCommented:
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
 
shchukaCommented:
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
 
kswinneyCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
shchukaCommented:
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
 
amy420Author Commented:
Mcix answered it

0
 
amy420Author Commented:
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
 
shchukaCommented:
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
 
mcixCommented:
Amy,

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


0
 
kswinneyCommented:
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
 
amy420Author Commented:
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
 
amy420Author Commented:
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
 
wfordCommented:
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
 
shchukaCommented:
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
 
mcixCommented:
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
 
amy420Author Commented:
Thanks mcix, how do I give you these points, I have no option...
Amy
0
 
mcixCommented:
Amy, I was glad to help...

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

Mark
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now