Help with Listbox control

Hello Everyone,

Looking to get help with the Listbox control. I have a program that parses a text file, retrieving only lines that contain a certain string and place each line into a Listbox. After reviewing the data within the list box, I need to create a text file from the entire Listbox (Listbox will contain ~ 3000 lines of data) contents so it can be attached as an email attachment.

Thanks fort he help!

What part do you need help with?

[quote=14797:@Stephen Taylor]Hello Everyone,

Looking to get help with the Listbox control. I have a program that parses a text file, retrieving only lines that contain a certain string and place each line into a Listbox. After reviewing the data within the list box, I need to create a text file from the entire Listbox (Listbox will contain ~ 3000 lines of data) contents so it can be attached as an email attachment.

Thanks fot he help![/quote]

Assuming a single column with one line per row this will put the listbox contents into a string:
DiM theText as String = thelistbox.Cell(-1,-1)

You can then save that as textfile.

  • Karen

… following that I suggest you to increase speed of your computing in hiding the listbox when importing or adding huge amount of rows into listbox. Show a spinning wheel instead or another loading indicator. Dont forget to use the various pragma directives like the well known:

#if not DebugBuild then
  #pragma BackgroundTasks false
  #pragma BoundsChecking false
  #pragma NilObjectChecking false
  #pragma StackOverflowChecking false
#endif

when filling listbox with loops and recursions. And finally as best advise, dont put your code inside listbox methods, create your own methods and call them from listbox events. otherwise your code will repeat itself on different onkey, onmouse down and up events.

Could you give more information on this Tomas ?
I don’t really understand what’s the difference between code in the Event and the Event calling an external function.

There is none.

Also, at least on Windows, a progresswheel will not spin unless you put heavy processing code into a thread. But then you can’t load the listbox directly. You’d have to go the long way around and have the thread load an array and a timer move it from the array to the listbox. Not sure if that will be worth it to you just to get a progress indicator. It really depends on how long the process takes.

[quote=14817:@Tomas Jakobs]… following that I suggest you to increase speed of your computing in hiding the listbox when importing or adding huge amount of rows into listbox. Show a spinning wheel instead or another loading indicator. Dont forget to use the various pragma directives like the well known:

#if not DebugBuild then
  #pragma BackgroundTasks false
  #pragma BoundsChecking false
  #pragma NilObjectChecking false
  #pragma StackOverflowChecking false
#endif

when filling listbox with loops and recursions. And finally as best advise, dont put your code inside listbox methods, create your own methods and call them from listbox events. otherwise your code will repeat itself on different onkey, onmouse down and up events.[/quote]
I have a method in a module that does this for me, i just call “BackgroundCodeOFF”
It’s simple to add it to the top of the code…

[quote=14917:@Derk Jochems]I have a method in a module that does this for me, i just call “BackgroundCodeOFF”
It’s simple to add it to the top of the code…[/quote]
Does this really work as you expect it to do? I was always under the impression that #pragma-directives are interpreted at compile time by the compiler and thus changing it’s behaviour. I.e. when the compiler encounters “#pragma BoundsChecking false”, it simply stops generating bounds checking code. But it does not actually insert any code (that could be called from elsewhere) that does anything at runtime.

So my idea here would be, your method “BackgroundCodeOFF” would have all checks disabled … but would do nothing else and the rest of your code would still have the generated checking stuff in it.

Yes, pragmas are local to the scope they are declared in. Most pragmas are also just a hint to the compiler, which is free to ignore them if it feels like it. For example, DisableAutoWaitCursor has done nothing for years.

[quote=14888:@JrmieLeroy]Could you give more information on this Tomas ?
I don’t really understand what’s the difference between code in the Event and the Event calling an external function.
[/quote]

In execution time or performance there might be no difference on this, but from developers’ point of view it helps you to keep your code clean and you don’t repeat yourself with same loops or cycles through a listbox in x different events (getting row/cell in MouseUp and MouseDown events for instance).

When conducting I/O operations to files or Databases I’ve found out that on Mac everything was smooth and ran perfectly. But on WIndows I had to split my algoritm because of unknown file I/O or TCP/IP port limitation of Windows (Too Many open TCP ports to remote mySQL Server). So I coulnd’t do this on every single line:

  1. read single line from file and parse it
  2. insert line into listbox
  3. insert current listbox row into database with (multiple) SQL Queries and Transactions

I’ve had to modify my aloritm into these steps:

  1. read and parse all lines into listbox
  2. take the first 100 rows and insert them into database
  3. repeat step 2. with the next 100 rows until .LastRow

So in kinda way I “misused” a listbox as huge cache for importing stuff.
Here a small video clip of this software: http://vimeo.com/42614080
It helps the client to mass calculate prices and rebates for his products (>200.000) due to Doller-Euro exchange rates in his ERP software.

That worked perfect Karen, thanks for the help. Thanks for the advice Thomas, I will look into your suggestion.

[quote=14980:@Tomas Jakobs]1. read and parse all lines into listbox
2. take the first 100 rows and insert them into database
3. repeat step 2. with the next 100 rows until .LastRow
[/quote]
Hmmm, which would be “better” - loading the rows into the listbox (hidden, I assume) or creating an array? My seat of the pants feeling is that an array would be both faster and more memory efficient.

Other thoughts?

[quote=15191:@Tim Jones]Hmmm, which would be “better” - loading the rows into the listbox (hidden, I assume) or creating an array? My seat of the pants feeling is that an array would be both faster and more memory efficient.
Other thoughts?
[/quote]

Good point! Would be interesting to know if a listbox (kinda array of cells and rows) is faster than a 2-dimensioned Array. But I guess an array won’t be more memory efficient. I am already using the listbox for data presentation, why should I utilize additional memory for an array then?