Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subscript out of range problem

Status
Not open for further replies.

gotinput

Technical User
Nov 12, 2009
3
US
Given the following input:

IP: 10.0.0.1 MAC: 00:11:22:33:44:55
computername.dns.root
IP: 11.0.0.1 MAC: 00:11:22:33:44:56
computer2.dns.root

the below script works great, however when the input is corrupted from another process and the data comes out:

IP: 10.0.0.1 MAC: 00:11:22:33:44:55
computername.dns.root
IP: 11

1.0.0.1 MAC: 00:11:22:33:44:56
computer2.dns.root

I get an "Run-time error ‘9’: Subscript out of range"

When i select Debug, the "IPString = IPStringOut(1)" is highlighted.

The data that we're running through this scrip is usually several megabites and we cannot easily manually remove the erranious carriage returns and duplicate ip integers

Please help!

Sub Convert_VC_Dump2()

Dim fso
Dim txtStreamIn
Dim txtStreamOut
Dim LineIn
Dim txtOut

Dim VulString
Dim AssetString
Dim MangString
Dim SevString
Dim STIGString
Dim StatString
Dim DeatilString
Dim IPString
Dim MACString
Dim HostString
Dim FindChkStr
Dim FindFixStr
Dim HitNum
Dim SingleFinding
Dim IPStringOut

'ask for the location to the dump file
'parse that file and save to the database's directory
'load that file to the database

Set fso = CreateObject("Scripting.FileSystemObject")
Set txtStreamIn = fso_OpenTextFile(getFileName(), 1)
cleanFileup (".\VC06_Convert.txt")
Set txtStreamOut = fso_OpenTextFile(".\VC06_Convert.txt", 8, True)
Set wShell = CreateObject("Wscript.Shell")

'Set txtstreamdebug = fso_OpenTextFile("C:\VMS\VC06_Debug.txt", 8, True)

LineIn = ""
txtOut = ""
StrLngth = 0
HitNum = 1
HitNumStr = ""
lineXfer = ""
SrchStr2 = ""

VulString = ""
AssetString = ""
MangString = ""
SevString = ""
STIGString = ""
StatString = ""
DetailString = ""
IPString = ""
MACString = ""
HostString = ""
FindChkStr = ""
FindFixStr = ""
SingleFinding = True


txtOut = "Vulnerability;Total;Asset;Severity;STIG_ID;FindChecks;FindFixes;Detail;IP;MAC;Host"
txtStreamOut.writeline txtOut
txtOut = ""

wShell.PopUp "Converting file, please wait..." & Chr(10) & "Do not close the database.", 5, "Info"

'Begin the parse
Do While Not (txtStreamIn.AtEndOfStream)
If (InStr(LineIn, "Complete Finding Detail") = 0) Then
LineIn = txtStreamIn.Readline
LineIn = Trim(LineIn)
End If
' Find a vulnerability to convert
If Trim(LineIn) = "Complete Finding Detail" Then

FoundFirst = True
LineIn = txtStreamIn.Readline
LineIn = txtStreamIn.Readline
LineIn = Replace(LineIn, ";", "-")
AssetString = Trim(LineIn)

'find the main vulnerability string
Do While InStr(LineIn, "Vulnerability:") = 0 And Not (txtStreamIn.AtEndOfStream)
LineIn = Trim(txtStreamIn.Readline)
Loop

' set the first part of the vulstring
If InStr(LineIn, "Vulnerability:") Then
LineIn = Trim(txtStreamIn.Readline)
LineIn = Replace(LineIn, ";", "-")
VulString = Trim(LineIn)
End If

' find the STIG ID
Do While InStr(LineIn, "STIG ID:") = 0 And Not (txtStreamIn.AtEndOfStream)
LineIn = Trim(txtStreamIn.Readline)
Loop
' set the STIG ID
If InStr(LineIn, "STIG ID:") Then
LineIn = Trim(txtStreamIn.Readline)
LineIn = Replace(LineIn, ";", "-")
STIGString = Trim(LineIn)
End If

' find the severity
Do While InStr(LineIn, "Severity:") = 0 And Not (txtStreamIn.AtEndOfStream)
LineIn = Trim(txtStreamIn.Readline)
Loop
' set the severity
If InStr(LineIn, "Severity:") Then
LineIn = Trim(txtStreamIn.Readline)
LineIn = Replace(LineIn, ";", "-")
SevString = Right(LineIn, Len(LineIn) - 2)
End If

' find the vulnerability name
Do While InStr(LineIn, "Finding Long Name:") = 0 And Not (txtStreamIn.AtEndOfStream)
LineIn = Trim(txtStreamIn.Readline)
Loop

VulString = VulString & " -- "

