PDA

Click to See Complete Forum and Search --> : Code works but is bulky. Any constructive suggestions?


Steve Thomas
Jan 20th, 2000, 12:12 AM
The problem with that is that it displays "A1" or "A2" etc rather than the message.

netSurfer
Jan 20th, 2000, 12:19 AM
Put the messages into a string array and select using the i variable you're looping with:

for i = 1 to 3
textbox(i).text = strMsgArray(i)
next i


Ooops, I just realized that the A1 etc are strings, that's what threw me. That's what I get for typing without reading CAREFULLY! :-) The above would work like this:

dim A1 as string()
redim A1(3)
a1(1) = "message1"
a1(2) = "message2"
a1(3) = "message3"

for i = 1 to 3
textbox(i).text = A1(i)
next i


[This message has been edited by netSurfer (edited 01-20-2000).]

Steve Thomas
Jan 20th, 2000, 02:12 AM
Thank you so much!!!!!!

Steve Thomas
Jan 20th, 2000, 02:28 AM
I copied your code but It doesn't like the statement

Dim A1 as string(). It doesn't like the parenthesis after string?

netSurfer
Jan 20th, 2000, 02:41 AM
oops. it's dim A1() as string

sorry about that :-)

Steve Thomas
Jan 20th, 2000, 11:42 AM
Dim A1 as string
Dim A2 as string
Dim A3 as String

A1 = "Message1"
A2 = "Message2"
A3 = "Message3"

If I write code and I want to do something like this:

for i = 1 to 3
TextBox.caption = A & i
next

I could write it like this but it is bulky:

if i = 1 then
TextBox.caption = A1
else
if i = 2 then
TextBox.caption = A2
else
if i = 3 then
TextBox.caption = A3
End if
Endif
Endif

Any Suggestions?

netSurfer
Jan 20th, 2000, 11:56 AM
for i = 1 to 3
textbox.text = "A" & i
next i

how's that?

You could also, if you're working with several text boxes instead of one, mke them a control array (all same name with different indexes). Then do this:


for i = 1 to 5
textbox(i).text = "A" & i
next i

this would in textbox(1) put A1, textbox(2) - A2 etc

[This message has been edited by netSurfer (edited 01-20-2000).]