Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
vb 6 help dynamic textboxes
Ok, what i need help with is referencing to a textbox that is created on the fly. like the user clicks a button, the button makes 5 new textboxes. I got that to work, however I don't know how to reference them.
here is the code i have so far
Option Explicit
Public iLeft As Integer, iTop As Integer, s As Integer, g As Integer
Private st(30) As String 'holds 30 students names
Private Sub Form_Load()
iLeft = 360
iTop = 1850
s = 1 'student number
End Sub
Private Sub Command2_Click()
grade st(0) 'grade student 0
End Sub
Private Sub Command3_Click()
For g = 1 To 5 'the for loop makes 5 new textboxes horizontally, calls them student1grade1 student1grade2 etc, then student2grade1 for the rows
LoadControl Me, "VB.TextBox", "student" & s & "grade" & g, "", 375, 1935, iTop, iLeft
iLeft = iLeft + 2050
Next g
iLeft = 360
iTop = iTop + 400
s = s + 1
End Sub
Public Function grade(student As String)
Dim nAssignments As Integer
Dim totalPoints As Double
Dim average As Double
nAssignments = 3 ' number of assignments
totalPoints = Val(student.Text) + Val(student.Text) + Val(student.Text) 'adds up the %s
average = totalPoints / nAssignments 'divides the %s
Text5.Text = average & " %"
End Function
Sub LoadControl(frm As Form, sControlType As String, sControlName As String, sCaption As String, iHeight As Integer, iWidth As Integer, iTop As Integer, iLeft As Integer) 'this function makes the new text boxes
On Error Resume Next
Dim newGrade As Control
Set newGrade = frm.Controls.Add(sControlType, sControlName)
With newGrade
.Height = iHeight
.Width = iWidth
.Top = iTop
.Left = iLeft
.Visible = True
End With
st(0) = newGrade.name
End Sub
so i need to be able to use the grade function by referencing the student.text however it doesnt pick it up as student1grade1.text but instead student.text literally. Any help is gladly appreciative like always :D thanks