Results 1 to 3 of 3

Thread: Dell Warranty

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    17

    Dell Warranty

    Hi, hope someone can help

    I have the following working function to retrieve the Dell "Ship Date" from the dell Website, which can be found here

    This works fine when the Warranty info is formatted with one line stating
    "Next Business Day"

    however returns a null when the Warranty info has more than one line, for example

    "Next Business Day"
    "Dell Business Support / ProSupport"

    Two example links

    One Line

    Two Lines

    [/URL]
    VB Code:
    1. Function GetWarranty(ByVal strCurrentTag)
    2.         Dim objHTTP, strPageText, strURL, strHeading
    3.         Dim intSummaryPos, intSummaryTableStart, intSummaryTableEnd, strInfoTable, arrCells, intCell, intOpenTag, intClosetag
    4.         'Dim strNewCell, strCurrentTag, i, intField
    5.         Dim strNewCell, i, intField, strShipDate
    6.         Dim arrHeadings() = {"Service Tag:", "Days Left"}
    7.  
    8.         objHTTP = CreateObject("Msxml2.XMLHTTP")
    9.         Dim strField(400)
    10.         strField(0) = Now
    11.         strPageText = ""
    12.         strURL = "http://supportapj.dell.com/support/topics/topic.aspx/ap/shared/support/my_systems_info/en/details?c=in&cs=inbsd1&l=en&s=bsd&ServiceTag=" & strCurrentTag & "&~tab=1"
    13.         'strURL = "http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=k12&servicetag=" & strCurrentTag
    14.         objHTTP.open("GET", strURL, False)
    15.         objHTTP.send()
    16.         strPageText = objHTTP.responseText
    17.         'MsgBox(arrHeadings.Length)
    18.  
    19.         For Each strHeading In arrHeadings
    20.             intSummaryPos = InStr(LCase(strPageText), LCase(strHeading))
    21.             If intSummaryPos > 0 Then
    22.                 intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
    23.                 intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
    24.                 strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
    25.                 strInfoTable = Replace(Replace(Replace(strInfoTable, vbCrLf, ""), vbCr, ""), vbLf, "")
    26.                 arrCells = Split(LCase(strInfoTable), "</td>")
    27.  
    28.                 For intCell = LBound(arrCells) To UBound(arrCells)
    29.                     arrCells(intCell) = Trim(arrCells(intCell))
    30.                     intOpenTag = InStr(arrCells(intCell), "<")
    31.  
    32.                     While intOpenTag > 0
    33.                         intClosetag = InStr(intOpenTag, arrCells(intCell), ">") + 1
    34.                         strNewCell = ""
    35.                         'If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Left(arrCells(intCell), intOpenTag - 1))
    36.                         If intClosetag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intClosetag))
    37.  
    38.                         arrCells(intCell) = Replace(Trim(strNewCell), " &nbsp;&nbsp;&nbsp;&nbsp;change service tag", "")
    39.                         intOpenTag = InStr(arrCells(intCell), "<")
    40.  
    41.                     End While
    42.                 Next
    43.  
    44.                 If LCase(arrCells(0)) = LCase("Service Tag:") Then
    45.                     strCurrentTag = ""
    46.  
    47.                     i = 0
    48.  
    49.                     For intField = 1 To UBound(arrCells) Step 2
    50.                         i = i + 1
    51.                         strField(i) = arrCells(intField)
    52.                     Next
    53.  
    54.                 ElseIf LCase(arrCells(0)) = LCase("Description") Then
    55.                     i = 0
    56.  
    57.                     For intField = 5 To UBound(arrCells)
    58.                         strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
    59.                         i = i + 1
    60.                         strField(i) = arrCells(intField)
    61.                     Next
    62.                 End If
    63.  
    64.             Else
    65.  
    66.                 strShipDate = "No Info"
    67.                 Return strShipDate
    68.  
    69.                 End
    70.  
    71.             End If
    72.         Next
    73.  
    74.         strShipDate = strField(8)
    75.  
    76.         Return (strShipDate)
    77.  
    78.     End Function

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Dell Warranty

    Try this (tested and worked for both links):
    Code:
    Imports System.Text.RegularExpressions
    Imports System.Net
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) _
                                  Handles Button1.Click
            MessageBox.Show("Ship Date: " & DellSite.GetShipDate("9rr7g4j"))
            MessageBox.Show("Ship Date: " & DellSite.GetShipDate("bh11y1j"))
        End Sub
    
    End Class
    
    Public Class DellSite
    
        '//fields
        Protected Shared ReadOnly ShipDatePattern As Regex
        Protected Shared ReadOnly BaseServiceUrl As String
    
        '//constructors
        Shared Sub New()
            DellSite.ShipDatePattern = New Regex("\>ship\s+date\:\<\/td\>\<[^>]*>(?<shipDate>\d*\/\d*\/\d*)\<", _
                                         RegexOptions.Compiled Or RegexOptions.IgnoreCase)
            DellSite.BaseServiceUrl = "http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=k12&servicetag="
        End Sub
    
        Private Sub New()
        End Sub
    
        '//methods
        ''' <summary>
        ''' Gets the ship date of the specified service tag.
        ''' </summary>
        ''' <param name="serviceTag">The service tag to get.</param>
        Public Shared Function GetShipDate(ByVal serviceTag As String) As String
            Using client = New WebClient()
                Dim source = client.DownloadString(String.Format("{0}{1}", _
                                                   DellSite.BaseServiceUrl, serviceTag))
                If Not String.IsNullOrEmpty(source) Then
                    Dim match = DellSite.ShipDatePattern.Match(source)
                    If match.Success Then
                        Return match.Groups("shipDate").Value
                    End If
                End If
            End Using
            Return String.Empty
        End Function
    
    End Class
    

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    17

    Re: Dell Warranty

    Thanks ForumAccount

    Using Webclient seems to have sorted it and looks much neater

    i did have to have the following 2 lines but thats only because i sit behind a proxy server

    VB Code:
    1. client.Proxy = System.Net.WebRequest.DefaultWebProxy
    2. client.Proxy.Credentials = stem.Net.CredentialCache.DefaultCredentials

    thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width