Re: referring to increasing VBA variable name in loop



I'd use an array:

Dim Phrase(1 to 30) as string
phrase(1) = "what you want1"
....
Phrase(30) = "what you want30"

Then you could use:

Dim iCtr as long
....
for ictr = lbound(phrase) to ubound(phrase)
xl.speech.speak phrase(ictr)
next ictr



ucdcrush@xxxxxxxxx wrote:

I am using VBA to put together some phrases to be spoken with the text
to speech feature in excel.

What I've got is a list of string variables,

Phrase1
Phrase2
Phrase3
...
Phrase30

which are set equal to different words or phrases such as
Phrase1 = "Hello"

I can hard-code a variable name into the speech code such as:

XL.Speech.Speak Phrase1

this will successfully speak the string assigned to Phrase1.

What Im having trouble with is referring to the Phrase1-30 variables
in a for loop, something like

for i = 1 to 30
xl.speech.speak phrase & i
next

This code doesn't produce any speech, I'm assuming because the
variable name isn't being passed as intended. How can I refer to
variables within a loop, when the loop # (i) is part of the variable
name?

Thanks.

--

Dave Peterson
.



Relevant Pages

  • Re: Error and Save as question
    ... Function SaveWithParens(SomeWorkbook As Workbook, myPath As String, _ ... Dim myNewFileName As String ... Dim iCtr As Long ... Dim TestStr As String ...
    (microsoft.public.excel.misc)
  • RE: adding text to time
    ... Dim strNum As String ... Dim strFrac As String ... Dim strTemp As String ... Dim iCtr As Integer ...
    (microsoft.public.access.externaldata)
  • Re: Sorting data in a cell alphabetically
    ... Function SortText(myStr As String) As String ... Dim mySplit As Variant ... Dim iCtr As Long ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How to Dim the contents of a variable in running procedure?
    ... There are some languages that let you build a variable name and use that string ... dim GapStart() as long ... 'later determine the number of operators in the formula string and then redim ... for iCtr = lboundto ubound ...
    (microsoft.public.excel.misc)
  • Re: how do I do hex to single precision conversion??
    ... Sorry for mix-up on terminology, i was using the phrases from the ... babbage website =) ... When comparing with the babbage URL, this string is ...
    (comp.lang.tcl)