0

So I have 2 forms and a class, on my 1st form, it adds items to a dictionary and on my second form it checks if the item that is supposed to be added on dictionary is successful. But the weird thing is, in form 1, it shows that the item is added in the dictionary but in my 2nd form, when I get the count of dictionary, it produces 0 which means there's nothing in there. Hope you could help me with this.

Form 1

Public Class register

Dim acc_num As New System.Text.StringBuilder()
Dim account_info As New ArrayList()
Dim access_acc As New Accounts

Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
    Try
        account_info.Add(fname_txt.Text & " " & lname_txt.Text)
        account_info.Add("0.00")
        access_acc.addAcc(account_number_lbl.Text, account_info)
        MsgBox("Your account has been registered! Thank you for banking with us, your money is in good hands")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
 End Sub

End Class

Form 2

Dim access_acc As New Accounts
 Private Sub btn_process_Click(sender As Object, e As EventArgs) Handles btn_process.Click
    MsgBox(access_acc.getCount().ToString)
 End Sub

My Class

Public Class Accounts

Private account As New Dictionary(Of String, ArrayList)

Public Sub addAcc(ByVal account_number As String, account_info As ArrayList)

    account.Add(account_number, account_info)
    MsgBox(account.Count)

End Sub

   Public Function getCount() As Integer
    Return account.Count
End Function

  End Class
iamLinker
  • 88
  • 1
  • 10
  • You're mixing .NET 1.x types (`ArrayList`) with .NET 2 Generics (`Dictionary(Of)`). You should only use Generics. – Dai Oct 25 '16 at 07:57
  • What is `class Accounts`, exactly? And why are you creating multiple instances of it? It looks like a repository object to me, is this the case? – Dai Oct 25 '16 at 07:58
  • @Dai yes it is, that class will hold the users account info. I used arraylist as one of its parameters because it is easy too lookup data using that. – iamLinker Oct 25 '16 at 08:04
  • Add `Option Explicit` to your project and all of your code files. – RBarryYoung Oct 25 '16 at 12:27

1 Answers1

0

I got rid of my problem by using Module(which is a C# counterpart to static) instead of Class. Here's a reference as to what is the best method to use in a certain situation.

Module VS Classes

Community
  • 1
  • 1
iamLinker
  • 88
  • 1
  • 10