Improve company productivity with a Business Account.Sign Up

x
?
Solved

Listviews and keeping info on same line

Posted on 1998-10-12
16
Medium Priority
?
191 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 200 total points
ID: 1439471
Amy, I was glad to help...

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

Mark
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

589 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