Problem, villeicht ein Denkfehler, Bitte um Hilfe :)

  • VBScript

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Marcus Gräfe.

    Problem, villeicht ein Denkfehler, Bitte um Hilfe :)

    Hallo

    Ich habe ein VBScript in Visual Basic umgewandelt.
    Das Problem ist jetzt, dass wenn ich ein Arrayliste mache und dann in die For Each schleife einbinde, funktionirt das nicht.

    Hoffe ihr könnt mir helfen.

    Gruss


    Visual Basic Code:
    Spoiler anzeigen

    Visual Basic-Quellcode

    1. Dim strinputFile As String = eingegebenetags
    2. Dim strOutputFile As String = ""
    3. Dim strDetails As String = ""
    4. Dim strCurrentTag As String = ""
    5. Dim strurl As String = "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=" & strServiceTag & "&~tab=1"
    6. Dim webClient As System.Net.WebClient = New System.Net.WebClient()
    7. Dim results As String
    8. Dim startpage As String
    9. Dim arraylist As List(Of String) 'arrheadings = Array("Service Tag:", "Days Left") <---- Das ist der VBScript Code
    10. arraylist.Add("Service Tag:")
    11. arraylist.Add("Days Left")
    12. Const intForReading = 1
    13. results = webClient.DownloadString(strurl)
    14. For Each strHeading In arraylist
    15. intSummaryPos = InStr(LCase(strPageText), LCase(strHeading))
    16. If intSummaryPos > 0 Then
    17. intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
    18. intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
    19. strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
    20. strInfoTable = Replace(Replace(Replace(strInfoTable, vbCrLf, ""), vbCr, ""), vbLf, "")
    21. arrCells = Split(LCase(strInfoTable), "</td>")
    22. For intCell = LBound(arrCells) To UBound(arrCells)
    23. arrCells(intCell) = Trim(arrCells(intCell))
    24. intOpenTag = InStr(arrCells(intCell), "<")
    25. While intOpenTag > 0
    26. intCloseTag = InStr(intOpenTag, arrCells(intCell), ">") + 1
    27. strNewCell = ""
    28. If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Left(arrCells(intCell), intOpenTag - 1))
    29. If intCloseTag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intCloseTag))
    30. arrCells(intCell) = Replace(Trim(strNewCell), " &nbsp;&nbsp;&nbsp;&nbsp;change service tag", "")
    31. intOpenTag = InStr(arrCells(intCell), "<")
    32. End While
    33. Next
    34. 'WScript.Echo Join(arrCells, "|")
    35. If LCase(arrCells(0)) = LCase("Service Tag:") Then
    36. 'strCurrentTag = """" & strServiceTag & """"
    37. strCurrentTag = ""
    38. For intField = 1 To UBound(arrCells) Step 2
    39. If strCurrentTag = "" Then
    40. strCurrentTag = " " & arrCells(intField) & " "
    41. Else
    42. strCurrentTag = strCurrentTag & ";" & arrCells(intField) & ""
    43. End If
    44. Next
    45. ElseIf LCase(arrCells(0)) = LCase("Description") Then
    46. For intField = 5 To UBound(arrCells)
    47. strCurrentTag = strCurrentTag & ";" & arrCells(intField) & ""
    48. Next
    49. End If
    50. Else
    51. strCurrentTag = """" & strServiceTag & """ ""No warranty information found."""
    52. End If
    53. Next
    54. strDetails = strDetails & strCurrentTag & vbCrLf & "#"
    55. strOutputFile = strDetails


    VBScript
    Spoiler anzeigen

    Quellcode

    1. strInputFile = "DellServiceTags.txt"
    2. strOutputFile = "Results.csv"
    3. arrHeadings = Array("Service Tag:", "Days Left")
    4. Set objFSO = CreateObject("Scripting.FileSystemObject")
    5. Const intForReading = 1
    6. Set objHTTP = CreateObject("MSXML2.serverXMLHTTP")
    7. 'strDetails = """Service Tag"",""System Type"",""Ship Date"",""Dell IBU"",""Description"",""Provider"",""Start Date"",""End Date"",""Days Left"""
    8. Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
    9. While Not objInputFile.AtEndOfStream
    10. strServiceTag = objInputFile.ReadLine
    11. strCurrentTag = ""
    12. strURL = "http://www.dell.com/support/troubleshooting/in/en/inbsd1/Index?c=in&l=en&s=bsd&cs=inbsd1&t=warranty&servicetag=DR8W55J"
    13. objHTTP.open "GET", strURL, False
    14. objHTTP.send
    15. strPageText = objHTTP.responseText
    16. For Each strHeading In arrHeadings
    17. intSummaryPos = InStr(LCase(strPageText), LCase(strHeading))
    18. If intSummaryPos > 0 Then
    19. intSummaryTableStart = InStrRev(LCase(strPageText), "<table", intSummaryPos)
    20. intSummaryTableEnd = InStr(intSummaryPos, LCase(strPageText), "</table>") + 8
    21. MsgBox intSummaryTableEnd
    22. MsgBox intSummaryTableStart
    23. strInfoTable = Mid(strPageText, intSummaryTableStart, intSummaryTableEnd - intSummaryTableStart)
    24. strInfoTable = Replace(Replace(Replace(strInfoTable, VbCrLf, ""), vbCr, ""), vbLf, "")
    25. arrCells = Split(LCase(strInfoTable), "</td>")
    26. For intCell = LBound(arrCells) To UBound(arrCells)
    27. arrCells(intCell) = Trim(arrCells(intCell))
    28. intOpenTag = InStr(arrCells(intCell), "<")
    29. While intOpenTag > 0
    30. intCloseTag = InStr(intOpenTag, arrCells(intCell), ">") + 1
    31. strNewCell = ""
    32. If intOpenTag > 1 Then strNewCell = strNewCell & Trim(Left(arrCells(intCell), intOpenTag - 1))
    33. If intCloseTag < Len(arrCells(intCell)) Then strNewCell = strNewCell & Trim(Mid(arrCells(intCell), intCloseTag))
    34. arrCells(intCell) = Replace(Trim(strNewCell), " &nbsp;&nbsp;&nbsp;&nbsp;change service tag","")
    35. intOpenTag = InStr(arrCells(intCell), "<")
    36. Wend
    37. Next
    38. 'WScript.Echo Join(arrCells, "|")
    39. If LCase(arrCells(0)) = LCase("Service Tag:") Then
    40. 'strCurrentTag = """" & strServiceTag & """"
    41. strCurrentTag = ""
    42. For intField = 1 To UBound(arrCells) Step 2
    43. If strCurrentTag = "" Then
    44. strCurrentTag = " " & arrCells(intField) & " "
    45. Else
    46. strCurrentTag = strCurrentTag & ";" & arrCells(intField) & ""
    47. End If
    48. Next
    49. ElseIf LCase(arrCells(0)) = LCase("Description") Then
    50. For intField = 5 To UBound(arrCells)
    51. strCurrentTag = strCurrentTag & ";" & arrCells(intField) & ""
    52. Next
    53. End If
    54. Else
    55. strCurrentTag = """" & strServiceTag & """ ""No warranty information found."""
    56. End If
    57. Next
    58. strDetails = strDetails & strCurrentTag & Vbcrlf & "#"
    59. Wend
    60. objInputFile.Close
    61. Set objInputFile = Nothing
    62. Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
    63. objOutputFile.Write strDetails
    64. objOutputFile.Close
    65. Set objOutputFile = Nothing
    66. Set objFSO = Nothing

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „dungons“ ()

    Ich glaube nicht, dass "for each" hier funktioniert. Versuch's mal mit

    Visual Basic-Quellcode

    1. for i = lbound(arrHeadings) to ubound(arrHeadings)
    2. strHeading = arrHeadings(i)
    Besucht auch mein anderes Forum:
    Das Amateurfilm-Forum