I am a NewBie to VBA with Excel, can guide me in implementing Multithreading in VBA, I guess VBA with Excel will support Multithreading any samples wld be of great help.
thanks in advance
venky
I am a NewBie to VBA with Excel, can guide me in implementing Multithreading in VBA, I guess VBA with Excel will support Multithreading any samples wld be of great help.
thanks in advance
venky
Hi venky,
I've taken the liberty of moving your post to the excel Help forum, where you may possibly have more chance of getting a response to your question
Regards,
John
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
VBA doesn't support multi-threading.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
hi Jhon,Originally Posted by johnske
Thanx, hope to get some help thr...anyhow i did solved it using the timer method, hope to get more other than Timers...
venky
Thnx i did tried solving the requirement with Timers but hope to get some other techniques than timersOriginally Posted by xld
venky
Can you point me to somewhere that documents this please? I have never done it but I don't see why the CreateThread API call cannot be used.Originally Posted by xld
The Timer, in effect, creates a separate thread. So what is it about multithreading that VBA doesn't support?
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Tony, VBA/VB supports objects in both single threaded and apartment models.
In my endeavours to try new or perhaps impossible things within VBA I some times neglect
the fact that"just because you can, then you should" .... sometimes you need to take stock
of what it is you are doing it for.
The API call CreateThread is one such API call that you really need to be aware of what you are doing!
Just because you can do it, doesn't in this case mean you should. ( I have been guilty of this )
Don't forget that @ the CPU register level (low level machine language) it is the CPU that handles
(by quickly swapping register value, instruction pointers and stack pointers) to give you the
appearance of mutlitasking without interfering with each other. Each process consists of a virtual
address space that includes executable instructions, a set of resources such as file handles,
and one or more threads that execute within its address space. Typical applications consist
of only one process, so program and process are often used synonymously. Why do I mention this?
because OS handle this differently eg NT schedules this .. the Win32 API defines four priority classes:
realtime, high, normal, and idle. These names correspond to priority levels 24, 13, 8, and 4.
Setting a process priority class causes all the threads of that process to begin executing at
priorities within ?2 of the class priority. One of the scheduler's jobs is to assign units of
CPU time (quantums) to threads. There really is a lot happening @ this level, better to let the
OS handle it, BUT if you do then you need to know about COMs (COMs is complex enought)
and it's underlying rules. Most people think first of the interface part of the COMS rules ie the methods
and properties that an object exposes. But it also defines THREADING as part of its rules, and like
any part of the COMs rules if you break it, you can get into very deep trouble.
The programer will need to know of the 3 threading models AND code appropriately so as to
adhere STRICTLY to the threading requirements of each object that it creates.
If you break the COM rules, you are no longer protected by those features in COM
that allow objects to successfully communicate (Interface) with each other and with clients.
If you must use that API then you MUST adhere to the COMs rules.
There are a number of OLE.dll calls to do to get this right, most of these are interface calls
CoMarshalInterThreadInterfaceInStream
CoInitialize
CoUninitialize, you will need an interface identifier
IDispatch interface (interface for dispatching, you will see this a lot for COM and C++ as it
is a std call)
CoGetInterfaceAndReleaseStream (you need to create a proxy object to represent your
new object)
Kind Regards,
Ivan F Moala From the City of Sails