hazejean Posted July 17, 2003 Posted July 17, 2003 Is there any way to Dim check boxes...so in the code below I can do a loop to dynamically define check boxes? Public Sub gettxt() Dim val As Integer Dim text(200) Dim result(200) Dim counter As Integer Dim val1 As Integer Dim text1 As String Dim i1 As Integer Dim verb1 As String Dim verb2 As String Dim verb3 As String Dim verb4 As String Dim verb5 As String Dim j As Integer Dim i As Integer Dim Mycheck(5) As CheckBox For i = 1 To 5 Controls.Add(Mycheck(i)) Next i val = Mycheck(1).CheckState verb1 = "one" verb2 = "two" verb3 = "three" verb4 = "four" verb5 = "five" 'Mycheck(1).Text = verb1 counter = 0 'If Mycheck(1).CheckState = 1 Then text(1) = verb1 Else If Mycheck(1).CheckState = 0 Then text(1) = "" 'If Check2.CheckState = 1 Then text(2) = verb2 Else If Check2.CheckState = 0 Then text(2) = "" ' If Check3.CheckState = 1 Then text(3) = verb3 Else If Check3.CheckState = 0 Then text(3) = "" ' If Check4.CheckState = 1 Then text(4) = verb4 Else If Check4.CheckState = 0 Then text(4) = "" ' If Check5.CheckState = 1 Then text(5) = verb5 Else If Check5.CheckState = 0 Then text(5) = "" For j = 1 To 200 If text(j) <> "" Then counter = counter + 1 : result(counter) = text(j) Else Next j ' text with punctuation val1 = val - 1 If val = 1 Then text1 = result(1) Else If val = 2 Then text1 = result(1) & " and " & result(2) Else If val > 2 Then For i1 = 1 To val1 text1 = text1 & result(i1) & ", " Next i1 text1 = text1 & "and " & result(val) End If RichTextBox1.Text = text1 End Sub End Class Quote
*Experts* mutant Posted July 17, 2003 *Experts* Posted July 17, 2003 You have to intiliazie the checkbox before adding it to the form. Replace this: For i = 1 To 5 Controls.Add(Mycheck(i)) Next i With: For i = 1 To 5 MyCheck(i) = New CheckBox Controls.Add(Mycheck(i)) Next i Quote
hazejean Posted July 17, 2003 Author Posted July 17, 2003 code problem? with suggested code I only get one text box? Quote
*Experts* mutant Posted July 17, 2003 *Experts* Posted July 17, 2003 That was only an example, you also have to change the location property, becuase right now they are being drawn over eachother. For i = 1 To 5 MyCheck(i) = New CheckBox MyCheck(i).Location = New Point(xcoordinate, y coordinate) Controls.Add(Mycheck(i)) Next i Substitute xcoordinate and ycoordinate with numbers. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.