Attempting to edit XML File through Visual Basic App RRS feed

  • Question

  • So, I'm making an app in VB, it's an ATM. It starts off with a form, where you enter the PIN into the textbox, and it checks against the XML file, and if it's correct, it lets you in.


    Private Sub btnPINENTER_Click(sender As Object, e As EventArgs) Handles btnPINENTER.Click
        Dim AccountPIN As Integer
        Dim AccountName As String
        Dim InputPIN As Integer = Val(txtPIN.Text)
        Dim xelement As XElement = XElement.Load("Accounts.xml")
        Dim Records As IEnumerable(Of XElement) = xelement.Elements()
        For Each Account In Records
            AccountPIN = (Account.Element("PIN").Value)
            AccountName = (Account.Element("Name").Value)
            If InputPIN = AccountPIN Then
                MsgBox("Correct Password" & vbNewLine & "Welcome" & AccountName)
                txtPIN.Text = ""
            End If
        Next Account
    End Sub

    The next step is that the second form works like an ATM machine. So there are three buttons, Deposit, Withdraw and Account Balance. Now I need a way to be able to use the Deposit and WIthdraw buttons so that they can update the data in the XML File, but I'm clueless on how to do this. I'm a newbie as you can tell. Any help is greatly appreciated.

    Friday, December 7, 2018 9:44 PM

All replies

  • Hello,

    The first things to consider (whether this is homework or not) are the following.

    Deposit/withdraw delegates/events and what constitutes insufficient funds that would trigger validation and as needed save/remember information.

    How about remembering transactions?

    Do you really want to expose this information in plan text or encrypted be it simple or complex?

    Example delegates

    Public Delegate Sub AccountBalanceWarningEventHandler(sender As Object, e As AccountBalanceWarningEventArgs)
    Public Delegate Sub AccountDenyingEventHandler(sender As Object, e As AccountDenialEventArgs)

    Then there are the classes for the delegates

    Public Class AccountBalanceWarningEventArgs
        Inherits EventArgs
        Public Sub New(pNumber As String, pWarningLevel As Decimal, pCurrentBalance As Decimal)
            WarningLevel = pWarningLevel
            Balance = pCurrentBalance
            AccountNumber = pNumber
        End Sub
        Public ReadOnly Property AccountNumber As String
        Public ReadOnly Property WarningLevel() As Decimal
        Public ReadOnly Property Balance() As Decimal
    End Class


    Public Class AccountDenialEventArgs
        Inherits EventArgs
        Private _reason As DenialReasons
        Public Sub New(Reason As DenialReasons)
            _reason = Reason
        End Sub
        Public ReadOnly Property Reason As DenialReasons
                Return _reason
            End Get
        End Property
    End Class

    Declaring them

    Public Event AccountBalanceWarningEvent As AccountBalanceWarningEventHandler
    Public Event AccountDenialEvent As AccountDenyingEventHandler
    Bottom line is how deep down the rabbit hole do you really want to go?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, December 8, 2018 12:21 AM