BioloMICS logo
×
BioloMICS menu

Obtain data from Mycobank

 
Code sample below is compete and describes a way to connect to a web services (here Mycobank) and use the data within BioloMICS.
 
Imports System
Imports Microsoft.VisualBasic
Imports System.windows.forms
 
Public Class Class1
 
     Public Function MycobankQuery(ByVal SpeciesName As String) As string
          Try
               Dim TextLine As String = ""
 
               TextLine = "http://www.mycobank.org/BioloMICSServer.aspx?Link=T&NameIs=" & SpeciesName
 
               Dim Req As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(TextLine), System.Net.HttpWebRequest)
 
               Req.Headers.Clear()
 
               Req.Headers.Add("GET", " HTTP/1.0")
 
               Req.Timeout = 5000
 
               Req.ContentType = "application/x-www-form-urlencoded"
 
               Dim loWebResponse As System.Net.WebResponse = Req.GetResponse()
               Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(1252) ' // Windows default Code Page
               Dim loResponseStream As New System.IO.StreamReader(loWebResponse.GetResponseStream(), enc)
               Dim temp As String = loResponseStream.ReadToEnd()
               Dim ListOfResults as String() = split(temp,"|")
               Dim SelectedName as String = ""
               Dim i as Integer = 1
               Dim MycobankName As string = split(temp,"@@")(0)
               Dim MycobankID As string = split(temp,"@@")(2)
               if ListOfResults.Length > 2 then
                    for each TempText as String in ListOfResults
                         if i < ListOfResults.Length then SelectedName &= i.tostring & ". " & Replace(TempText, "@@", " ") & vbcrlf
                         i = i + 1
                    next
                    SelectedName = inputbox("Select the number of the species to be used: " & vbcrlf & vbcrlf & SelectedName)
                    if SelectedName <> "" then
                         Dim FinalSelection as String = ListOfResults(cint(SelectedName)-1)
                         MycobankName = split(FinalSelection,"@@")(0)
                         MycobankID = split(FinalSelection,"@@")(2)
                    end if
               end if
              
               loWebResponse.Close()
               loResponseStream.Close()
               MycobankQuery = MycobankName & vbcrlf & "http://www.mycobank.org/MycoTaxo.aspx?Link=T&Rec=" & MycobankID
          Catch ex As Exception
               MycobankQuery = ex.Message.ToString
          End Try
     End Function
 
'     Shared Sub Main()
'          dim ClassTest as New Class1
'          dim SpeciesNames as String() = split(clipboard.gettext, vbcrlf)
'               for each SpeciesName as String in SpeciesNames
'                    Console.Write(ClassTest.MycobankQuery(SpeciesName) & vbcrlf)
'               next
'               beep
'     End Sub
 
     Shared Sub Main()
          dim ClassTest as New Class1
          Dim SpeciesName as String =inputbox("Species name to search for?")
          if SpeciesName <> "" then
               Clipboard.clear()
               Clipboard.settext(ClassTest.MycobankQuery(SpeciesName))
               'Console.Write(clipboard.gettext)
               beep
          end if
     End Sub
End Class