PDA

View Full Version : Help with Function



mcmichael13
04-27-2009, 10:57 AM
ok so I have a request from my boss... I suggested some other methods to do this but he wanted to know if it was possible to do it in the way i'm about to desribe:

Background:
We have a spread sheet with test data that are put onto plots. the spreadsheet uses a graph, and PIP to show which "bin" each of the tested parts fall into. However, he wants to combine all the tested parts into one spreadsheet.

Now the function is defined for the particular part tested. He was curious as to whether the actual name of the function could be a variable

i.e.

Function SoL_bin_D2(u, v)

if "SoL_bin_D2" could change so that the code would run based on the part number, and the function would also be defined under this part number.

I suggested If statements that would just encapsulate the entirety of the function but he doesnt want that for ease of future manipulation.

Any suggestions?

Please ask if you need any more info. Thanks.

mdmackillop
04-27-2009, 11:11 AM
If you mean

Test = Sol_bin_ & MyPart(u,v)

I don't think you can do this.

BTW, you might want to use Select Case rather than multipe IF statements, if you need to go down that road.

mcmichael13
04-27-2009, 11:22 AM
yeah i didnt think it was possible either. but i figured i would ask anyway, thanks

Cosmo
04-27-2009, 11:41 AM
You may be able to use CallByName, but I believe the function that you are calling needs to be in a class or userForm module for this.

Paul_Hossler
04-27-2009, 12:58 PM
You can pass the part number to a driver sub, which would then .Run a sub based on the passed part number


Option Explicit

Sub Drv()
Call SubDrv("1", "11111111111111111")
Call SubDrv("2", "22222222222222222")
Call SubDrv("3", "33333333333333333")
End Sub

Sub SubDrv(ByRef p As String, ByRef s As String)
Call Application.Run("SubName" & p, s)
End Sub

Sub SubName1(s As String)
MsgBox "Sub 1 " & s
End Sub
Sub SubName2(s As String)
MsgBox "Sub 2 " & s
End Sub
Sub SubName3(s As String)
MsgBox "Sub 3 " & s
End Sub



Might be able to simplfy this a bit

Paul