Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

variable 'stocks' is used before it has been assigned a value in vb.net

variable ‘stocks’ is used before it has been assigned a value in vb.net
is there anything wrong code?.

I made please guide me

 For i = 0 To _myTable.Rows.Count - 1
                    Dim detail = New ItemTransfersDetail With {
                        .No = Convert.ToInt32(_myTable.Rows(i)(0)),
                        .Invno = BtxtInvoNo.Text,
                        .CodeProduct = _myTable.Rows(i)(1).ToString(),
                        .Barcode = _myTable.Rows(i)(2).ToString(),
                        .Colorcode = _myTable.Rows(i)(3).ToString(),
                        .Size = _myTable.Rows(i)(4).ToString(),
                        .Qty = Convert.ToInt32(_myTable.Rows(i)(5).ToString())
                        }

                    Dim stocks = New Stocks With {
'Error code below
                        .QTY_STOCK = (stocks.QTY_STOCK - detail.Qty),
                        .CodeProduct = _myTable.Rows(i)(1).ToString(),
                        .Barcode = _myTable.Rows(i)(2).ToString(),
                        .Colorcode = _myTable.Rows(i)(3).ToString(),
                        .Size = _myTable.Rows(i)(4).ToString()
                        }
                    itrservicedetail.InsertItemTransfersdetail(detail)
                    sservice.Updatestockminus(stocks)
 Public Class Stocks
        Public Property CodeProduct() As String
        Public Property Barcode() As String
        Public Property Colorcode() As String
        Public Property Size() As String
        Public Property QTY_STOCK() As Integer
    End Class

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are declaring the stocks variable and using that variable in the expression that initialises it:

Dim stocks = New Stocks With { .QTY_STOCK = (stocks.QTY_STOCK - detail.Qty),

How can stocks.QTY_STOCK possibly have a value there when that’s the property you’re setting with that code? You haven’t bothered to explain what you’re actually trying to achieve with that code so we can’t tell you what it should be like, but it definitely shouldn’t be like that.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading