Results 1 to 20 of 20

Thread: OCX - Gurus

  1. #1

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    I try to create a OCX that contain a listbox - and i want to insert a lot of records to a listbox in design time, to save the Additem step in the listbox, also to eliminate the need of external file to be inserted to the Listbox. Is there a quick way to achive that? Is there a limit at design time, eto enter the values in to the list property of the list box? I try the 'Cut' and 'Paste" and i canot move over 1200 item, any idea?
    Regards

  2. #2
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    i think additem and adding it in list time takes up about the same time
    YC Sim
    Teenage Programmer
    UIN 37903254



  3. #3

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    What is the different between UserControl_InitProperties and UserControl_Initialize ?
    Regards

  4. #4
    Guest
    From MSDN:

    This event allows the author of the object to initialize a new instance of the object. This event occurs only when a new instance of an object is being created; this is to allow the author of the object to distinguish between creating a new instance of the object and loading an old instance of the object.
    By putting in code to initialize new instances in the InitProperties event rather than the Initialize event, the author can avoid cases where loading data through a ReadProperties event into an old instance of the object will undo the initialization of the object.

  5. #5

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Thanks,
    BTW - the limit for listbox item is - 1200 at design time and 32766 item in run time.

    Thanks again

  6. #6

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    I want to fill a Listbox eith a 30000 lines of text and i want to use the List1.ItemData. Is it another index ? how can i find a list1.list(item) with specifid Itemdata?
    My Itemdata is 6581091 and i like to extract the list1.listindex of it.
    Regards

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ItemData is an array of numeric values that can be used as secondary values not shown in the list. You use the Itemdata property as you use List property
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    kedaman,
    I have a ItemData - 2784573 - how can i know what is the text (List1.item or list) related to that ItemDdata?

    Regards

  9. #9
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    Walk thru all the items in a loop eg.
    Code:
    For i = 0 To List1.ListCount - 1
        If List1.ItemData(i) = <the one i was looking for> Then
            MsgBox List1.List(i)
        End If
    Next 'i
    Hope this helps

    Crazy D

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    That's a way to find out, but why did you lost the index in the first place if you got that value?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    kedaman,
    I did not lost the index in the first place, I have a list of records and i want to extract a part of the record to the Listbox, and sort the Text - But - i want to be able to locate a line from the sotrted Listbox by the uniq (unsorted) number thet i have with the record, How can i do it?
    Regards

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess you would just have to search for it, using Crazy D's method
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    When i add my ocx to a form its start to read the input file and insert the record to a Listbox, and when i Run my project its start to read the file again and start all over again, Why is that? how can i prevent the read of file in the design time (put the ocx on form)? how can i pass a filename to a ocx to refresh the file?
    Regards

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Inside the usercontrol you can use the readonly ambient.usermode property to determine if it is not in designmode:
    Code:
    If UserControl.Ambient.UserMode Then
      'Read file
    End if
    I'm not sure in which way you want to pass the filename, either you should make a method in the usercontrol or store it in a module while notifying it another way, that's up to you
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    kedaman,
    I put the code in the UserControl_Initialize() and i got
    "Run-time error '398'
    Client site not available.
    ???

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hmm, that's because the object hasn't been created yet, you would have to put it in another event that fires after initialization:
    Code:
    Private Sub UserControl_Resize()
        Static Running As Boolean
        If Running = False Then
            If UserControl.Ambient.UserMode Then
            End If
            Running = True
        End If
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  17. #17

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Thanks, i'll try it imm..

  18. #18
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Talking A cheap method?

    If I got it correctly, you want to assign a long set of data to a list box prior to execution. My suggestion would be parse the data set with Excel and convert the raw data to assignment statements, so that any variable or constant arrays of desired size, could be loaded but would be embedded in code. Such as;

    Field1 Field2
    ------ ------
    data11 data21
    data12 data22
    data13 data23

    would be;

    field1(1) = data11
    field2(1) = data21
    field1(2) = data12

    .. and so on..

    I could have misintrepeted your problem, though.

    Good Luck!

    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

  19. #19

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    Yes i want to assign a long set of data to a list box prior to execution, BUT as u c i have some problem with it, 1st when i add the ocx on a form - its start to load the file, 2nd when i run the project its start all over again, 3rd when i stop the project (surprise) its start again...
    Well can u be more specific?

  20. #20
    Lively Member
    Join Date
    Jul 2000
    Posts
    70

    Talking My trick is not to use an OCX at all!

    Suggest that you have a single-table database. Convert it to csv (comma seperated values) format.
    Open it with excel, and using either worksheet function or VBA coding, generate code strings which would assign data values into items of an array in VB. Like this;

    Under Excel your dataset looks like this:

    A B C
    1 ID Name Surname
    2 1 Matthew Gibbs
    3 2 Sean Connery
    4 3 Robert Palmer
    5 4 And So On

    Now Convert data to code string via Column D :
    D
    1 VBCode
    2 ="ID("&(ROW()-1)&")="&A1&":Name("&(ROW()-1)&")="&chr(34)&B1&chr(34)&":Surname("&(ROW()-1)&")="&chr(34)&C1&chr(34)
    3 ="ID("&(ROW()-1)&")="&A2&":Name("&(ROW()-1)&")="&chr(34)&B2&chr(34)&":Surname("&(ROW()-1)&")="&chr(34)&C2&chr(34)
    4 ...
    5 ...

    These formula will show:
    D
    1 VBCode
    2 ID(1)=1:Name(1)="Matthew":Surname(1)="Gibbs"
    3 ID(2)=2:Name(2)="Sean":Surname(2)="Connery"

    Now copy the stuff on the column D from Row2 to the end. Paste it into your module in VB. Now you have a code that assigns your dataset to 3 arrays. Just declare them:

    Dim ID(1 To X) As Integer
    Dim Name(1 To X) As String, _
    Surname(1 To X) As String

    Do whatever you want with these arrays, assign to Listboxes or anything...

    As you have - it seems - a long list of items, I would advice this code stuff be in a seperate module. As you compile, you'll have all the stuff embedded in your main exe.

    I hope, I helped..
    Kiziltan Yuceil
    Freelance Web/VB/VBA Programmer
    "It's not what you know it's to whom you consult and with whom you collaborate"

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