Switch Argument = Field
Switch Argument = Field
(OP)
I am working on a switch function that checks the value in some fields and depending on the current value, it prints a new value.
I hope that this shows what I am trying to accomplish.
The problem here is getting the function to excecute with a field of my choice as the argument.
If this is not possible, then if saving the value from a specific field into a variable and use the variable instead.
CODE
Start Sub
field = Range("L14")
ActiveCell.FormulaR1C1 = Tålamod(field)
End Sub
Function Tålamod(Resultat As Integer)
Tålamod = Switch(Resultat = "9", "70", Resultat = "10", "73", Resultat = "11", "76", Resultat = "12", "79", Resultat = "13", "82", Resultat = "14", "85", Resultat = "15", "88", Resultat = "16", "92", Resultat = "17", "95", Resultat = "18", "98")
End Function
field = Range("L14")
ActiveCell.FormulaR1C1 = Tålamod(field)
End Sub
Function Tålamod(Resultat As Integer)
Tålamod = Switch(Resultat = "9", "70", Resultat = "10", "73", Resultat = "11", "76", Resultat = "12", "79", Resultat = "13", "82", Resultat = "14", "85", Resultat = "15", "88", Resultat = "16", "92", Resultat = "17", "95", Resultat = "18", "98")
End Function
The problem here is getting the function to excecute with a field of my choice as the argument.
If this is not possible, then if saving the value from a specific field into a variable and use the variable instead.





RE: Switch Argument = Field
CODE
const ixcmp = 0, ixval=1, ixmax=2
dim lut, ix
lut = array ("9", "70", "10", "73", "11", "76", "12", "79", "13", "82", "14", "85", "15", "88", "16", "92", "17", "95", "18", "98")
for ix = 0 to ubound(lut) step ixmax
if Resultat = lut(ix + ixcmp) then
xxx = lut(ix + ixval)
exit for
end if
next
End Function