how d0 error of expectation unhandled in visual basic

Jack 0 Reputation points
2023-03-28T13:49:01.0266667+00:00

Screenshot 2023-03-28 164243

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,712 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 53,416 Reputation points
    2023-03-28T14:52:10.35+00:00

    The specific issue is that you're accessing the first row of dt the table. But there are no rows in that table. I know that because you create the table in the previous line. At that point it is an empty table. Hence you are trying to access an empty array of rows. Before you try to access a row you need to first confirm the table has rows using dt.Rows.Count

    Furthermore you have the same issue with the columns. You are trying to access the first column of the first row dt.Rows(0)(0) but the row has no columns defined so there are no columns to read. In order to get this code to work you would need to first define the columns in your table and then add rows to the table with the data. At that point the code would work fine.

    I cannot, at this point, tell you what you should be doing in this specific code because you're creating a new table and then trying to access a non-column of a non-existent row. You're going through all this effort just to set the balance textbox of your UI. You don't really need a table for that. Since you didn't provide us with where the balance is currently defined at we cannot give you the correct code but the simplest possible example would be this.

    ' TODO: Get data from your database backend using whatever library you use
    Dim oldBalanceValue As Currency
    Set oldBalanceValue = 12.34
    
    oldBalance.Text = oldBalanceValue.ToString()
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.