Sending multiple lines of text to a text box, from a loop.

supercrewed
02-22-2008, 07:12 AM
I am creating a program that needs to create several lines in a text box, based on a certain criteria. However, the way I've written the sample is not acceptable.
So my question is, Can you send multiple lines to a text box, using a loop, to generate the lines of text?

When you run the sample, you'll see what I'm trying to do, but I don't like it, can you help?

Basically the loop would be easy, but I just don't know ho to send the multiple lines of text to the text box from the loop.

supercrewed
02-22-2008, 08:31 AM
Sorry guys, I rem'ed out some of the subs, but this one works. Please take a look at it, and let me know if there is a better way using a loop. Just enter some number in the input boxes, The P Dim. must be larger than the W dim...
Thanks

loquin
02-22-2008, 10:52 AM
Well, it looks as if your code would really benefit from using arrays and loops. For instance:CUT_1 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_1 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1

Z_2 = Z_1 * 2
If Z_2 <= Z_ONE Then
CUT_2 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_2 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_2 = ""

End If

Z_3 = Z_2 + Z_1
If Z_3 <= Z_ONE Then
CUT_3 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_3 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_3 = ""

End If

Z_4 = Z_3 + Z_1
If Z_4 <= Z_ONE Then
CUT_4 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_4 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_4 = ""
End If

Z_5 = Z_4 + Z_1
If Z_5 <= Z_ONE Then
CUT_5 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_5 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_5 = ""
End If

Z_6 = Z_5 + Z_1
If Z_6 <= Z_ONE Then
CUT_6 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_6 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_6 = ""
End If

Z_7 = Z_6 + Z_1
If Z_7 <= Z_ONE Then
CUT_7 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_7 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_7 = ""
End If

Z_8 = Z_7 + Z_1
If Z_8 <= Z_ONE Then
CUT_8 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_8 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_8 = ""
End If

Z_9 = Z_8 + Z_1
If Z_9 <= Z_ONE Then
CUT_9 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_9 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_9 = ""
End If

Z_10 = Z_9 + Z_1
If Z_10 <= Z_ONE Then
CUT_10 = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_10 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
PASS = PASS + 1
Else
CUT_10 = ""
End If

PASS_1 = CUT_1 & CUT_2 & CUT_3 & CUT_4 & CUT_5 & CUT_6 & CUT_7 & CUT_8 & CUT_9 & CUT_10

Z_NEXT = (Z_1 * PASS)

End FunctionLets assume you have an array called Z, with 10 elements, and an array CUT, also with 10 Elements. This will allow you to shorten the above code to:' Dimmed wherever you've dimmed the global variables.
Dim Z(10) as Double ' (this actually has 11 elements, but we'll ignore that for now)
Dim Cut(10) as String ' ditto

Public Sub PASS_ONE()

Cut(1) = "Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_1 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf

For Pass = 2 to 10
Z(Pass) = Z(Pass) + Z(1)
If Z(pass) <= Z(1) then
Cut(Pass) ="Y" & (P / 2 - TOOL_RADIUS) & "Z" & Z_2 & vbCrLf & "Y" & (-P / 2 + TOOL_RADIUS) & vbCrLf
Else
Cut(Pass) = ""
End If
Next Pass

PASS_1 = CUT_1 & CUT_2 & CUT_3 & CUT_4 & CUT_5 & CUT_6 & CUT_7 & CUT_8 & CUT_9 & CUT_10

Z_NEXT = (Z_1 * PASS)

End Sub

Note that, since your function was NOT returning a value to the calling program is is actually a SUB, so I made it one.

Also, I didn't go to the trouble of looking up PASS_1, Z_NEXT, or other variables. It APPEARS that they could be arrays also, which would also temd to simplify the code.

I really recommend that you review the installments on loops in the ***

Finally, I would also recommend that, at the top of every form and module code, the compiler directive "Option Explicit" be there.

VB will do this for you automatically. In the Tools, Options menu, make sure that "Require Variable Declaration" is checked.

The compiler will then throw an error whenever you try to run your app or compile it, when there's undeclared variables. And, that's a GOOD thing.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum