|
-
Mar 11th, 2000, 06:54 PM
#1
Thread Starter
Member
How do I add the contents of a textbox array without enshrining the number of indexes in my code?
For example, I can't use:
Val(text2.text)= Val(text1(1).text) + Val(text1(2).text) ..etc.., because my program creates textboxes at runtime.
Is there any 'For...Next' way of doing it or something?
Thanks for any help!
-
Mar 11th, 2000, 08:18 PM
#2
PowerPoster
Will this work...
Dim Cnt As Integer
Dim FinalVal As Integer
FinalVal=0
For Cnt= Text1.LBound To Text1.UBound:FinalCnt = FinalCnt + CInt(Text1(Cnt).Text):Next
Text2.Text = CStr(FinalVal)
Edited by Chris on 03-12-2000 at 08:26 AM
-
Mar 12th, 2000, 07:06 AM
#3
Thread Starter
Member
Chris, thanks for your help, but I couldn't quite get it to work. I didn't get an error, but textbox3 didn't become visible, as it should if the sum of the text1 array is equal to the figure inserted in the text2 box.
Any help would be appreciated!
Private Sub Text2_KeyPress(keyascii As Integer)
keyascii = Asc(Chr(keyascii))
Dim Cnt As Integer
Dim FinalVal As Integer
FinalVal = 0
For Cnt = Text1.LBound To Text1.UBound: FinalCnt = FinalCnt + CInt(Text1(Cnt).Text): Next
If Text2.Text = CStr(FinalVal) And keyascii = vbKeyReturn Then
Text3.Visible = True
End If
End Sub
-
Mar 12th, 2000, 09:53 PM
#4
Lively Member
i don't really understand what you are trying to do here, but the code seems to work if...
you enter a number in text2 and press enter
if the number you entered is equal to the sum of the textboxes, text3 become visible
if you want text3 to become visible even if the number entered in text2 is not equal to the sum of text1() change and to or in your if test at the bottom your keypress event
-
Mar 12th, 2000, 10:46 PM
#5
PowerPoster
Your code should work fine, but i notice the following code may not need in this sub procedure.
keyascii = Asc(Chr(keyascii))
because it first convert to character then convert back to ascii code, which it the same as the original keyascii. 
Did other control or sub procedure cause set the Text3 visible properties to false, hence, will will not see the Text3 textbox even your set it visible in the Text2_KeyPress procedure.
Chris, thanks for your help, but I couldn't quite get it to work. I didn't get an error, but textbox3 didn't become visible, as it should if the sum of the text1 array is equal to the figure inserted in the text2 box.
Any help would be appreciated!
Private Sub Text2_KeyPress(keyascii As Integer)
keyascii = Asc(Chr(keyascii))
Dim Cnt As Integer
Dim FinalVal As Integer
FinalVal = 0
For Cnt = Text1.LBound To Text1.UBound: FinalCnt = FinalCnt + CInt(Text1(Cnt).Text): Next
If Text2.Text = CStr(FinalVal) And keyascii = vbKeyReturn Then
Text3.Visible = True
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|