PDA

View Full Version : Passing variables into a function



JRCross
10-19-2016, 05:20 PM
So I'm working on a UserForm to generate notes at the moment, and one thing I've been trying to do is create a function that, among other things, makes the next frame in the segment visible

I currently have this as the starter to my function


Private Function POROChange(cbo As ComboBox, PORO As ComboBox, poroLabel As label, Optional frameBox As frame)


Then I call the function in another sub


Private Sub cboOutcome1_Change()
POROChange cboOutcome1, cboPORO1, POROLabel1, frameOut2

When I don't include the parameter for frame it works fine, but as soon as I include the parameter for frame it gives a type mismatch error 13

What am I doing wrong?

gmaxey
10-19-2016, 05:48 PM
Try frameBox as Object

JRCross
10-19-2016, 05:58 PM
That did the job, thanks!

The next part I'm working on is also in regards to the frame, and I'm sure I'm just using the wrong terminology here, but I'm not sure what it's meant to be


Private Function POROChange(cbo As ComboBox, PORO As ComboBox, poroLabel As label, Optional frameBox As Object)
.
.
.
If frameBox <> Null Then
frameBox.Visible = False
End If


Basically if there is a frame (or object) passed as frameBox then it makes the frame visible (or invisible as necessary), but if there is no frame passed then it ignores the frame aspect of the code

gmaxey
10-19-2016, 06:08 PM
Function Test(Optional oF As Object = Nothing)
If Not oF Is Nothing Then
oF.Visible = True
End If
End Function

JRCross
10-19-2016, 06:40 PM
It works!!

Thanks so much

I've still got a lot to work on this project so if I need more help I'll make a new thread, but I think I'm good for now on this part

Thanks again!