Call a sub in a modeless userform from a code module?

F

fedude

I have a long calculation and I created a userform (CHandicaps) with a
progress-bar. In CHandicaps, I created a routing to update the progress bar
(UpdateProgress).

So when my calculation begins, I show the userform:

CHandicaps.Show vbModeless

Now during the long calculation, I want to call the UpdateProgress function
in the userform.

This seems simple, but I've been banging around with this for a long time
and cannot get my head around how to interact with a form "from a module".
Color me lost....

Do I need to pull the UpdateProgress code out of the userform and put it in
my calculation? If so how do I reference a field in the userform?

Any help would be appreciated..
 
R

r

'Userform class module
'Userform1 with ScrollBar1
Option Explicit

Private Sub UserForm_Initialize()
Me.ScrollBar1.Min = 0
Me.ScrollBar1.Max = m
End Sub


'standard module
Option Explicit

Public m As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub Test()
Dim lTop As Long, i As Long
lTop = 100
m = lTop
UserForm1.Show vbModeless

For i = 0 To lTop
addOne i
'...
Sleep 100
DoEvents
'...
Next

Unload UserForm1
End Sub

Sub addOne(i As Long)
UserForm1.ScrollBar1.Value = i
End Sub

regards
r
 
F

fedude

Thanks Leith. That did the trick.

I was all good with what you wrote except for the fact that my sub was
private. Your comment about the sub being "visible" triggered me to remove
the "Private" from the sub and voila.....Success.

Thanks!
 
F

fedude

Thanks r,

When I saw your sub "addOne" was not private triggered me to remove the
private attribute and make it available. Voila, I was in business.

Thanks for the help!
 
F

fedude

Thanks r,

When I saw your sub "addOne" was not private triggered me to remove the
private attribute and make it available. Voila, I was in business.

Thanks for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top