Advertisement
ZeekoSec

boring stuff

Dec 23rd, 2016
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.85 KB | None | 0 0
  1. Imports System.Text
  2. Imports MaterialSkin
  3. Public Class Form1
  4.  
  5.     Public Function synonym(ByVal ord As String) As String
  6.         Dim sourceString As String = New System.Net.WebClient().DownloadString("http://sproget.dk/lookup?SearchableText=" + ord)
  7.         Dim stringSeparators() As String = {"<h3 id=""thesaurus"">Dansk Synonymordbog</h3><br />"}
  8.         Dim split = sourceString.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
  9.  
  10.         Dim string_after = split(1)
  11.  
  12.         Dim mystr As String = string_after
  13.         Dim cut_at As String = "</div>"
  14.         Dim x As Integer = InStr(mystr, cut_at)
  15.  
  16.         Dim string_before As String = mystr.Substring(0, x - 2)
  17.  
  18.         Dim regex As New Text.RegularExpressions.Regex("<(.|\n)*?>")
  19.         Dim result As String = regex.Replace(string_before, String.Empty)
  20.  
  21.         Dim final As String = result.Replace(",", Environment.NewLine)
  22.  
  23.         Dim entries As New List(Of String)()
  24.  
  25.         For Each line As String In final.Split(vbLf)
  26.             line = String.Join(" ", line.Split(New Char() {}, StringSplitOptions.RemoveEmptyEntries))
  27.             If line.Contains("Ã") OrElse line.Contains(";") OrElse line.Contains(":") OrElse line.Contains(">") OrElse line.Contains("<") OrElse line.Contains(" "c) Then
  28.                 Dim i = 0
  29.             Else
  30.                 entries.Add(line)
  31.  
  32.             End If
  33.  
  34.         Next
  35.  
  36.  
  37.         Dim builder As New StringBuilder()
  38.         For Each i As Object In entries
  39.             builder.AppendLine(i + ", ".ToString())
  40.         Next
  41.  
  42.  
  43.  
  44.         Dim output As String = builder.ToString().Remove(0, 4)
  45.         Return output.Remove(output.Length - 4)
  46.  
  47.     End Function
  48.  
  49.     Public Function rndsynonym(ByVal ord As String) As String
  50.         Dim sourceString As String = New System.Net.WebClient().DownloadString("http://sproget.dk/lookup?SearchableText=" + ord)
  51.         Dim stringSeparators() As String = {"<h3 id=""thesaurus"">Dansk Synonymordbog</h3><br />"}
  52.         Dim split = sourceString.Split(stringSeparators, 2, StringSplitOptions.RemoveEmptyEntries)
  53.  
  54.         Dim string_after = split(1)
  55.  
  56.         Dim mystr As String = string_after
  57.         Dim cut_at As String = "</div>"
  58.         Dim x As Integer = InStr(mystr, cut_at)
  59.  
  60.         Dim string_before As String = mystr.Substring(0, x - 2)
  61.  
  62.         Dim regex As New Text.RegularExpressions.Regex("<(.|\n)*?>")
  63.         Dim result As String = regex.Replace(string_before, String.Empty)
  64.  
  65.         Dim final As String = result.Replace(",", Environment.NewLine)
  66.  
  67.         Dim entries As New List(Of String)()
  68.  
  69.         For Each thing As String In final.Split(vbLf)
  70.             If thing.Contains("a") Then
  71.                 Dim i = 1
  72.             Else
  73.                 entries.Add(thing)
  74.             End If
  75.  
  76.  
  77.         Next
  78.  
  79.  
  80.         Dim rnd As New Random()
  81.         'Variable to hold our random line number
  82.         Dim line As Integer
  83.  
  84.  
  85.         'Now we need a random number
  86.         line = rnd.Next(entries.Count + 1)
  87.         'Now write out the random line to the TextBox
  88.  
  89.         Dim builder As New StringBuilder()
  90.         builder.AppendLine(entries(line).Trim())
  91.         Return builder.ToString().Replace(" ", "")
  92.  
  93.     End Function
  94.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  95.         Dim SkinManager As MaterialSkinManager = MaterialSkinManager.Instance
  96.         SkinManager.AddFormToManage(Me)
  97.         SkinManager.Theme = MaterialSkinManager.Themes.LIGHT
  98.         SkinManager.ColorScheme = New ColorScheme(Primary.Indigo500, Primary.Indigo700, Primary.Indigo100, Accent.Pink200, TextShade.WHITE)
  99.     End Sub
  100.  
  101.     Private Sub MaterialRaisedButton1_Click(sender As Object, e As EventArgs)
  102.     End Sub
  103.  
  104.     Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
  105.         If PictureBox2.Visible = False Then
  106.             PictureBox2.Visible = True
  107.         Else
  108.             PictureBox2.Visible = False
  109.         End If
  110.     End Sub
  111.  
  112.     Private Sub MaterialSingleLineTextField1_Click(sender As Object, e As EventArgs) Handles MaterialSingleLineTextField1.Click
  113.         If MaterialSingleLineTextField1.Text = "Skriv noget.." Then
  114.             MaterialSingleLineTextField1.Clear()
  115.         End If
  116.     End Sub
  117.  
  118.     Private Sub MaterialRaisedButton2_Click(sender As Object, e As EventArgs) Handles MaterialRaisedButton2.Click
  119.         Try
  120.             MaterialSingleLineTextField3.Text = synonym(MaterialSingleLineTextField4.Text)
  121.         Catch ex As Exception
  122.             MaterialSingleLineTextField3.Text = "Kunne ikke finde synonymer :("
  123.         End Try
  124.  
  125.     End Sub
  126.  
  127.     Private Sub MaterialSingleLineTextField4_Click(sender As Object, e As EventArgs) Handles MaterialSingleLineTextField4.Click
  128.         If MaterialSingleLineTextField4.Text = "Skriv noget.." Then
  129.             MaterialSingleLineTextField4.Clear()
  130.         End If
  131.     End Sub
  132. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement