Question

Convert VBS to VB.net/VB 2008

Asked by: jcamping

I need the attached VBS converted to VB.NET or VB 2008. Any takers?

'=========================
' Get_Warranty_Info_On_HP_Equipment_From_Service_Tag.vbs
' http://www.experts-exchange.com/Programming/Languages/Q_23097377.html
 
strInputFile = "HPSerialNumbers.txt"
strOutputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Results.csv"
 
arrTextToSearchFor = Array("Warranty Type","HWM Onsite")
 
arrJoinFields = Array("Serial Number","Product Number","Product Description","Date of Warranty Check","Warranty Type","Start Date","HP Care Pack Serial Number","HWM Onsite","Status","End Date","Service Level","Deliverables","6-Hour, 24x7, Call-To-Repair, HW Support","Wty: HP HW Maintenance Onsite Support","Wty: HP Support for Initial Setup")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
 
strDetails = """WARRANTY INFORMATION"""
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
      arrLine = Split(objInputFile.ReadLine, ";")
      strProductNumber = arrLine(0)
      strSerialNumber = arrLine(1)
      strURL = "http://www11.itrc.hp.com/service/ewarranty/warrantyResults.do?BODServiceID=NA&serialNumber10=&RegisteredPurchaseDate=&y=11&x=26&serialNumber4=&country=IN&serialNumber9=&serialNumber5=&serialNumber6=&serialNumber7=&serialNumber8=&serialNumber1=" & strSerialNumber & "&serialNumber2=&serialNumber3=&productNumber=" & strProductNumber & "&hpweb_printable=true"
      Set objIE = CreateObject("InternetExplorer.Application")
      objIE.Visible = True
      objIE.Navigate strURL
      While objIE.ReadyState <> 4
            WScript.Sleep 100
      Wend
      
      strPageText = objIE.Document.Body.InnerHTML
      'WScript.Echo strPageText
 
      ' Reset the text for the current product
      strCurrentProduct = ""
 
      For Each strSearchText In arrTextToSearchFor
            intSummaryPos = InStr(LCase(strPageText), LCase(strSearchText))
            If intSummaryPos > 0 Then
                  intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
                  intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
                  strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
                  strInfoTable = Replace(Replace(Replace(strInfoTable, VbCrLf, ""), vbCr, ""), vbLf, "")
                  strInfoTable = Replace(strInfoTable, "<BR>", VbLf)
                  'WScript.Echo strInfoTable
                  arrCells = Split(LCase(strInfoTable), "</td>")
                  For intCell = LBound(arrCells) To UBound(arrCells)
                        arrCells(intCell) = Trim(arrCells(intCell))
                        intOpenTag = InStr(arrCells(intCell), "<")
                        While intOpenTag > 0
                              intCloseTag = InStr(intOpenTag, arrCells(intCell), ">") + 1
                              strNewCell = ""
                              If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Left(arrCells(intCell), intOpenTag - 1))
                              If intCloseTag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intCloseTag))
                              arrCells(intCell) = Trim(strNewCell)
                              intOpenTag = InStr(arrCells(intCell), "<")
                        Wend
                  Next
                  'WScript.Echo Join(arrCells, "|")
                  strCurrentProduct = strCurrentProduct & Join(arrCells, "|")
                  strCurrentProduct = Replace(strCurrentProduct, "||", "|")
                  'strCurrentProduct = Replace(Replace(Replace(strCurrentProduct, "||", "|"), VbCrLf & "|", "|"), "|" & VbCrLf, "|")
                  If Left(strCurrentProduct, 1) = "|" Then strCurrentProduct = Right(strCurrentProduct, Len(strCurrentProduct) - 1)
                  If Right(strCurrentProduct, 1) = "|" Then strCurrentProduct = Left(strCurrentProduct, Len(strCurrentProduct) - 1)
                  If LCase(arrCells(0)) = LCase("Service Tag:") Then
                        'strCurrentTag = """" & strServiceTag & """"
                        strCurrentTag = ""
                        For intField = 1 To UBound(arrCells) Step 2
                              If strCurrentTag = "" Then
                                    strCurrentTag = """" & arrCells(intField) & """"
                              Else
                                    strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
                              End If
                        Next
                  ElseIf LCase(arrCells(0)) = LCase("Description") Then
                        For intField = 5 To UBound(arrCells)
                              strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
                        Next
                  End If
            Else
                  strCurrentTag = """" & strServiceTag & """,""No warranty information found."""
            End If
      Next
      'WScript.Echo strCurrentProduct
      If InStr(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number") > 0 Then _
            strCurrentProduct = Replace(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number", "hp care pack serial number")
      arrCells = Split(strCurrentProduct, "|")
      strJoinFields = ";" & Join(arrJoinFields, ";") & ";"
      For Each strCell In arrCells
            strCell = ProperCase_Words(strCell)
            If InStr(LCase(strJoinFields), ";" & LCase(strCell) & ";") > 0 Then
                  strDetails = strDetails & VbCrLf & """" & strCell & """"
            Else
                  'strDetails = Left(strDetails, Len(strDetails) - 1) & ": " & strCell & """"
                  strDetails = Left(strDetails, Len(strDetails) - 1) & """,""" & strCell & """"
            End If
      Next
      strDetails = strDetails & VbCrLf & VbCrLf & "==========================" & VbCrLf
      objIE.Quit
Wend
objInputFile.Close
Set objInputFile = Nothing
 
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run """" & strOutputFile & """", 1, False
'MsgBox "Done. Please see " & strOutputFile
 
Function ProperCase_Words(strText)
      If IsNumeric(Left(strText, 1)) = False Then
            strText = UCase(Left(strText, 1)) & Mid(strText, 2)
      End If
 
      intPos = InStr(strText, " ")
      Do
            If IsNumeric(Mid(strText, intPos + 1, 1)) = False Then
                  strText = Left(strText, intPos) & UCase(Mid(strText, intPos + 1, 1)) & Mid(strText, intPos + 2)
            End If
            intPos = InStr(intPos + 1, strText, " ")
            If intPos > Len(strText) - 1 Then Exit Do
      Loop While intPos > 0
 
      ProperCase_Words = strText
End Function
'=========================

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-13 at 16:05:04ID24809647
Tags

HP

,

Warranty

,

check

,

vbs

,

vb.net

Topics

VB Script

,

Visual Basic Programming

,

.NET

Participating Experts
2
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. convert vb.net to vb script
    I have created a working VB.net app but now would like to created a VB script that does the same function. is there a way to convet VB.net code to VB script? is there an app that I can download and use? The purpose of this app is to list a group of printers that are on a prin...
  2. VB to VB.NET
    I need to convert the following code from VB6 to VB.NET #If DEBUGWINDOWPROC Then Private m_SCHook As WindowProcHook #End If #If DEBUGWINDOWPROC Then On Error Resume Next Set m_SCHook = CreateWindowProcHook #End If I'm stumped at the WindowProcHook clas...
  3. VB.net and VB
    Hi, If I have a good book for teaching visual basic, can I use it to learn VB.net or there is a total difference between vb and vb.net? Thanks
  4. convert vb.net to vb classic
    i am sure ... many people want to convert vb classic in new vb.net.. But i want to cobvert a code in vb.net to vb classic! Existis a free tool to od thath? I have see many time ago a site to onverrt on line but dont remember where... Help me please.
  5. convert code vb.net to vb classic
    i am sure ... many people want to convert vb classic in new vb.net.. But i want to convert a code in vb.net to vb classic! Existis a free tool to od thath? I have see many time ago a site to onverrt on line but dont remember where... Help me please.
  6. vb or vb.net
    short answer, what is vb.net is it better than old vb? is more like C?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: TheLearnedOnePosted on 2009-10-14 at 05:15:49ID: 25569578

It might be easier if you explained what this code does (and what your question is), since E-E is usually about answering questions, and not a free-coder system.

 

by: Arthur_WoodPosted on 2009-10-14 at 06:50:44ID: 25570424

And, in addition, converting VBS to VB.NET is generally a non-trival exercise, and the direct converion usually creates more problems than it solves.  VBS is generally not written on an Object oriented manner, and the conversion to an OO language such as VB,Net does not make use of the VB.NET capabilities.

In addition, that is quite a bit of code, and you are asking one of us to do this for FREE.  I doubt that there are many altruistic 'experts' here, who would be willing to do this out of the kindness of their hearts.  We are all volunteers, and contribute our knowledge and expertise to this site when we are not otherwise engaged in our professional responsibilities.  And since we do not have access to the operating environment in which this code would be executed, testing any conversion would be problematic, at best.

AW

 

by: jcampingPosted on 2009-10-14 at 08:17:11ID: 25571527

OK, sorry about that. The code is supposed to retreive warranty info from HP's support site. It retreives the PN and SN from a txt file, sends it to the webpage and populates a CSV file with the results. When I tried translating it, I can't get it to populate the CSV with any of the info. This is what it gives me:
      
      </TBODY></TABLE>/tbody></table>
      
==========================      

I've attached what I came up with, that gives me the above results. Any ideas as to how to get it to work correctly in .NET?

'=========================
        ' Get_Warranty_Info_On_HP_Equipment_From_Service_Tag.vbs
        ' http://www.experts-exchange.com/Programming/Languages/Q_23097377.html
        Dim strInputFile, strOutputFile, objFSO, strDetails, arrLine, strProductNumber, strSerialNumber, strURL
        Dim objIE, strPageText, strCurrentProduct, strSearchText, intSummaryPos, intSummaryTableStart, intSummaryTableEnd
        Dim strInfoTable, arrCells, intCell, intOpenTag, intCloseTag, strNewCell, strCurrentTag, intField, strServiceTag
        Dim strJoinFields, strCell, objOutputFile, objShell
        strInputFile = "RN040AW#ABA;CNU7050TSR"
        strOutputFile = "Results.csv"
        strCurrentTag = ""
        strServiceTag = ""
        Dim arrTextToSearchFor() = {"Warranty Type", "HWM Onsite"}
 
        Dim arrJoinFields() = {"Serial Number", "Product Number", "Product Description", "Date of Warranty Check", "Warranty Type", "Start Date", "HP Care Pack Serial Number", "HWM Onsite", "Status", "End Date", "Service Level", "Deliverables", "6-Hour, 24x7, Call-To-Repair, HW Support", "Wty: HP HW Maintenance Onsite Support", "Wty: HP Support for Initial Setup"}
 
        objFSO = CreateObject("Scripting.FileSystemObject")
        'Const intForReading = 1
 
        strDetails = """WARRANTY INFORMATION"""
        'Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
        'While Not objInputFile.AtEndOfStream
        arrLine = Split(strInputFile, ";")
        strProductNumber = arrLine(0)
        strSerialNumber = arrLine(1)
        strURL = "http://www11.itrc.hp.com/service/ewarranty/warrantyResults.do?BODServiceID=NA&serialNumber10=&RegisteredPurchaseDate=&y=11&x=26&serialNumber4=&country=IN&serialNumber9=&serialNumber5=&serialNumber6=&serialNumber7=&serialNumber8=&serialNumber1=" & strSerialNumber & "&serialNumber2=&serialNumber3=&productNumber=" & strProductNumber & "&hpweb_printable=true"
        objIE = CreateObject("InternetExplorer.Application")
        objIE.Visible = True
        objIE.Navigate(strURL)
        'While objIE.ReadyState <> 4
        'WScript.Sleep(100)
        'End While
 
        strPageText = objIE.Document.Body.InnerHTML
        'WScript.Echo strPageText
 
        ' Reset the text for the current product
        strCurrentProduct = ""
 
        For Each strSearchText In arrTextToSearchFor
            intSummaryPos = InStr(LCase(strPageText), LCase(strSearchText))
            If intSummaryPos > 0 Then
                intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
                intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
                strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
                strInfoTable = Replace(Replace(Replace(strInfoTable, vbCrLf, ""), vbCr, ""), vbLf, "")
                strInfoTable = Replace(strInfoTable, "<BR>", vbLf)
                'WScript.Echo strInfoTable
                arrCells = Split(LCase(strInfoTable), "</td>")
                For intCell = LBound(arrCells) To UBound(arrCells)
                    arrCells(intCell) = Trim(arrCells(intCell))
                    intOpenTag = InStr(arrCells(intCell), "<")
                    While intOpenTag > 0
                        intCloseTag = InStr(intOpenTag, arrCells(intCell), ">") + 1
                        strNewCell = ""
                        If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intOpenTag - 1))
                        If intCloseTag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intCloseTag))
                        arrCells(intCell) = Trim(strNewCell)
                        intOpenTag = InStr(arrCells(intCell), "<")
                    End While
                Next
                'WScript.Echo Join(arrCells, "|")
                strCurrentProduct = strCurrentProduct & Join(arrCells, "|")
                strCurrentProduct = Replace(strCurrentProduct, "||", "|")
                'strCurrentProduct = Replace(Replace(Replace(strCurrentProduct, "||", "|"), VbCrLf & "|", "|"), "|" & VbCrLf, "|")
                If Mid(strCurrentProduct, 1) = "|" Then strCurrentProduct = Mid(strCurrentProduct, Len(strCurrentProduct) - 1)
                If Mid(strCurrentProduct, 1) = "|" Then strCurrentProduct = Mid(strCurrentProduct, Len(strCurrentProduct) - 1)
                If LCase(arrCells(0)) = LCase("Service Tag:") Then
                    'strCurrentTag = """" & strServiceTag & """"
                    strCurrentTag = ""
                    For intField = 1 To UBound(arrCells) Step 2
                        If strCurrentTag = "" Then
                            strCurrentTag = """" & arrCells(intField) & """"
                        Else
                            strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
                        End If
                    Next
                ElseIf LCase(arrCells(0)) = LCase("Description") Then
                    For intField = 5 To UBound(arrCells)
                        strCurrentTag = strCurrentTag & ",""" & arrCells(intField) & """"
                    Next
                End If
            Else
                strCurrentTag = """" & strServiceTag & """,""No warranty information found."""
            End If
        Next
        'WScript.Echo strCurrentProduct
        If InStr(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number") > 0 Then _
              strCurrentProduct = Replace(strCurrentProduct, "hpcare pack serial numberhpcare pack serial number", "hp care pack serial number")
        arrCells = Split(strCurrentProduct, "|")
        strJoinFields = ";" & Join(arrJoinFields, ";") & ";"
        For Each strCell In arrCells
            strCell = ProperCase_Words(strCell)
            If InStr(LCase(strJoinFields), ";" & LCase(strCell) & ";") > 0 Then
                strDetails = strDetails & vbCrLf & """" & strCell & """"
            Else
                'strDetails = Left(strDetails, Len(strDetails) - 1) & ": " & strCell & """"
                strDetails = Mid(strDetails, Len(strDetails) - 1) & """,""" & strCell & """"
            End If
        Next
        strDetails = strDetails & vbCrLf & vbCrLf & "==========================" & vbCrLf
        objIE.Quit()
        'Wend
        'objInputFile.Close
        'Set objInputFile = Nothing
 
        objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
        objOutputFile.Write(strDetails)
        objOutputFile.Close()
        objOutputFile = Nothing
        objFSO = Nothing
 
        objShell = CreateObject("WScript.Shell")
        objShell.Run("""" & strOutputFile & """", 1, False)
        'MsgBox "Done. Please see " & strOutputFile

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:

Select allOpen in new window

 

by: TheLearnedOnePosted on 2009-10-14 at 08:20:02ID: 25571556

Screen scraping to get HTML response in .NET is accomplished with an HttpWebRequest.  It gets more complicated if you have cookies, need to pass certificates to an HTTPS URL, etc., but still achievable.

Example:

Imports System.Net
Imports System.IO
 
Public Class WebPages
 
  Public Shared Function GetPageText(ByVal url As String) As String
 
    ' Create a request to myIPaddress.com.
    Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
 
    ' Set time out to 10 seconds.
    request.Timeout = 10000
 
    ' Get the response from the server.
    Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
 
      ' Get the text stream.
      Using stream As Stream = response.GetResponseStream()
 
        ' Create a reader to access the text stream.
        Using readerText As New StreamReader(stream)
 
          ' Get the text from the stream.
          Return readerText.ReadToEnd()
        End Using
      End Using
    End Using
 
  End Function
 
End Class

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:

Select allOpen in new window

 

by: jcampingPosted on 2009-10-14 at 09:14:51ID: 25572176

That works great! I used the attached code to make use of the code you gave me and then extract the line I need.

Dim strSerialNumber, strProductNumber
        'strInputFile = "RN040AW#ABA;CNU7050TSR"
        strSerialNumber = "CNU7050TSR"
        strProductNumber = "RN040AW#ABA"
        My.Computer.FileSystem.WriteAllText("C:\temp\webresults.txt", WebPages.GetPageText("http://www11.itrc.hp.com/service/ewarranty/warrantyResults.do?BODServiceID=NA&serialNumber10=&RegisteredPurchaseDate=&y=11&x=26&serialNumber4=&country=IN&serialNumber9=&serialNumber5=&serialNumber6=&serialNumber7=&serialNumber8=&serialNumber1=" & strSerialNumber & "&serialNumber2=&serialNumber3=&productNumber=" & strProductNumber & "&hpweb_printable=true"), True)
        Dim lines As String() = System.IO.File.ReadAllLines("C:\temp\webresults.txt")
        '12th line is at index 11 - arrays are 0-based.
        '34th character is at index 33 - strings are also 0-based.
        Dim Warranty_end As String = Replace(lines(870), vbTab, "")
 
        MsgBox(Warranty_end)

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: jcampingPosted on 2009-10-14 at 09:16:24ID: 31640823

Sorry again for the "it don't work" question. I should have known better than to just post some code and say "fix it".

 

by: TheLearnedOnePosted on 2009-10-14 at 09:27:51ID: 25572328

If you can depend on the result always being on the same line, then what you have shown would work.  But, if I know anything about software development, is that you can't depend on something being static.  It would be better if you parsed through the HTML to find the right element.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...