Home > Coding > Had to write a VBScript today

Had to write a VBScript today

January 13th, 2009

003_p5_det_c
Creative Commons License photo credit: wisof

Had to write a VBScript today to do some funky stuff. Basically we needed to copy in a string of text and then output that text so it would be formatted to go into an email.

Input text looked something like:

x.x.x.0/x Company  How Assigned    Location

The big issue I had with all of this is that there’s spaces in the company names, spaces in the location, spaces in how assigned… so I couldn’t use a space as the delimter. Well, the code is UGLY… but the general concept is I knew I had certain points where I would have more than one space in a row. After the company name I had 2 spaces. After the How assigned I had 4 spaces. So I could create a couple arrays and delimit using those known values. The only other problem I had was how to get rid of the IP address before the company name… well I solved that by getting rid of all the numbers from the section of the array where the company should be. Again this isn’t pretty – but it got the job done.

window.resizeTo 450,500

dim arrHeaders(3), strIP, strCompany, strStatus, strNewContent
arrHeaders(0) = "IP Block:"
arrHeaders(1) = "Customer:"
arrHeaders(2) = "Status:"
arrHeaders(3) = "IDC:"

Sub SetCopyPaste

strPortal = "From the site:"

strline = CopyPaste.value
arrFields = Split(strLine)
arrFields2 = Split(strline, "  ")
cutString = arrFields2(0)
arrFields3 = Split(strline, "    ")

strAlphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
For i = 1 to len(cutString)
strChar = mid(cutString,i,1)
If instr(strAlphaNumeric,strChar) Then
CleanedString = CleanedString & strChar
End If
next

strIP = arrFields(0)
strCompany = CleanedString
strStatus = arrFields2(1)
strIDC = arrFields3(1)
strNewContent = strPortal & vbCrLf & vbCrLf & arrheaders(0) & " " & strIP & " - " & strStatus & vbCrLf _
& arrHeaders(1) & " " & strCompany & vbCrLf & arrheaders(3) & " " & strIDC

CombinedText.Value = strNewContent

End Sub

Obviously there’s VBSCRIPT tags at the top and the bottom… and some HTML to format the page.

The attached file you can grab and see the whole thing with the code and whatnot.

Output text looked like this:
From the site:

IP Block: x.x.x.0/x – How Assigned
Customer: Company
IDC: Location

spam-email

Post to Twitter Tweet This Post

brandon Coding

  1. No comments yet.
  1. No trackbacks yet.

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.