Compound variable ??

C

Canblue

I have a DB with elements like C1AM, C2AM..C10AM, all integers. In other
languages I can concatenate a counter to step through the data items i.e.
C || counter || AM to cycle through the variables. Is there a way in VB6 to
do something similar? I was not looking at an array but if I have to go
there then so be it.

do I = 1 to 10
a = a + C || I || AM
end
 
M

macropod

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name. For example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub
 
C

Canblue

I tried that and it does not work as expected. The variables, C1AM, C2AM
etc. has integer. I want to calculate the average of the values. The number
of elements ranges from 12 to 18 then 24. Looking for a blackbox.
How can I step through the DB items.

macropod said:
Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name. For example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Canblue said:
I have a DB with elements like C1AM, C2AM..C10AM, all integers. In other
languages I can concatenate a counter to step through the data items i.e.
C || counter || AM to cycle through the variables. Is there a way in VB6 to
do something similar? I was not looking at an array but if I have to go
there then so be it.

do I = 1 to 10
a = a + C || I || AM
end
 
M

macropod

Hi Canblue,

What is happening that isn't as expected? How are you accessing the variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


Canblue said:
I tried that and it does not work as expected. The variables, C1AM, C2AM
etc. has integer. I want to calculate the average of the values. The number
of elements ranges from 12 to 18 then 24. Looking for a blackbox.
How can I step through the DB items.

macropod said:
Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name. For example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Canblue said:
I have a DB with elements like C1AM, C2AM..C10AM, all integers. In other
languages I can concatenate a counter to step through the data items i.e.
C || counter || AM to cycle through the variables. Is there a way in VB6 to
do something similar? I was not looking at an array but if I have to go
there then so be it.

do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he wants,
the OP has to use the variable name generated by the "A" & i & "B" to get
the value from the database for each field that is represented by a variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

macropod said:
Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


Canblue said:
I tried that and it does not work as expected. The variables, C1AM, C2AM
etc. has integer. I want to calculate the average of the values. The
number of elements ranges from 12 to 18 then 24. Looking for a blackbox.
How can I step through the DB items.

macropod said:
Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name. For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers. In
other languages I can concatenate a counter to step through the data
items i.e.
C || counter || AM to cycle through the variables. Is there a way in
VB6 to do something similar? I was not looking at an array but if I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
C

Canblue

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the community
provide me with an example of what you mean by DB.Fiedls suitable command?

I need a point of reference to proceed.

Thanks.

Doug Robbins - Word MVP said:
While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he wants,
the OP has to use the variable name generated by the "A" & i & "B" to get
the value from the database for each field that is represented by a variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

macropod said:
Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


Canblue said:
I tried that and it does not work as expected. The variables, C1AM, C2AM
etc. has integer. I want to calculate the average of the values. The
number of elements ranges from 12 to 18 then 24. Looking for a blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name. For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers. In
other languages I can concatenate a counter to step through the data
items i.e.
C || counter || AM to cycle through the variables. Is there a way in
VB6 to do something similar? I was not looking at an array but if I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the community
provide me with an example of what you mean by DB.Fiedls suitable command?

I need a point of reference to proceed.

Thanks.

Doug Robbins - Word MVP said:
While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he
wants,
the OP has to use the variable name generated by the "A" & i & "B" to get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

macropod said:
Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables, C1AM,
C2AM
etc. has integer. I want to calculate the average of the values. The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers. In
other languages I can concatenate a counter to step through the data
items i.e.
C || counter || AM to cycle through the variables. Is there a way
in
VB6 to do something similar? I was not looking at an array but if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
C

Canblue

I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first 3
elements. Any of the other elements do not show any value but when I look at
the screen, all of the information is there.



Doug Robbins - Word MVP said:
What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the community
provide me with an example of what you mean by DB.Fiedls suitable command?

I need a point of reference to proceed.

Thanks.

Doug Robbins - Word MVP said:
While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he
wants,
the OP has to use the variable name generated by the "A" & i & "B" to get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables, C1AM,
C2AM
etc. has integer. I want to calculate the average of the values. The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers. In
other languages I can concatenate a counter to step through the data
items i.e.
C || counter || AM to cycle through the variables. Is there a way
in
VB6 to do something similar? I was not looking at an array but if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first 3
elements. Any of the other elements do not show any value but when I look
at
the screen, all of the information is there.



