• Calculated name of variable (Any)

    Author
    Topic
    #430305

    Hi

    I have a timesheet macro that stores two sets of arrival and departure times for each day of the week then adds the lot up. The code is very repetitive. For example:

    	Sat1 = FormatForDialog("Sat1")
    	Sat2 = FormatForDialog("Sat2")
    	Sat3 = FormatForDialog("Sat3")
    	Sat4 = FormatForDialog("Sat4")
    	etc, etc

    Is there any way of referring to a variable by its calculated name? Something along the lines of:

    	For i = 1 to 4
    		"Sat" & i = FormatForDialog("Sat" & i)
    	Next i
    Viewing 0 reply threads
    Author
    Replies
    • #1004375

      The argument of FormatForDialog is a string, so you can use “Sat” & i there, but you cannot refer to a variable that way, but you could create an array:

      Dim Sat(1 To 7)
      Dim i As Integer
      For i = 1 To 7
      Sat(i) = FormatForDialog(“Sat” & i)
      Next i

    Viewing 0 reply threads
    Reply To: Calculated name of variable (Any)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: