Express Entry:Visual BASIC

From Melissa Data Wiki
Jump to: navigation, search

← Express Entry Reference

Express Entry Navigation
Introduction
Getting Started
Global Getting Started
Global Terms
Endpoints
ExpressAddress
ExpressCityState
ExpressFreeForm
ExpressPostalCode
ExpressStreet
GlobalExpressAddress
GlobalExpressCountry
GlobalExpressLocalityAdministrativeArea
GlobalExpressFreeForm
GlobalExpressPostalCode
GlobalExpressThoroughfare
Response
XML Response
JSON Response
Global XML Response
Global JSON Response
Token Server
Result Codes
Express Entry Result Codes
Sample Code
US CSharp
US JavaScript
US Visual BASIC
Global CSharp
Global JavaScript
Token Server Support



US REST Visual BASIC Sample Project


US REST Visual BASIC Sample Code

Imports System.Web
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.XmlWriter
Imports System.Xml.Serialization


Public Class Form1

  Dim isInitialized As Boolean = False
  Dim request As HttpWebRequest
  Dim response As HttpWebResponse = Nothing
  Dim responseReader As Stream
  Dim address As Uri
  Dim tServer As String
  Dim xmlDoc As XmlDocument
  Dim rootNode As New System.Xml.XmlDocument
  Dim Tempstr(7) As String

  '***************************************************************************
  ' Function to Initialize DQWS V2 REST
  '****************************************************************************
  Private Sub TextAddress_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextAddress.KeyUp

    If isInitialized = False Then
      'txtResults.Text = ""
      'Set up column labels and initialize
      ListView1.Columns.Add("Address", 140)
      ListView1.Columns.Add("City", 100)
      ListView1.Columns.Add("State", 50)
      ListView1.Columns.Add("Zip Code", 100)
      ListView1.FullRowSelect = True

      'Set up the list view to display City, State, and ZIP Code correctly
      ListView1.ShowItemToolTips = True
      ListView1.View = View.Details

      isInitialized = True
    Else
      ListView1.Items.Clear()
      txtResults.Clear()

      ' Set the Server URL to the form input
      tServer = "https://expressentry.melissadata.net/web/ExpressFreeForm"

      'use escape codes with License Keys, or the server will not respond to pluses and other characters
      Dim auth As String
      auth = Uri.EscapeDataString(TxtCustID.Text)
      tServer += "?id=" + auth
      tServer += "&ff=" + TextAddress.Text
      tServer += "&maxrecords=" + txtMaxMatches.Text
      tServer += "&format=XML"

      address = New Uri(tServer)

      'Create the web request
      request = DirectCast(WebRequest.Create(address), HttpWebRequest)

      ' Get response  
      response = DirectCast(request.GetResponse(), HttpWebResponse)

      ' Get the response stream into a reader  
      responseReader = response.GetResponseStream()

      Dim outXML As XmlTextWriter
      outXML = New XmlTextWriter("response.xml", Nothing)

      xmlDoc = New XmlDocument
      xmlDoc.Load(responseReader)
      xmlDoc.Save(outXML)
      outXML.Close()

      ' Load root node of the XML Response
      rootNode.Load("response.xml")

      PopulateNodes(rootNode)

      response.Close()
      responseReader.Close()

    End If

  End Sub

  '***************************************************************************
  ' Functions to Populate The Output Fields
  '****************************************************************************
  ' Populate Output Fields that have existing nodes
  Public Function Add(ByVal theNode As XmlNode)

    If (theNode.ParentNode.Name = "ResultCode") Then

      '**********************************************************************************
      ' Block to Handle Different Error Codes and Status Codes in each Record
      '**********************************************************************************
      Dim errorCodeString As String = theNode.Value
      Dim errorCodeList As String() = Nothing
      Dim errorCode As String

      errorCodeList = errorCodeString.Split(",")
      For Each errorCode In errorCodeList

        If (errorCode = "CS00") Then
          txtResults.Text += errorCode + ": Search returned at least one result; "
        ElseIf (errorCode = "GE01") Then
          txtResults.Text += errorCode + ": Empty XML Request Structure; "
        ElseIf (errorCode = "GE02") Then
          txtResults.Text += errorCode + ": Empty XML Request Record Structure; "
        ElseIf (errorCode = "GE03") Then
          txtResults.Text += errorCode + ": Counted records send more than number of records allowed per request; "
        ElseIf (errorCode = "GE04") Then
          txtResults.Text += errorCode + ": License Key empty; "
        ElseIf (errorCode = "GE05") Then
          txtResults.Text += errorCode + ": License Key not valid; "
        ElseIf (errorCode = "GE06") Then
          txtResults.Text += errorCode + ": License Key disabled; "
        ElseIf (errorCode = "GE07") Then
          txtResults.Text += errorCode + ": XML Request invalid; "
        ElseIf (errorCode = "GE08") Then
          txtResults.Text += errorCode + ": License Key is not valid for this product; "
        ElseIf (errorCode = "SE01") Then
          txtResults.Text += errorCode + ": Authorization check failed; "

        ElseIf (errorCode = "CE00") Then
          txtResults.Text += errorCode + ": Search completed, no results found; "
        ElseIf (errorCode = "CE01") Then
          txtResults.Text += errorCode + ": Search failed because of a bad setup (mdHints UE01); "
        ElseIf (errorCode = "CE02") Then
          txtResults.Text += errorCode + ": Search failed because of a search error (mdHints UE02); "
        End If

      Next errorCode
      ' End of Error Handling
      '*********************************************************************************
    ElseIf (theNode.ParentNode.Name = "AddressLine1") Then
      Tempstr(0) = theNode.Value
    ElseIf (theNode.ParentNode.Name = "City") Then
      Tempstr(1) = theNode.Value
    ElseIf (theNode.ParentNode.Name = "State") Then
      Tempstr(2) = theNode.Value
    ElseIf (theNode.ParentNode.Name = "PostalCode") Then
      Tempstr(3) = theNode.Value
      ''Upon receiving PostalCode, populate the ListView
      'Dim itm As ListViewItem
      'itm = New ListViewItem(Tempstr)
      'ListView1.Items.Add(itm)
    ElseIf (theNode.ParentNode.Name = "SuiteName") Then
      Tempstr(4) = theNode.Value
      'ElseIf (theNode.ParentNode.Name = "SuiteRange") Then
      '  Tempstr(5) = theNode.Value
    ElseIf (theNode.ParentNode.Name = "SuiteCount") Then
      Dim itm As ListViewItem
      itm = New ListViewItem(Tempstr)
      ListView1.Items.Add(itm)
      'Clear Suite information for those that have none
      Tempstr(4) = ""
      Tempstr(5) = ""
      Tempstr(6) = ""
    End If

  End Function


  ' Populate the Node List through a Recursive Call from the root
  Public Sub PopulateNodes(ByVal xml As XmlDocument)
    For Each xmlnode As XmlNode In xml
      SearchRecord(xmlnode)
    Next
  End Sub

  ' Search for Current Record In the Record List
  Public Sub SearchRecord(ByVal xml As XmlNode)

    'For Each parentNode As XmlNode In xml.ChildNodes
    For Each xmlNode As XmlNode In xml

      If (xmlNode.Name = "ResultCode") And (xmlNode.HasChildNodes) Then
        '***********************************************************************
        ' Block to Handle Different Error Codes in Initialization Results
        Dim errorCodeString As String = xmlNode.FirstChild.Value
        Dim errorCodeList As String() = Nothing
        Dim errorCode As String

        errorCodeList = errorCodeString.Split(",")

        For Each errorCode In errorCodeList

          If (errorCode = "SE01") Then
            txtResults.Text += errorCode + ": Authorization check failed; "
          ElseIf (errorCode = "GE01") Then
            txtResults.Text += errorCode + ": Empty XML Request Structure; "
          ElseIf (errorCode = "GE02") Then
            txtResults.Text += errorCode + ": Empty XML Request Record Structure; "
          ElseIf (errorCode = "GE03") Then
            txtResults.Text += errorCode + ": Counted records send more than number of records allowed per request; "
          ElseIf (errorCode = "GE04") Then
            txtResults.Text += errorCode + ": License Key empty; "
          ElseIf (errorCode = "GE05") Then
            txtResults.Text += errorCode + ": License Key not valid; "

          ElseIf (errorCode = "GE06") Then
            txtResults.Text += errorCode + ": License Key disabled; "
          ElseIf (errorCode = "GE07") Then
            txtResults.Text += errorCode + ": XML Request invalid; "
          ElseIf (errorCode = "CS00") Then
            txtResults.Text = errorCode + ": Search returned at least one result; "
          ElseIf (errorCode = "GE08") Then
            txtResults.Text += errorCode + ": License Key is not valid for this product; "

          ElseIf (errorCode = "CE00") Then
            txtResults.Text += errorCode + ": Search completed, no results found; "
          ElseIf (errorCode = "CE01") Then
            txtResults.Text += errorCode + ": Search failed because of a bad setup (mdHints UE01); "
          ElseIf (errorCode = "CE02") Then
            txtResults.Text += errorCode + ": Search failed because of a search error (mdHints UE02); "
          ElseIf (errorCode = "XS01") Then
            txtResults.Text += errorCode + ": Complete Result Set Returned"
          ElseIf (errorCode = "XS02") Then
            txtResults.Text += errorCode + ": Partial set of results returned"
          ElseIf (errorCode = "XS03") Then
            txtResults.Text += errorCode + ": Search completed - no results found"
          End If
          ' Did not Initialize
          'isInitialized = False
          'Exit Sub

        Next errorCode

      ElseIf (xmlNode.Name = "Results") And (xmlNode.HasChildNodes) Then

        PopulateSubNodes(xmlNode)

      End If

    Next
  End Sub

  ' Populate all Sub Nodes below the chosen Record Node
  Public Sub PopulateSubNodes(ByVal parentxmlnode As XmlNode)
    For Each node As XmlNode In parentxmlnode
      Add(node)
      PopulateSubNodes(node)
    Next

  End Sub


  Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    If ListView1.SelectedItems.Count > 0 Then

      TextAddress.Text = ListView1.SelectedItems(0).SubItems(0).Text
      TxtCity.Text = ListView1.SelectedItems(0).SubItems(1).Text
      TxtState.Text = ListView1.SelectedItems(0).SubItems(2).Text
      TxtZIP.Text = ListView1.SelectedItems(0).SubItems(3).Text

      'Formerly suite support
      'If Not ListView1.SelectedItems(0).SubItems(0).Text.Equals("") Then

      'Add Suite List
      'Dim suiteList As String()
      'suiteList = ListView1.SelectedItems(0).SubItems(5).Text.Split(",")
      'For Each suite As String In suiteList

      'comboBox1.Items.Add(suite)
      'ComboBox1.SelectedIndex = 0

      'Next

      'End If
    End If


  End Sub

  Private Sub TxtCustID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCustID.TextChanged

  End Sub

  Private Sub txtMaxMatches_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaxMatches.TextChanged

  End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  End Sub

  Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

  End Sub

  Private Sub txtResults_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtResults.TextChanged

  End Sub

  Private Sub TextAddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextAddress.TextChanged

  End Sub
End Class

Personal tools
Namespaces

Variants
Actions
Navigation
Products
Support