' build the vulerability name
Do While (InStr(LineIn, "Finding Details:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
If InStr(LineIn, "Finding Details:") = 0 Then
LineIn = Replace(LineIn, Chr(10), "")
LineIn = Replace(LineIn, Chr(13), "")
LineIn = Replace(LineIn, ";", "-")
VulString = VulString & LineIn
End If
Loop
VulString = Trim(VulString)
Do While InStr(VulString, " ")
VulString = Replace(VulString, " ", " ")
Loop

' build a temporary details holder
Do While (InStr(LineIn, "Finding Discussion:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
If InStr(LineIn, "Finding Discussion:") = 0 Then
If InStr(LineIn, "occurrences") = 0 Then
LineIn = Replace(LineIn, Chr(10), "")
LineIn = Replace(LineIn, Chr(13), "")
LineIn = Replace(LineIn, ";", "-")
LineIn = Trim(LineIn)
TempDetails = TempDetails & LineIn & ">><<"
End If
End If
Loop
Do While (InStr(TempDetails, " "))
TempDetails = Replace(TempDetails, " ", " ")
Loop
TempDetails = Replace(TempDetails, ">><<>><<", ">><<")
TempDetails = Replace(TempDetails, "Host>><<Name", "Host Name")
TempDetails = Replace(TempDetails, "Host Name:>><<", "Host Name: ")
TempDetailsA = Split(TempDetails, ">><<")

'If InStr(TempDetails, "HFHSK51") And InStr(TempDetails, "00:18:71:E4:C0:28") Then
' txtStreamOut.writeline TempDetails
' MsgBox found
'End If

' find the discussion area to set the it to the details area
Do While (InStr(LineIn, "Vulnerability Fixes:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
If InStr(LineIn, "Vulnerability Fixes:") = 0 Then
LineIn = Replace(LineIn, ";", "-")
LineIn = Replace(LineIn, Chr(10), "")
LineIn = Replace(LineIn, Chr(13), "")
LineIn = Trim(LineIn)
If LineIn = "" Then
DetailString = DetailString & "[[]]"
Else
DetailString = DetailString & LineIn
End If
End If
Loop

'Clean up the string
Do While (InStr(DetailString, "[[]][[]]"))
DetailString = Replace(DetailString, "[[]][[]]", "[[]]")
Loop
Do While (InStr(DetailString, " "))
DetailString = Replace(DetailString, " ", " ")
Loop
DetailString = Replace(DetailString, " ", " ")
DetailString = Replace(DetailString, "[[]]", vbCrLf)

' find and bulid the finding fixes
Do While (InStr(LineIn, "Vulnerability Mitigations:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
If InStr(LineIn, "Vulnerability Mitigations:") = 0 Then
LineIn = Replace(LineIn, ";", "-")
LineIn = Replace(LineIn, Chr(10), "")
LineIn = Replace(LineIn, Chr(13), "")
LineIn = Trim(LineIn)
If LineIn = "" Then
FindFixString = FindFixString & "[[]]"
Else
FindFixString = FindFixString & LineIn
End If
End If
Loop

'Clean up the string
Do While (InStr(FindFixString, "[[]][[]]"))
FindFixString = Replace(FindFixString, "[[]][[]]", "[[]]")
Loop
Do While (InStr(FindFixString, " "))
FindFixString = Replace(FindFixString, " ", " ")
Loop
FindFixString = Replace(FindFixString, " ", " ")
FindFixString = Replace(FindFixString, "[[]]", vbCrLf)


' find the vulnerablity checks
Do While (InStr(LineIn, "Vulnerability Checks:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
Loop
' bulid the vulnerabilty checks area
Do While (InStr(LineIn, "Complete Finding Detail") = 0) And (InStr(LineIn, "Total Findings:") = 0) And Not (txtStreamIn.AtEndOfStream)
LineIn = txtStreamIn.Readline
If InStr(LineIn, "Complete Finding Detail") = 0 And InStr(LineIn, "Total Findings:") = 0 Then
LineIn = Replace(LineIn, ";", "-")
LineIn = Replace(LineIn, Chr(10), "")
LineIn = Replace(LineIn, Chr(13), "")
LineIn = Trim(LineIn)
If LineIn = "" Then
FindChkString = FindChkString & "[[]]"
Else
FindChkString = FindChkString & " " & LineIn
End If
End If
Loop

'Clean up the string
Do While (InStr(FindChkString, "[[]][[]]"))
FindChkString = Replace(FindChkString, "[[]][[]]", "[[]]")
Loop
Do While (InStr(FindChkString, " "))
FindChkString = Replace(FindFixString, " ", " ")
Loop
FindChkString = Replace(FindChkString, " ", " ")
FindChkString = Replace(FindChkString, "[[]]", vbCrLf)




'MsgBox VulString & Chr(10) & AssetString & Chr(10) & SevString & Chr(10) & STIGString & Chr(10) & IPString & Chr(10) & MACString & Chr(10) & HostString, vbOKOnly, Info

If UBound(TempDetailsA) >= 1 Then
For i = 0 To UBound(TempDetailsA)
If (InStr(TempDetailsA(i), "IP:") > 0) Then
SingleFinding = False
IPStringOut = ""
IPStringOut = Split(TempDetailsA(i), " ")
IPString = IPStringOut(1)
If UBound(IPStringOut) >= 3 Then
MACString = IPStringOut(3)
End If
If UBound(IPStringOut) >= 6 Then
HostString = IPStringOut(6)
End If

'If InStr(TempDetails, "TYNCPTSWK01103") And InStr(MACString, "00:13:D3:54:D2:A0") Then
' MsgBox UBound(IPStringOut)
'MsgBox IPStringOut(1) & " ; " & IPStringOut(5) & " ; " & IPStringOut(6)
'End If


'MsgBox VulString & Chr(10) & AssetString & Chr(10) & SevString & Chr(10) & STIGString & Chr(10) & IPString & Chr(10) & MACString & Chr(10) & HostString, vbOKOnly, Info

'txtOut = VulString + ";" & "1" & ";" + AssetString + ";" + SevString + ";" + STIGString + ";" + FindChkString + ";" + FindFixString + ";" + DetailString + ";" + IPString + ";" + MACString + ";" + HostString
txtOut = VulString + ";" & "1" & ";" + AssetString + ";" + SevString + ";" + STIGString + ";" + ";" + ";" + ";" + IPString + ";" + MACString + ";" + HostString
'txtOut = txtOut + Chr(10)
txtStreamOut.writeline txtOut
End If
Next
End If

If (SingleFinding) Then
'MsgBox VulString & Chr(10) & AssetString & Chr(10) & SevString & Chr(10) & STIGString & Chr(10) & IPString & Chr(10) & MACString & Chr(10) & HostString, vbOKOnly, Info
'txtOut = VulString + ";" & "1" & ";" + AssetString + ";" + SevString + ";" + STIGString + ";" + FindChkString + ";" + FindFixString + ";" + DetailString
txtOut = VulString + ";" & "1" & ";" + AssetString + ";" + SevString + ";" + STIGString + ";" + ";" + ";"

'txtOut = txtOut + Chr(10)
txtStreamOut.writeline txtOut
End If

FindFixString = Right(FindFixString, Len(FindFixString) - 2)
FindChkString = Right(FindChkString, Len(FindChkString) - 2)
Call LoadNewVul(VulString, FindChkString, FindFixString, DetailString)

txtOut = ""
HitNum = 1
VulString = ""
AssetString = ""
SevString = ""
STIGString = ""
DetailString = ""
TempDetails = ""
TempDetailsA = ""
IPString = ""
MACString = ""
HostString = ""
FindChkString = ""
FindFixString = ""
'IPStringOut = ""
SingleFinding = True

End If

Loop

txtStreamOut.Close
txtStreamIn.Close
'txtstreamdebug.Close

If fso.FileExists(".\schema.ini") = 0 Then
'Grr = CreateSchemaFile(True, ".\", "VC06_Convert.TXT", "VC06_Convert")
End If

wShell.PopUp "Conversion done, importing file now. Please wait...", 2, "Info"

If fso.FileExists(".\VC06_Convert.txt") Then
DoCmd.TransferText acImportDelim, "VC06_Convert_Import", "VC06_Convert", ".\VC06_Convert.txt", True
End If

'wShell.PopUp "Identifying General", 2, "Info"

'DoCmd.OpenQuery ("Q_VC06_Mark_General")
CurrentDb.Execute "UPDATE Q_VC06 SET Q_VC06.Host = 'GENERAL' WHERE (((Q_VC06.Host) Is Null) AND ((Q_VC06.IP) Is Null))", dbFailOnError

'wShell.PopUp "Marking Duplicate Vulnerabilites", 2, "Info"

DupMark

'wShell.PopUp "Setting Tiers", 2, "Info"

TierMark

wShell.PopUp "New data loaded. Import complete.", 5, "Info"


End Sub
 


Hi,

IPStringOut(1) has no element 1.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I understand that (or think i do), is there a way to have it pick up where it left off? Or check for the presence of an element 1 before trying to set the variable equal to it?
 


Code:
If UBound(IPStringOut)>=1 then
   IPString = IPStringOut(1)
else
  'what do you want to do here?
   IPString ="???"
end if

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I consulted my brother-in-law who offerred this up and it did the trick.

'Check to see if line was split and last character duplicated

If UBound(IPStringOut) < 7 Then

If i < UBound(TempDetailsA) Then

If StrComp(Right(TempDetailsA(i), 1), Left(TempDetailsA(i + 1), 1) = 0 Then

TempDetailsA(i + 1) = Right(TempDetailsA(i), Len(TempDetailsA(i)) - 1) + TempDetailsA(i + 1)

i = i + 1

IPStringOut = Split(TempDetailsA(i), " ")

End If

End If

End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top