Hello and welcome to devshed.
Just to let you know you can wrap your code in [ Code ] tags and it will format it nicer.
A lot of it depends on the type of exception being thrown but I would guess it's related to the firstname.IndexOf(name) line. You're calling a function on firstName before firstName has been set to anything (although if IndexOf is a static method it might not matter.)
Dim name As String = txtName.Text 'full name
Dim firstname, lastname As String 'First and Last
Dim zip As String = txtCity.Text 'Zip
Dim n As Integer = name.IndexOf(",")
Dim length As Integer = -4
lastname = name.Substring(n, 1)
length = zip.Length
Dim invoice As String = firstname & lastname & CStr(length)