rwan rwan - 1 month ago 9
Vb.net Question

VB 13 windows form - how do I pass my variable between two forms [New to coding]

On one form I have:

lblQuizName.Text = "Enter Quiz Name"


Later on I call a separate form:

frmQuizForStudents.Show()


How do I move the text from
lblQuizName.Text
into this form as it doesn't let me write a parameter when I call
frmQuizForStudents
.

Especially because it has
Public Class frmQuizForStudents
at the top, I cannot write: "
Public Class frmQuizForStudents(lblQuizName)
".

Answer

You can create a new constructor using the parameter needed for your frmQuizForStudents form :

Public Class frmQuizForStudents

    sub new(QuizName as string)
         '... Code here
    end sub

end class

Also, to call this Form you will need to create a new instance of it before using the new parameter:

dim NewQuizForStudents as New frmQuizForStudents(lblQuizName.Text)
NewQuizForStudents.show