Results 1 to 19 of 19

Thread: ListBox1.ListCount Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    Question ListBox1.ListCount Question

    hello,

    i'm semi familiar with vb6 and the function of sending all my information in a listbox to the clipboard but i just cannot get it to work properly in vb.net. here is my code:

    Dim x As Integer
    x = ListBox1.ListCount
    For x = 0 To (ListBox1.ListCount - 1)
    If ListBox1.ListCount (x) = True Then GenerateText = GenerateText & ListBox1.List (x) & vbCrLf
    Next
    GenerateText = GenerateText & "" & vbCrLf
    GenerateText = GenerateText & Text1.Text

    It states

    'ListCount' is not a member of 'System.Windows.Form.ListBox'

    'List' is not a member of 'System.Windows.Form.ListBox'

    as well as

    'Text1' is not declared'

    can someone shed some light on this for me ...much appreciated.


    - justin

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You would have to use Items collection of the ListBox class:

    ListBox1.Items.Count

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    yay

    ok that fixed the first part of them not working but now the rest shows as following:

    For x = 0 To (ListBox1.Items.Count - 1)
    If ListBox1.Items.Count (x) = True Then GenerateText = GenerateText & ListBox1.Items.Count (x) & vbCrLf
    Next
    GenerateText = GenerateText & "" & vbCrLf
    GenerateText = GenerateText & Text1.Text
    End Function


    when i hover over the items in green it states:

    'Public Overridable Overloads ReadOnly Property Count() As Integer' has no parameters and its return cannot be indexed'

    oh and Text1 still is not 'declared'.

    thanks again! this forum is great.

    - justin

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You can't refer to an item by the count property. You're doing this:
    ListBox1.Items.Count(x)
    where you should be refering to the items collection itself:
    ListBox1.Items(x)

    Try this:
    Code:
    For x = 0 To (ListBox1.Items.Count - 1)
    If ListBox1.Items(x) = True Then GenerateText = GenerateText & ListBox1.Items (x) & vbCrLf
    Next
    GenerateText = GenerateText & "" & vbCrLf
    GenerateText = GenerateText & Text1.Text
    End Function

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Just a note if you are adding text to a variable you can use this shortcut:

    GenerateText &= Text1.Text

    Instead of:

    GenerateText = GenerateText & Text1.Text

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    hmm

    ok i am slowly but surely getting it i think ...thanks for being patient...but i still get the

    'Text1 is not declared'

    ...what am i missing? thanks a lot!



    - justin

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Text1 should be a textbox control on your form. If you renamed it, then you will need to change the Text1 to whatever you named it.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    more fun..

    once again thanks for the responses folks..you been great...another thing thats boggling my little brain..

    Private Sub Button1_Click()
    Dim data As String
    data = GenerateText()
    Clipboard.Clear()
    Clipboard.SetText(data)
    MsgBox("Data copied to clipboard. ", vbInformation + vbOKOnly, "Task Done")

    End Sub



    after the code i've pasted earlier is now straightened out..here is the following that i'm trying to get to work in vb .net that i was using in vb6. i tried to change the clipboard.clear to:

    Clipboard.GetDataObject()
    Clipboard.SetDataObject()


    i think i'm a little screwed up still..any info would help mucho


    justin

  9. #9
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You know that you can open a VB6 project in .Net, and the upgrade wizard will start. It will try to convert your old VB6 code to VB.Net code. Works pretty well, but it won't get everything.

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    Thumbs down hmm

    i tried but i only have vb .net standard not professional so it says i'm not cool enough to use it (jk) it says my version doesn't support it.

    - justin

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    hmmm...

    any ideas? sorry to keep buggin.

    justin

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    In this case I don't think you need to clear the clipboard because the old value will be reset to the new one.

  13. #13
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    http://msdn.microsoft.com/library/de...albasicnet.asp
    or
    http://msdn.microsoft.com/library/de...eclipboard.asp
    or
    http://msdn.microsoft.com/library/de...mbersTopic.asp

    I am not sure what your asking about the clipboard, but those three links should get you all the information you need to deal with the clipboard. If your still having problems, post the code, where the error is, what you are trying to do, and I will see if I can help you further.

  14. #14

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13

    hmm..

    yup, i've been looking on msdn...thanks for the help and links..i'll try to get that part hammered out.

    my next task is going to be pulling from a sql database on an interval and caching the db information locally in a file somehow so if network connectivity gets lost the tool will still be functional....does this sound feasable to the rest of you? like basically when i create the installer it has no content, then once you make the sql db connection for the first time it creates a local file and caches it and then checkes every 5 hours for an update or i can push them out and force updates? does this seem possibe....or am i going to have a go back to the drawing board?

    thanks!

    justin

  15. #15
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    It seems possible, but is the app going to be running continuously?

    If not, I would just make a seperate thread to pull the data from the server, and start that thread on each startup. This way it won't affect performance of the app because it will do it in the background.

    I am sure there are many, many ways to do this, and DB's really aren't my strongest of skills. I am sure someone else will have a better idea.

  16. #16
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Originally posted by hellswraith
    Text1 should be a textbox control on your form. If you renamed it, then you will need to change the Text1 to whatever you named it.
    Point of interest on that. In VB6 a textbox default name was Text1.

    In .Net it is TextBox1
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  17. #17

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13
    yes, basically what the app is going to do is be deployed to many users and there will be a back end web server with forms for me to submit the database updates with.

    when i make changes i want them to eventually get out to everyone...so i want to put a time interval on it to hit the web server where the sql server resides every few hours AND have an option to force an update ...


    if i did it on launch of the app that might work..but what about the force of an update? is that possible?


    - justin

  18. #18

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    13
    cander,

    thanks...sometimes i overlook really easy stuff and i'm thankful for people like you to show me the way...appreciate it.


    justin

  19. #19
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    if i did it on launch of the app that might work..but what about the force of an update? is that possible?
    Just have a button that updates it. Then just do the same thing you did on startup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width