Advertisement
mathiasbk

fellesnevner vb

Aug 27th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Collections.Generic
  2. Imports System.ComponentModel
  3. Imports System.Data
  4. Imports System.Drawing
  5. Imports System.Linq
  6. Imports System.Text
  7. Imports System.Windows.Forms
  8. Imports System.Text.RegularExpressions
  9.  
  10. Namespace Fellesnevner
  11.     Public Partial Class Form1
  12.         Inherits Form
  13.         Public Sub New()
  14.             InitializeComponent()
  15.         End Sub
  16.  
  17.         Private Sub button1_Click(sender As Object, e As EventArgs)
  18.             textBox1.Text = ""
  19.             'test[0] = Convert.ToInt32(tall1.Value);
  20.             'test[1] = Convert.ToInt32(tall2.Value);
  21.             Dim t As String = textBox2.Text
  22.             Dim words As String() = t.Split(","C)
  23.             Dim nr As Integer = 0
  24.             Dim test As Integer() = New Integer(words.Length - 1) {}
  25.             If Not IsAllDigits(t) Then
  26.                 MessageBox.Show("Du kan kun bruke tall og Komma.")
  27.             Else
  28.                 For Each x As String In words
  29.                     test(nr) = Convert.ToInt32(words(nr))
  30.  
  31.                     nr += 1
  32.                 Next
  33.                 sharedfaction(test)
  34.             End If
  35.  
  36.  
  37.         End Sub
  38.         Public Shared Function IsAllDigits(s As String) As Boolean
  39.             For Each c As Char In s
  40.                 If Not [Char].IsDigit(c) AndAlso c <> ","C Then
  41.                     Return False
  42.                 End If
  43.             Next
  44.             Return True
  45.         End Function
  46.         Public Function sharedfaction(tall As Integer()) As Integer
  47.             Dim tallene As Integer() = tall
  48.             Dim funnet As Boolean = False
  49.             Dim counter As Integer = tallene.Max()
  50.             Dim delelige As Integer() = New Integer(49) {}
  51.             Dim list As New List(Of Integer)()
  52.             Dim increaser As Integer = 1
  53.             While Not funnet
  54.  
  55.                 For Each i As Integer In tallene
  56.                     counter = tallene.Max() * increaser
  57.                     If counter Mod i = 0 Then
  58.                         'delelige[i] = 1;
  59.                         list.Add(1)
  60.                         'textBox1.Text += "\r\n "+counter + " % " + i + " = 1";
  61.                         textBox1.Text += vbCr & vbLf & counter & " / " & i & " = " & counter \ i & ". Er delelig"
  62.                     Else
  63.                         'delelige[i] = 2;
  64.                         'textBox1.Text += "\r\n " + counter + " % " + i + " = 2";
  65.                         textBox1.Text += vbCr & vbLf & counter & " / " & i & " = " & counter \ i & ". IKKE delelig"
  66.                         list.Add(2)
  67.  
  68.                     End If
  69.                 Next
  70.  
  71.                 If list.Contains(2) Then
  72.                     list.Clear()
  73.                 Else
  74.                     'MessageBox.Show("Fellesnevner funnet: " + counter);
  75.                     resultatlabel.Text = counter.ToString()
  76.                     funnet = True
  77.                     list.Clear()
  78.                 End If
  79.                 textBox1.Text += vbCr & vbLf
  80.                     'counter++;
  81.                 increaser += 1
  82.             End While
  83.             Return 1
  84.         End Function
  85.  
  86.         Private Sub Form1_Load(sender As Object, e As EventArgs)
  87.             resultatlabel.Text = ""
  88.         End Sub
  89.     End Class
  90. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement