When I click Category1 everything works but...

  • Thread starter Thread starter Claude du Québec
  • Start date Start date
C

Claude du Québec

Guest
Good morning everyone,

When I click Category1 everything works but when I click on Category2, I have an error on line 59:

MyButtons(CType(MyProducts.Item(0), Integer)).Text = MyProducts.Item(3)

Here is the code on the form "FrmProductsInvoicing" (Bold is line 59 where the error is)

Imports System.Data.SqlClient
Public Class FrmProductsInvoicing
Public AuthUser As String
Dim MyButtons(2800) As Button
Dim MyButtonsID(2800) As TextBox
Public DBDS As DataSet

Private Sub ChargeMyButtons()
If Me.CategoryID.Text = 1 Then
For B As Integer = 1 To 70
MyButtons(B) = Me.Controls("Button" & B)
Next
End If
If Me.CategoryID.Text = 2 Then
For B As Integer = 71 To 140
MyButtons(B) = Me.Controls("Button" & B)
Next
End If
End Sub

Private Sub ChargeMyButtonsID()
If Me.CategoryID.Text = 1 Then
For B As Integer = 1 To 70
MyButtonsID(B) = Me.Controls("ProdID" & B)
Next
End If
If Me.CategoryID.Text = 2 Then
For B As Integer = 71 To 140
MyButtonsID(B) = Me.Controls("ProdID" & B)
Next
End If
End Sub

Public Sub LoadUsernamesOnButtons()

Dim MyConnection As New SqlConnection
Dim MyCommande As SqlCommand

MyConnection.ConnectionString = "Server=CLAUDE-PC\192.168.0.133,1433;database=ACData;User=admin;Pwd=mANONbENOIT1954;"
MyConnection.Open()

MyCommande = MyConnection.CreateCommand()
MyCommande.CommandType = CommandType.Text
If Me.CategoryID.Text = 1 Then
MyCommande.CommandText = "SELECT ID, Category, SalePrice1, ProductName, Active, CategoryID FROM ProductsBasicView Where ID Between 1 And 70 ORDER BY ID ASC"
End If
If Me.CategoryID.Text = 2 Then
MyCommande.CommandText = "SELECT ID, Category, SalePrice1, ProductName, Active, CategoryID FROM ProductsBasicView Where ID Between 71 And 140 ORDER BY ID ASC"
End If
ChargeMyButtons()
ChargeMyButtonsID()
Dim MyProducts As SqlDataReader
MyProducts = MyCommande.ExecuteReader()

Do While MyProducts.Read
If MyProducts.Item(4) = 0 Then ' 1 and 4, the column FirstName = Employee or the column Active = False
MyButtons(CType(MyProducts.Item(0), Integer)).Visible = False ' and True to be visible
Else
MyButtons(CType(MyProducts.Item(0), Integer)).Text = MyProducts.Item(3)
MyButtonsID(CType(MyProducts.Item(0), Integer)).Text = MyProducts.Item(0)
End If
Loop

MyProducts.Close()
MyCommande.Dispose()
MyConnection.Close()
End Sub
Public Sub LoadMyProductsImagesOnButtons()

End Sub
Private Sub ACLoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadUsernamesOnButtons()
WindowState = FormWindowState.Maximized
End Sub

Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
Dim FormMain As New MainForm
MainForm.Show()
Me.Close()
End Sub

Private Sub BtnMaximize_Click(sender As Object, e As EventArgs) Handles BtnMaximize.Click
WindowState = FormWindowState.Maximized
Me.BtnNormal.Visible = True
Me.BtnMaximize.Visible = False
End Sub

Private Sub BtnMinimize_Click(sender As Object, e As EventArgs) Handles BtnMinimize.Click
WindowState = FormWindowState.Minimized
End Sub

Private Sub BtnNormal_Click(sender As Object, e As EventArgs) Handles BtnNormal.Click
WindowState = FormWindowState.Normal
Me.BtnMaximize.Visible = True
Me.BtnNormal.Visible = False
End Sub

End Class


And this is the error:

1580612.jpg

Continue reading...
 

Similar threads

Back
Top