Doug Robbins - Word MVP said:
What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he
wants,
the OP has to use the variable name generated by the "A" & i & "B" to
get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables, C1AM,
C2AM
etc. has integer. I want to calculate the average of the values.
The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers.
In
other languages I can concatenate a counter to step through the
data
items i.e.
C || counter || AM to cycle through the variables. Is there a
way
in
VB6 to do something similar? I was not looking at an array but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
C

Canblue

Oops. Sorry. I was focused on the For loop code. The error is with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is my
background is mainframe languages with some exposure to PC based products.
Anyway, the source data is a DB. The data that is displayed on the screen
comes from a query.

I have this feeling that I am going down the road with partial directions --
I see a solution to the end result, figure that it should work like this or
that and start creating a process flow, maybe using the incorrect techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are just so
many options.

I appreciate the patients of all the participants.

Doug Robbins - Word MVP said:
Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first 3
elements. Any of the other elements do not show any value but when I look
at
the screen, all of the information is there.



Doug Robbins - Word MVP said:
What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what he
wants,
the OP has to use the variable name generated by the "A" & i & "B" to
get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you accessing the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables, C1AM,
C2AM
etc. has integer. I want to calculate the average of the values.
The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all integers.
In
other languages I can concatenate a counter to step through the
data
items i.e.
C || counter || AM to cycle through the variables. Is there a
way
in
VB6 to do something similar? I was not looking at an array but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

If I run a macro containing the following code:

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

The message box displays 55 which is the sum of the numbers from 1 to 10

Are you saying that when you run the above code, the command

ActiveDocument.Variables(myVar).Value = i

produces an error?

Of course the above is all academic. While I know what DB stands for in
generic terminology, you have so far not provided any information on what it
really is.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Oops. Sorry. I was focused on the For loop code. The error is with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is my
background is mainframe languages with some exposure to PC based products.
Anyway, the source data is a DB. The data that is displayed on the screen
comes from a query.

I have this feeling that I am going down the road with partial
directions --
I see a solution to the end result, figure that it should work like this
or
that and start creating a process flow, maybe using the incorrect
techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are just so
many options.

I appreciate the patients of all the participants.

Doug Robbins - Word MVP said:
Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand
this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first 3
elements. Any of the other elements do not show any value but when I
look
at
the screen, all of the information is there.



:

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because
of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM
by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what
he
wants,
the OP has to use the variable name generated by the "A" & i & "B"
to
get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value
from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you accessing
the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables,
C1AM,
C2AM
etc. has integer. I want to calculate the average of the values.
The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable
name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all
integers.
In
other languages I can concatenate a counter to step through
the
data
items i.e.
C || counter || AM to cycle through the variables. Is there
a
way
in
VB6 to do something similar? I was not looking at an array
but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
C

Canblue

I was not running it as a macro. It was event code, on open and yes it
generated the error. What is it that you are looking for/ need from me to
help solve this?

Doug Robbins - Word MVP said:
If I run a macro containing the following code:

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

The message box displays 55 which is the sum of the numbers from 1 to 10

Are you saying that when you run the above code, the command

ActiveDocument.Variables(myVar).Value = i

produces an error?

Of course the above is all academic. While I know what DB stands for in
generic terminology, you have so far not provided any information on what it
really is.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Oops. Sorry. I was focused on the For loop code. The error is with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is my
background is mainframe languages with some exposure to PC based products.
Anyway, the source data is a DB. The data that is displayed on the screen
comes from a query.

I have this feeling that I am going down the road with partial
directions --
I see a solution to the end result, figure that it should work like this
or
that and start creating a process flow, maybe using the incorrect
techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are just so
many options.

I appreciate the patients of all the participants.

Doug Robbins - Word MVP said:
Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand
this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first 3
elements. Any of the other elements do not show any value but when I
look
at
the screen, all of the information is there.



:

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant, because
of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM, C2AM..C10AM
by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do what
he
wants,
the OP has to use the variable name generated by the "A" & i & "B"
to
get
the value from the database for each field that is represented by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value
from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you accessing
the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables,
C1AM,
C2AM
etc. has integer. I want to calculate the average of the values.
The
number of elements ranges from 12 to 18 then 24. Looking for a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable
name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


I have a DB with elements like C1AM, C2AM..C10AM, all
integers.
In
other languages I can concatenate a counter to step through
the
data
items i.e.
C || counter || AM to cycle through the variables. Is there
a
way
in
VB6 to do something similar? I was not looking at an array
but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

On opening what? What application are you using? This newsgroup is for the
use of Visual Basic in Word and I suspect that your post is off topic.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I was not running it as a macro. It was event code, on open and yes it
generated the error. What is it that you are looking for/ need from me to
help solve this?

Doug Robbins - Word MVP said:
If I run a macro containing the following code:

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

The message box displays 55 which is the sum of the numbers from 1 to 10

Are you saying that when you run the above code, the command

ActiveDocument.Variables(myVar).Value = i

produces an error?

Of course the above is all academic. While I know what DB stands for in
generic terminology, you have so far not provided any information on what
it
really is.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
Oops. Sorry. I was focused on the For loop code. The error is with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is my
background is mainframe languages with some exposure to PC based
products.
Anyway, the source data is a DB. The data that is displayed on the
screen
comes from a query.

I have this feeling that I am going down the road with partial
directions --
I see a solution to the end result, figure that it should work like
this
or
that and start creating a process flow, maybe using the incorrect
techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are just
so
many options.

I appreciate the patients of all the participants.

:

Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a
query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand
this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed
to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first
3
elements. Any of the other elements do not show any value but when
I
look
at
the screen, all of the information is there.



:

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant,
because
of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM,
C2AM..C10AM
by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do
what
he
wants,
the OP has to use the variable name generated by the "A" & i &
"B"
to
get
the value from the database for each field that is represented
by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value
from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you
accessing
the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables,
C1AM,
C2AM
etc. has integer. I want to calculate the average of the
values.
The
number of elements ranges from 12 to 18 then 24. Looking for
a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable
name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


message
I have a DB with elements like C1AM, C2AM..C10AM, all
integers.
In
other languages I can concatenate a counter to step through
the
data
items i.e.
C || counter || AM to cycle through the variables. Is
there
a
way
in
VB6 to do something similar? I was not looking at an
array
but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
C

Canblue

You are correct. I am dealing with Access VBA, forum heading indicated VBA
General discussion. Will hunt for a more appropriate forum.

Thanks for pointing this out.


Doug Robbins - Word MVP said:
On opening what? What application are you using? This newsgroup is for the
use of Visual Basic in Word and I suspect that your post is off topic.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I was not running it as a macro. It was event code, on open and yes it
generated the error. What is it that you are looking for/ need from me to
help solve this?

Doug Robbins - Word MVP said:
If I run a macro containing the following code:

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

The message box displays 55 which is the sum of the numbers from 1 to 10

Are you saying that when you run the above code, the command

ActiveDocument.Variables(myVar).Value = i

produces an error?

Of course the above is all academic. While I know what DB stands for in
generic terminology, you have so far not provided any information on what
it
really is.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Oops. Sorry. I was focused on the For loop code. The error is with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is my
background is mainframe languages with some exposure to PC based
products.
Anyway, the source data is a DB. The data that is displayed on the
screen
comes from a query.

I have this feeling that I am going down the road with partial
directions --
I see a solution to the end result, figure that it should work like
this
or
that and start creating a process flow, maybe using the incorrect
techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are just
so
many options.

I appreciate the patients of all the participants.

:

Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a
query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not understand
this
error or how to fix it.

The source data is a DB via a query and screen. Control is passed
to a
second screen via a click action.

There is a problesm that I do not understand. I can print the first
3
elements. Any of the other elements do not show any value but when
I
look
at
the screen, all of the information is there.



:

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant,
because
of
the
"A" and the "B". Neither can you assign a .Value to it directly

The OP talks about having a DB with elements like C1AM,
C2AM..C10AM
by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do
what
he
wants,
the OP has to use the variable name generated by the "A" & i &
"B"
to
get
the value from the database for each field that is represented
by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the value
from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you
accessing
the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


I tried that and it does not work as expected. The variables,
C1AM,
C2AM
etc. has integer. I want to calculate the average of the
values.
The
number of elements ranges from 12 to 18 then 24. Looking for
a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a variable
name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


message
I have a DB with elements like C1AM, C2AM..C10AM, all
integers.
In
other languages I can concatenate a counter to step through
the
data
items i.e.
C || counter || AM to cycle through the variables. Is
there
a
way
in
VB6 to do something similar? I was not looking at an
array
but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 
D

Doug Robbins - Word MVP

So finally we find out that the database (DB) that you are using is Access.
I lost count of how many times I asked what was the source of the data.

The name of this newsgroup is microsoft.public.word.vba.general.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
You are correct. I am dealing with Access VBA, forum heading indicated
VBA
General discussion. Will hunt for a more appropriate forum.

Thanks for pointing this out.


Doug Robbins - Word MVP said:
On opening what? What application are you using? This newsgroup is for
the
use of Visual Basic in Word and I suspect that your post is off topic.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Canblue said:
I was not running it as a macro. It was event code, on open and yes it
generated the error. What is it that you are looking for/ need from me
to
help solve this?

:

If I run a macro containing the following code:

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

The message box displays 55 which is the sum of the numbers from 1 to
10

Are you saying that when you run the above code, the command

ActiveDocument.Variables(myVar).Value = i

produces an error?

Of course the above is all academic. While I know what DB stands for
in
generic terminology, you have so far not provided any information on
what
it
really is.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Oops. Sorry. I was focused on the For loop code. The error is
with
ActiveDocument.Variables(myVar).Value = i statement.

This is starting to get very PC complicated. What I mean by that is
my
background is mainframe languages with some exposure to PC based
products.
Anyway, the source data is a DB. The data that is displayed on the
screen
comes from a query.

I have this feeling that I am going down the road with partial
directions --
I see a solution to the end result, figure that it should work like
this
or
that and start creating a process flow, maybe using the incorrect
techniques.
I guess this means that I really do not know what I am doing in VB6.
Note. I have taken college courses for VB ver 3 and C. There are
just
so
many options.

I appreciate the patients of all the participants.

:

Are you saying that you get an error on the a = 0 line?

I do not understand what you mean by "The source data is a DB via a
query
and screen."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

I tried your example

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

I get the 424 run time error on the 3rd line. I do not
understand
this
error or how to fix it.

The source data is a DB via a query and screen. Control is
passed
to a
second screen via a click action.

There is a problesm that I do not understand. I can print the
first
3
elements. Any of the other elements do not show any value but
when
I
look
at
the screen, all of the information is there.



:

What is the source of the data? (DB assumed to be data base)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself
of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Doug. Thanks. You are correct re: fields.
It has been may years since I dabbled with databases. Can the
community
provide me with an example of what you mean by DB.Fiedls
suitable
command?

I need a point of reference to proceed.

Thanks.

:

While you can do this

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
ActiveDocument.Variables(myVar).Value = i
a = a + ActiveDocument.Variables(myVar).Value
Next i
MsgBox a

You cannot do

Dim i As Long, a As Long
Dim myVar As String
a = 0
For i = 1 To 10
myVar = "A" & i & "B"
a = a + myVar
Next i
MsgBox a

as myVar is a String (even if you declare it as a variant,
because
of
the
"A" and the "B". Neither can you assign a .Value to it
directly

The OP talks about having a DB with elements like C1AM,
C2AM..C10AM
by
which
I assume that he means fields like C1AM, C2AM..C10AM. To do
what
he
wants,
the OP has to use the variable name generated by the "A" & i
&
"B"
to
get
the value from the database for each field that is
represented
by a
variable
name using something like

a = a + DB.Fields(myVar)

where DB.Fields is a suitable command that will return the
value
from
the
fields of the database

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail
yourself
of
my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi Canblue,

What is happening that isn't as expected? How are you
accessing
the
variables' values?

--
Cheers
macropod
[MVP - Microsoft Word]


message
I tried that and it does not work as expected. The
variables,
C1AM,
C2AM
etc. has integer. I want to calculate the average of the
values.
The
number of elements ranges from 12 to 18 then 24. Looking
for
a
blackbox.
How can I step through the DB items.

:

Hi Canblue,

Yes, you certainly can incorporate a counter into a
variable
name.
For
example:

Sub Demo()
Dim i As Integer
Dim myVar As String
For i = 1 To 10
myVar = "A" & i & "B"
MsgBox myVar
Next i
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


message
I have a DB with elements like C1AM, C2AM..C10AM, all
integers.
In
other languages I can concatenate a counter to step
through
the
data
items i.e.
C || counter || AM to cycle through the variables. Is
there
a
way
in
VB6 to do something similar? I was not looking at an
array
but
if
I
have to go there then so be it. do I = 1 to 10
a = a + C || I || AM
end
 

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