Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Collections.Generic
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Linq
- Imports System.Text
- Imports System.Windows.Forms
- Imports System.Text.RegularExpressions
- Namespace Fellesnevner
- Public Partial Class Form1
- Inherits Form
- Public Sub New()
- InitializeComponent()
- End Sub
- Private Sub button1_Click(sender As Object, e As EventArgs)
- textBox1.Text = ""
- 'test[0] = Convert.ToInt32(tall1.Value);
- 'test[1] = Convert.ToInt32(tall2.Value);
- Dim t As String = textBox2.Text
- Dim words As String() = t.Split(","C)
- Dim nr As Integer = 0
- Dim test As Integer() = New Integer(words.Length - 1) {}
- If Not IsAllDigits(t) Then
- MessageBox.Show("Du kan kun bruke tall og Komma.")
- Else
- For Each x As String In words
- test(nr) = Convert.ToInt32(words(nr))
- nr += 1
- Next
- sharedfaction(test)
- End If
- End Sub
- Public Shared Function IsAllDigits(s As String) As Boolean
- For Each c As Char In s
- If Not [Char].IsDigit(c) AndAlso c <> ","C Then
- Return False
- End If
- Next
- Return True
- End Function
- Public Function sharedfaction(tall As Integer()) As Integer
- Dim tallene As Integer() = tall
- Dim funnet As Boolean = False
- Dim counter As Integer = tallene.Max()
- Dim delelige As Integer() = New Integer(49) {}
- Dim list As New List(Of Integer)()
- Dim increaser As Integer = 1
- While Not funnet
- For Each i As Integer In tallene
- counter = tallene.Max() * increaser
- If counter Mod i = 0 Then
- 'delelige[i] = 1;
- list.Add(1)
- 'textBox1.Text += "\r\n "+counter + " % " + i + " = 1";
- textBox1.Text += vbCr & vbLf & counter & " / " & i & " = " & counter \ i & ". Er delelig"
- Else
- 'delelige[i] = 2;
- 'textBox1.Text += "\r\n " + counter + " % " + i + " = 2";
- textBox1.Text += vbCr & vbLf & counter & " / " & i & " = " & counter \ i & ". IKKE delelig"
- list.Add(2)
- End If
- Next
- If list.Contains(2) Then
- list.Clear()
- Else
- 'MessageBox.Show("Fellesnevner funnet: " + counter);
- resultatlabel.Text = counter.ToString()
- funnet = True
- list.Clear()
- End If
- textBox1.Text += vbCr & vbLf
- 'counter++;
- increaser += 1
- End While
- Return 1
- End Function
- Private Sub Form1_Load(sender As Object, e As EventArgs)
- resultatlabel.Text = ""
- End Sub
- End Class
- End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement