I am trying to scan my XML code in order to find the max value in various attributes. I am looking to create a Subroutine with maybe a for loop or something that can look at the UID="" and UserID="" Attributes and have it return the Max Value out of those 2 attributes since I am using NextUID Num="" Attribute to provide the next Unique User ID number when creating a new Department or UserID for an actual User account in my XML file.

Note: This is just an app I am designing for practice as I am an intermediate/begging programmer, so I'm not worried about the content that is inside my XML code as it's all false information and doesn't really represent a specific person. I have hidden all of the passwords in this post to avoid comments for hashing the passwords, etc. I will do that when I redesign the app for an actual app I am prepping to build once I get this one in working order.

I will provide my XML code for review to see if anyone has some advice. I am not using classes to send information to and do the work, so I'm using basic Subroutines, and some functions and am sharing between files when needed. I am going to redesign and build this app that will utilize classes there (still need to figure out how to build classes to do the work and simplify the code). For now I'm just trying to learn as much as I can and am eager to do so and am learning on my own, so please bare with me.

XML code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Database   -   <SortList Type="A-Z" />
      <User Name="" UserID="" ActType="" Password="" LogoutTime="" Phone="" Email="" ExtraNotes="" />-->
<Records>
  <LastDeptSelected Name="Admin" />
  <Departments>
    <NextUID Num="019" />
    <Department Name="Admin" UID="000" SortBy="UID" Members="1">
      <User Name="Admin" UserID="001" ActType="Admin" Password="******" LogoutTime="60" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Administrator" />
    </Department>
    <Department Name="Engineering" UID="002" SortBy="A-Z" Members="1">
      <User Name="David Smith" UserID="003" ActType="Admin" Password="******" LogoutTime="20" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Administrator" />
      <User Name="Michael Smith" UserID="004" ActType="User" Password="mike2020" LogoutTime="15" Phone="509-248-9588" Email="[email protected]" ExtraNotes="" />
    </Department>
    <Department Name="Controls" UID="005" SortBy="A-Z" Members="2">
      <User Name="Russell Smith" UserID="006" ActType="Admin" Password="******" LogoutTime="60" Phone="555-555-55555" Email="[email protected]" ExtraNotes="Programmer" />
      <User Name="Smith David" UserID="007" ActType="User" Password="******" LogoutTime="60" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Programmer" />
      <User Name="Chris Smith" UserID="008" ActType="User" Password="******" LogoutTime="60" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Controls Tech" />
    </Department>
    <Department Name="Construction" UID="009" SortBy="UID" Members="1">
      <User Name="Randy Smith" UserID="010" ActType="Admin" Password="******" LogoutTime="60" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Construction Manager VP" />
    </Department>
    <Department Name="Management" UID="011" SortBy="UID" Members="1">
      <User Name="Michael Smith" UserID="012" ActType="Admin" Password="******" LogoutTime="5" Phone="555-555-5555" Email="[email protected]" ExtraNotes="" />
    </Department>
    <Department Name="Shipping" UID="013" SortBy="UID" Members="1">
      <User Name="Jody Smith" UserID="014" ActType="Admin" Password="******" LogoutTime="15" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Shipping" />
    </Department>
    <Department Name="Parts" UID="015" SortBy="A-Z">
      <User Name="Brad Smith" UserID="016" ActType="Admin" Password="******" LogoutTime="15" Phone="555-555-5555" Email="[email protected]" ExtraNotes="Parts Salesman" />
    </Department>
    <Department Name="CAD" UID="017" SortBy="A-Z">
      <User Name="Jackson Johnson" UserID="018" ActType="Admin" Password="******" LogoutTime="15" Phone="555-555-5555" Email="[email protected]" ExtraNotes="CAD Engineer" />
    </Department>
  </Departments>
</Records>

I have written some code for managing the NextUID number and formatting it as well as counting the number of User accounts there and displaying that onthe screen. I am wanting to find the MAX number before this code, but in the same Subroutine to be able to create the NextUID number based on that Max value and adding 1 to it, instead of the app just creating the next number as I'm doing here (because if a user is removed, I want to keep the number count down as much as possible and if the value gets deleted somehow, I want it to have the ability to create it on its own if that makes sense.

Code:
Public Sub Next_UID()

        Dim UIDList As XmlNodeList
        Dim User_xmld As New XmlDocument()
        User_xmld.Load(DeptSelectAttsFile)
        Dim UserXMLNode As XmlNode = User_xmld.SelectSingleNode("/Records/Departments/NextUID")
        Dim Add_UID As Integer = +1
        Dim NextUID As Integer
        UIDList = User_xmld.GetElementsByTagName("NextUID")
        Dim ReturnValue As New List(Of String)


        If Main.lblActType.Text = "Admin" Then
            For Each node As XmlNode In User_xmld.SelectNodes("//Records/Departments/Department/User")
                ReturnValue.Add(node.Attributes("Name").Value)
            Next

            '--Count All Users and Return Value to Main Admin (on the lblMembers Label)
            For i As Integer = 0 To ReturnValue.Count
                'int = i
                ReturnValue.Add(i)
                lblUserID.Text = i.ToString
            Next
        End If

        Try
            For Each UID As XmlElement In UIDList

                If UserXMLNode IsNot Nothing Then
                    '--Automatically add Next UserID number into textbox & grey out the box
                    txtUID.Text = UID.Attributes("Num").Value
                    txtUID.Enabled = False
                    '--Convert NextUID from an integer to a string & Add 1 to it
                    NextUID = Convert.ToInt32(UID.Attributes("Num").Value) + Add_UID
                    '--If the Next UserID is less than 100, format as a 3 digit number
                    If NextUID < 100 Then
                        UID.Attributes("Num").Value = NextUID.ToString("000")
                        NewDeptUID = NextUID.ToString("000")
                    Else
                        '--If the Next UserID number is greater than 100, just keep as an integer, no need to
                        '--Convert to a string
                        UID.Attributes("UID").Value = NextUID
                        NewDeptUID = NextUID
                        Exit For
                    End If
                End If
            Next
        Catch ex As Exception
            MessageBox.Show("Missing NextUID Number in Users.ULA File, Contact your Administrator.", "File Error")
            'UserApplicationForm.lblNotification.Text = "An Error has occurred - Contact your Administrator"
            Me.Close()
        End Try
    End Sub
Any help would be greatly appreciated as I'm getting frustrated.