0

I have three string variables, thisTemplateFrame1Type, hisTemplateFrame2Type, thisTemplateFrame3Type.

They hold values such as PVCV, ABS_Var etc.

I have a loop that goes through these 3 (but n as it can be 1 to 3) variables and then based on a Select Case I want it to do things.

Example:

for i = 1 to {defined number of Frames}
   Select Case thisTemplateFrame1Type
      Case Is = "PVCV"
         [do stuff]
...
   End Select
Next i

Now this is tedious.

What I need instead is something like:

for i = 1 to {defined number of Frames}
   Select Case CStr("thisTemplateFrame" & meFrameCounter & "Type") 
  'this above should evaluate to say thisTemplateFrame1Type, thisTemplateFrame2Type...
      Case Is = "PVCV"
         [do stuff]
...
   End Select
Next i

That solution doesn't work because CStr("thisTemplateFrame" & meFrameCounter & "Type") always equals thisTemplateFrame1Type as a value but that basically means thisTemplateFrame1Type <> PVCV so the Case block moves on.

How do I pass the value properly?

1 Answer 1

2

You cannot dynamically construct variable names in that way. You can however reframe (boom boom) your structure and loop an array of frames

Option Explicit
Public Sub test()
    Dim frames(), frame As Variant, thisTemplateFrame1Type As String, thisTemplateFrame2Type As String, thisTemplateFrame3Type As String
    thisTemplateFrame1Type = "A"
    thisTemplateFrame2Type = "B"
    thisTemplateFrame3Type = "C"

    frames = Array(thisTemplateFrame1Type, thisTemplateFrame2Type, thisTemplateFrame3Type)

    For frame = LBound(frames) To UBound(frames)

        Select Case frames(frame)
        Case "A"

        Case "B"

        Case "C"
        End Select

    Next
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.