daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Dec 17th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim UsernameArray() As String = IO.File.ReadAllLines("Username.txt")
  2.    
  3. Imports System.Data.OleDb
  4. Public Class Form3
  5.     Public Score2 As Integer
  6.  
  7.     Dim UsernameArray() As String = IO.File.ReadAllLines("Username.txt")
  8.     Dim NumOfValues As Integer = 0
  9.     Dim JustScore(NumOfValues) As Integer
  10.     Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  11.         Dim ScoreArray() As String = IO.File.ReadAllLines("Score.txt")
  12.  
  13.         lblScore.Text = Score2
  14.  
  15.         UpdateData()
  16.  
  17.     End Sub
  18.  
  19.     Private Sub butSubmit_Click(sender As Object, e As EventArgs) Handles butSubmit.Click
  20.  
  21.         'Write to a file
  22.         Using Writer As New IO.StreamWriter("Username.txt", True)
  23.             Writer.WriteLine(txtUsername.Text & ", " & lblScore.Text)
  24.         End Using
  25.  
  26.         Using Writer As New IO.StreamWriter("Score.txt", True)
  27.             Writer.WriteLine(lblScore.Text)
  28.         End Using
  29.  
  30.         ReDim JustScore(NumOfValues)
  31.         UpdateData()
  32.  
  33.         MessageBox.Show("Saved")
  34.         butSubmit.Visible = False
  35.     End Sub
  36.  
  37.     Private Sub butMergeSort_Click(sender As Object, e As EventArgs) Handles butMergeSort.Click
  38.         MergeSort(JustScore)
  39.  
  40.         MessageBox.Show("Data is Sorted, You can Now use the Searching Operation")
  41.  
  42.         butSearch.Visible = True
  43.  
  44.     End Sub
  45.  
  46.     Private Sub butSearch_Click(sender As Object, e As EventArgs) Handles butSearch.Click
  47.         binary_search()
  48.     End Sub
  49.  
  50.     Private Sub UpdateData()
  51.         Dim ScoreArray() As String = IO.File.ReadAllLines("Score.txt")
  52.  
  53.         For i = 0 To ScoreArray.Length - 1
  54.  
  55.             ScoreArray(i) = CInt(ScoreArray(i))
  56.  
  57.             JustScore(NumOfValues) = ScoreArray(i)
  58.  
  59.             NumOfValues += 1
  60.             ReDim Preserve JustScore(NumOfValues)
  61.         Next
  62.  
  63.     End Sub
  64.  
  65.  
  66.     Private Sub Merge_Sort(ByVal ar() As Integer, ByVal low As Integer, ByVal high As Integer)
  67.  
  68.         If low >= high Then Return
  69.         Dim length As Integer = high - low + 1
  70.         Dim middle As Integer = Math.Floor((low + high) / 2)
  71.         Merge_Sort(ar, low, middle)
  72.         Merge_Sort(ar, middle + 1, high)
  73.         Dim temp(ar.Length - 1) As Integer
  74.         For i As Integer = 0 To length - 1
  75.             temp(i) = ar(low + i)
  76.         Next
  77.         Dim m1 As Integer = 0
  78.         Dim m2 As Integer = middle - low + 1
  79.         For i As Integer = 0 To length - 1
  80.             If m2 <= high - low Then
  81.                 If m1 <= middle - low Then
  82.                     If temp(m1) > temp(m2) Then
  83.                         ar(i + low) = temp(m2)
  84.                         m2 += 1
  85.                     Else
  86.                         ar(i + low) = temp(m1)
  87.                         m1 += 1
  88.                     End If
  89.                 Else
  90.                     ar(i + low) = temp(m2)
  91.                     m2 += 1
  92.                 End If
  93.             Else
  94.                 ar(i + low) = temp(m1)
  95.                 m1 += 1
  96.             End If
  97.         Next
  98.  
  99.     End Sub
  100.  
  101.  
  102.     Private Sub MergeSort(ByVal ar() As Integer)
  103.  
  104.         Merge_Sort(ar, 0, ar.Length - 1)
  105.  
  106.         For j = 0 To JustScore.Length - 1
  107.             Console.WriteLine(JustScore(j) & ", ")
  108.         Next
  109.  
  110.     End Sub
  111.  
  112.     Sub binary_search()
  113.         Dim Result As Integer = -1
  114.         Dim Low As Integer = 0
  115.         Dim High As Integer = JustScore.Length - 1
  116.         Dim Middle As Integer
  117.         Dim UserInput As Integer
  118.  
  119.         UserInput = InputBox("What is Your Score")
  120.  
  121.         While Low <= High And Result = -1
  122.             Middle = (Low + High) / 2
  123.             If UserInput = JustScore(Middle) Then
  124.                 Result = Middle
  125.             ElseIf UserInput < JustScore(Middle) Then
  126.                 High = Middle - 1
  127.             ElseIf UserInput > JustScore(Middle) Then
  128.                 Low = Middle + 1
  129.             End If
  130.         End While
  131.  
  132.         Dim temp As Integer
  133.  
  134.         temp = Result
  135.  
  136.         Result = JustScore.Length - Result
  137.  
  138.         If Result > 0 Then
  139.             MessageBox.Show("Your Value is at the " & Result & " Place in the List")
  140.         Else
  141.             MessageBox.Show("Your Value Isn't in the List")
  142.         End If
  143.  
  144.     End Sub
  145.  
  146. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top