Using 'i' to calculate public variables

B

baptism by fire

If anyone can help me out:

I've written some code that uses public variables and the values transfer
fine from one sub to the next when placed in sequence. But for some reason I
can't get a set of variables to transfer to another sub when I perform
calculations were I'm selecting the variable name with the 'i' variable.

I'm going to past in the variables declared and the sub that's not working
properly. Could a more knowledgeable person tell me what's breaking down?
Thank you.

Public Row_Constant As Integer
Public Spacer As Integer
Public Stores_Per_Graph_1 As String
Public Stores_Per_Graph_2 As String
Public Stores_Per_Graph_3 As String
Public Stores_Per_Graph_4 As String
Public Number_of_Graphs As String
Public Store_Count As Integer
Public i As Integer

Sub GET_STORES_PER_GRAPH()

Number_of_Graphs = 2
Store_Count = 29

Dim a As Integer
Dim Stores_Used As Integer

a = 0
i = 1

MsgBox ("This is " & Stores_Per_Graph_i)

Do

Stores_Per_Graph_i = Ceiling((Store_Count - Stores_Used) / (Number_of_Graphs
- a))
Stores_Used = Stores_Used + Stores_Per_Graph_i

MsgBox ("This is " & Stores_Per_Graph_i)

i = i + 1
a = a + 1
Loop Until (Number_of_Graphs - a) = 0

End Sub

Sub GET_STORES_PER_GRAPH_1 ()

MsgBox ("This is " & Stores_Per_Graph_i)

End Sub
 
T

Tim Williams

Variables don't work that way. Maybe you want an array?

'*****************************
Option Explicit

Public Stores_Per_Graph(1 To 4) As String

Sub Tester()
Dim i As Integer

For i = 1 To 4
Stores_Per_Graph(i) = i * 10
Next i

For i = 1 To 4
MsgBox "Value " & i & " = " & Stores_Per_Graph(i)

Next i

End Sub
'******************************

Tim
 
B

baptism by fire

Thank you. I tried to simplify my problem by isolating the code that was
giving me problems, but after you answered I realized that I hadn't included
everything to make that code function. At any rate, thank you - that works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top