1

I'm new in Vb.net and try to learn how to program,but i stuck on this stages.

I create a new sub and declare it in 1 form

Public Class WebForm5
    Public Sub info()
        Dim x As String
        Dim y As String
        Dim z As String
        x = txtbookn.Text
        y = txtqua.Text.ToString
        z = txtpri.Text.ToString
    End Sub
End Class

and i try to pass it to another classes which in

Public Class Product
    Public Sub New()
        Me.Book_Name = (value for x)
        Me.UnitPrice =(value for y)
        Me.quantty=(value for z)
    End Sub
End Class

2 Answers 2

1

Pass it in the constructor

Public Class Product
   Public Sub New(x as String, y as String, z As String)
      Me.Book_Name = x
      Me.UnitPrice = y
      Me.quantty = z
  End Sub
End Class

Then in your page you can call it as

Dim MyProduct as Product = New Product(txtbookn.Text, txtqua.Text, txtpri.Text)
Sign up to request clarification or add additional context in comments.

Comments

0

Your x, y, and z variables are not in the scope of the New() sub. If you want them to be accessible you either have to pass them as parameters, or they need to be defined outside of both classes. Right now they only exist in info().

2 Comments

May i know how can i defined outside both of the classes, i'm new, wanna learn more.
Sorry I meant outside of the methods. They still need to be in your scope. If you maintain 2 classes you'll need to pass them as parameters when you call your method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.