Microsoft Small Basic

Program Listing:
Embed this in your website
' TechNet Wiki Article List 0.21
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Last update 2015-02-12
' Program ID WWJ884-2
'
TextWindow.Title = "TechNet Wiki Article List 0.21"
Not = "False=True;True=False;"
qt = Text.GetCharacter(34)
LT = "<"
root = "http://social.technet.microsoft.com"
tags = "1=Small Basic;"
tags = "1=BASIC;2=VB;3=VB.NET;4=VB.Net 2008;5=vb.net 2012;6=VB2013;7=visual basic;8=visual basic.net;9=visual basic 10;10=visual basic 2010;"
nArticle = 0
stdout = Program.Directory + "/list.html"
' The following line could be harmful and has been automatically commented.
' File.WriteContents(stdout, LT + "!DOCTYPE html>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "html lang=" + qt + "en" + qt + ">")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "head>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "meta charset=" + qt + "UTF-8" + qt + ">")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "title>TechNet Wiki Article List" + LT + "/title>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/head>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "body>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "p>TechNet Wiki Article List - " + Clock.Date + LT + "/p>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "table>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "tr>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>TITLE")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>LAST REVISION BY" + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>CREATION DATE" + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>TAGS" + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/tr>")
nTag = Array.GetItemCount(tags)
For iTag = 1 To nTag
  eob = "False" ' end of blog
  EncodeTag()
  url = root + "/wiki/contents/articles/tags/" + encoded + "/default.aspx"
  site = url
  pageIndex = 1
  pageLast = ""
  While Not[eob]
    TextWindow.WriteLine(site)
    buf = Network.GetWebPageContents(site)
    pNotFound = Text.GetLength(buf) + 1
    p = 1
    eod = "False"
    While Not[eod]
      param = "tag=h4;class=post-name;"
      FindTag()
      If tag = "" Then
        eod = "True"
      Else
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "tr>")
        bufSave = buf
        pH4 = p
        p = 1
        buf = tag
        param = "tag=a;"
        FindTag()
        GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>" + LT + "a href=" + qt + attr["href"] + qt + ">" + txt + LT + "/a>" + LT + "/td>")
        nArticle = nArticle + 1
        buf = bufSave
        p = pH4
        param = "tag=a;class=internal-link view-user-profile;"
        FindTag()
        If tag = "" Then
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td> " + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td> " + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td> " + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/tr>")
          eod = "True"
        Else
          GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>" + LT + "a href="+ qt + root + attr["href"] + qt + ">" + txt + "" + LT + "/a>" + LT + "/td>")
          param = "tag=div;class=post-date;"
          FindTag()
          If tag = "" Then
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td> " + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td> " + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/tr>")
            eod = "True"
          Else
            pDiv = p
            bufSave = buf
            p = 1
            buf = tag
            param = "tag=span;class=value;"
            FindTag()
            GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>" + txt + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "td>" + tags[iTag] + LT + "/td>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/tr>")
            buf = bufSave
            p = pDiv
          EndIf
        EndIf
      EndIf
    EndWhile
    pageIndex = pageIndex + 1
    If pageLast = "" Then
      param = "tag=span;class=summary;"
      FindTag()
      If tag = "" Then
        eob = "True"
      Else
        GetAttrAndText()
        lenPage = Text.GetIndexOf(Text.GetSubTextToEnd(txt, 11), " ") - 1
        pageLast = Text.GetSubText(txt, 11, lenPage)
      EndIf
    EndIf
    site = url + "?PageIndex=" + pageIndex
    If pageLast < pageIndex Then
      eob = "True"
    EndIf
  EndWhile
EndFor
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/table>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "p>Total " + nArticle + " articles." + LT + "/p>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/body>")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, LT + "/html>")
TextWindow.WriteLine("Total " + nArticle + " articles.")
Sub EncodeTag
  ' param tags - array for tags
  ' param iTag - index of the array for tags
  ' return encoded - encoded tag
  encoded = ""
  len = Text.GetLength(tags[iTag])
  For i = 1 To len
    c = Text.GetSubText(tags[iTag], i, 1)
    If c = " " Then
      c = "+"
    ElseIf c = "." Then
      c = "-"
    ElseIf c = "#" Then
      c = "_2300_"
    ElseIf c = "+" Then
      c = "_2B00_"
    ElseIf c = "-" Then
      c = "_2D00_"
    EndIf
    If Text.EndsWith(encoded, "_") And Text.StartsWith(c, "_") Then
      l1 = Text.GetLength(encoded) - 1
      encoded = Text.Append(Text.GetSubText(encoded, 1, l1), Text.GetSubTextToEnd(c, 2))
    Else
      encoded = Text.Append(encoded, c)
    EndIF
  EndFor
EndSub
Sub FindTag
  ' find tag from html buffer
  ' param["tag"] - tag name
  ' param["class"] - class name
  ' param p - pointer for buffer
  ' param buf - html buffer
  ' return tag - found tag
  pSave = p
  tag = ""
  findNext = "True"
  While findNext
    findNext = "False"        ' tag may be not found
    pTag = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), LT + param["tag"])
    If 0 < pTag Then
      lTag = Text.GetLength(param["tag"]) + 1
      pTag = p + pTag - 1
      len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/" + param["tag"] + ">")
      If param["class"] = "" Then
        len = len + lTag
        tag = Text.GetSubText(buf, pTag, len)
        findNext = "False"    ' found the tag
      ElseIf 0 < len Then
        findNext = "True"     ' tag may have different class
        len = len + lTag
        attr = "class=" + qt + param["class"] + qt
        pAttr = pTag + lTag + 1
        lAttr = Text.GetLength(attr)
        If Text.GetSubText(buf, pAttr, lAttr) = attr Then
          tag = Text.GetSubText(buf, pTag, len)
          findNext = "False"  ' found the tag
        EndIf
        p = pTag + len
      EndIf
    EndIf
  EndWhile
  If tag = "" Then
    p = pSave
  EndIf
EndSub
Sub GetAttrAndText
  ' get attributes and text from given tag
  ' param tag - given tag
  ' return attr[] - array of attributes in the tag
  ' return txt - text in the tag
  pTag = Text.GetIndexOf(tag, " ") + 1
  pEnd = Text.GetIndexOf(tag, ">")
  attr = ""
  While pTag <= pEnd
    pEq = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "=")
    If 0 < pEq Then
      pEq = pTag + pEq - 1
      If Text.GetSubText(tag, pEq + 1, 1) = qt Then
        pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), qt)
        If 0 < pQ Then
          pQ = pEq + 2 + pQ - 1
          attr[Text.GetSubText(tag, pTag, pEq - pTag)] = Text.GetSubText(tag, pEq + 2, pQ - pEq - 2)
          pTag = pQ + 2
        EndIf
      EndIf
    Else
      pTag = pEnd + 1
    EndIf
  EndWhile
  If pEnd + 1 < pTag Then
    pTag = pEnd + 1
  EndIf
  len = Text.GetLength(tag)
  txt = ""
  While pTag <= len
    pL = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), LT)
    If pL = 0 Then
      txt = Text.Append(txt, Text.GetSubTextToEnd(tag, pTag))
      pTag = len + 1
    Else
      pL = pTag + pL - 1
      txt = Text.Append(txt, Text.GetSubText(tag, pTag, pL - pTag))
      pR = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), ">")
      If 0 < pR Then
        pTag = pTag + pR
      Else
        pTag = len + 1
      EndIf
    EndIf
  EndWhile
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.