Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
[help]it's a problem about multithread in vba

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
floydd
Just In
Just In


Joined: 02 Jul 2004
Posts: 1

Post Post subject: [help]it's a problem about multithread in vba Reply with quote

------------------begin macro-----------------------
'btnconfirm is a button on the user interface
Private Sub btnConfirm_Click()
'run the process of analyzing in a new thread
Dim tId As Long, hThread As Long
hThread = CreateThreadL(0, 0, AddressOf DurativeFunc, 0, 0, tId)
End Sub

'the following is parts of module1

Declare Function CreateThreadL Lib "kernel32" Alias "CreateThread" _
(ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress

As Long, _
ByVal lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As

Long

Function DurativeFunc(ByVal lpvThreadParm As Long) As Long
Dim dwResult As Long
dwResult = 0

'problem:
'the following process(in fact it's a timeconsuming process,here just simplified)

work well in a non-multithread function
'but here(as a multithread function) it only modify the content of cells(1,3)
'why???
For i = 1 To 10
ActiveSheet.Cells(i, 3) = i
Next

DurativeFunc = dwResult
End Function
------------------------end macro---------------------
i just want to update the user interface(informing user of what's going on),when a

time-consuming process is running.

anyway if anyone gets time to help i would be very happy.
any other method to solve the problem is appreciated.
Sat Jul 03, 04 9:40 am
Back to top
floydd View user's profile Send private message
dude
Power User
Power User


Joined: 10 Mar 2004
Posts: 376
Location: Savar, Dhaka

Post Post subject: Reply with quote

This is something that DK can answer. Where is DK when one needs him?
Tue Jul 06, 04 6:59 am
Back to top
dude View user's profile Send private message Visit poster's website
dinangkur
Super Moderator
Super Moderator


Joined: 24 Mar 2004
Posts: 491
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

According to your information, in non-multi environment it works fine. That's mean it's a sequential process. You didn't provide much of the code to check. So, I assume that all the cell information is not provided at same time from you function, so It just updates the first cell. Try to debug it step by step, you will find the problem. Also check the process ID that the thread creates and also termination thread code. Multi threaded is needed if you update large amount of data at once, otherwise sequential process is good regarding to today's PC.

Please post more code, so we can test the program and find the bug. Thanks.

-DK.
_________________
...we too are stardust...
Tue Jul 06, 04 11:24 pm
Back to top
dinangkur View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group