Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Factor Finder v1.0 (Numbers)
#4
(04-23-2011, 12:27 PM)The High Roller Wrote: Hey thanks Infinity, this is actually helpful for my math. I am in Algebra 1 and we use factors ALL the time. Thanks again! PROPS!

Sidenote: Is there a source code please?

I'll give you the basic function I used and other things like how I got the enter key to perform the task of button 1 which handled that function to a string.

Here's the rule I used to create the method for finding factors. If the input in the textbox was 1 I just manually created the output for the factors in the listbox and didn't use this code at all. (Using an if statement and Exit Sub command before this code).
Code:
'"1" will always be a factor so we'll always add it (with the exception of 0)
        ListBox1.Items.Add("1")
        'Defining how we find the factors of the number in Textbox1
        Dim N, x As Integer
        N = Val(TextBox1.Text)
        For x = 2 To N - 1
            If N Mod x = 0 Then
                ListBox1.Items.Add(x)
            End If
        Next
        'This is where we add the value of N (All the factors) to the listbox
        ListBox1.Items.Add(N)
        'Show the number input from Textbox1 into Label2 to confirm which number we are searching for factors (Just something fancy)
        Label2.Text = TextBox1.Text
        'Show in another label how many factors there are (how many listbox items there are)
        Label11.Text = ListBox1.Items.Count

        'Otherwise if listbox has 2 factor values, it has to be 1 and another number (itself) meaning it's a prime number
        If ListBox1.Items.Count = 2 Then
            'So display the value of Label12.Text to show that it's a prime number with this message
            Label12.ForeColor = Color.DarkOrange
            Label12.Text = "(This is a prime number!)"
        Else 'Otherwise, it's not a prime number, so don't show anything
            Label12.Text = ""
        End If

Here's for pressing Enter which will perform the task of button 1 click.
Code:
'Keypresses for in Textbox1
    Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        'If the key pressed is Enter
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            'Then perform the code for the Find Factors button
            Find_Factors.PerformClick()
        End If

Here is the code I used to only allow numbers into the textbox for the input
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        'Only allow numeric entries for the textbox
        If AllowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If

    End Sub

And I defined AllowedChars with this at the top under the Public Class
Code:
Dim AllowedChars As String = "0123456789" & vbBack

I'm glad you find it useful though, that's one of the reasons I created this besides the fact that I was just fooling around in Visual Basic a while ago. I knew at least a couple people would find it useful for one of their math courses.
Reply


Messages In This Thread
Factor Finder v1.0 (Numbers) - by AceInfinity - 04-22-2011, 08:52 PM
RE: Factor Finder v1.0 (Numbers) - by Resistance - 04-23-2011, 12:27 PM
RE: Factor Finder v1.0 (Numbers) - by ReactioNz - 04-23-2011, 12:39 PM
RE: Factor Finder v1.0 (Numbers) - by AceInfinity - 04-23-2011, 01:07 PM
RE: Factor Finder v1.0 (Numbers) - by KoBE - 04-24-2011, 02:55 PM
RE: Factor Finder v1.0 (Numbers) - by AceInfinity - 04-24-2011, 03:00 PM
RE: Factor Finder v1.0 (Numbers) - by iCrack - 05-05-2011, 12:25 PM
RE: Factor Finder v1.0 (Numbers) - by AceInfinity - 05-05-2011, 03:41 PM
RE: Factor Finder v1.0 (Numbers) - by Michael_ - 06-11-2011, 11:35 AM
RE: Factor Finder v1.0 (Numbers) - by Ted Bundy - 06-11-2011, 11:59 AM
RE: Factor Finder v1.0 (Numbers) - by BacklTrack - 06-11-2011, 03:33 PM
RE: Factor Finder v1.0 (Numbers) - by AceInfinity - 06-13-2011, 02:08 AM
RE: Factor Finder v1.0 (Numbers) - by -Dreams - 06-14-2011, 02:21 AM
RE: Factor Finder v1.0 (Numbers) - by AceInfinity - 06-19-2011, 03:08 AM
RE: Factor Finder v1.0 (Numbers) - by RiChZ - 06-21-2011, 06:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [TUT] MD5 Encrypter & Finder [VB.NET] Fragma 12 7,120 11-25-2012, 10:36 PM
Last Post: ƃu∀ ıʞƃu∀
  Help with VB 2010 (Numbers) Dεlluzion 1 754 06-22-2011, 12:07 PM
Last Post: Coding Support
  [VB.NET/Source] Converte Numbers To Letters : 1000 To One Thousand! ThePrinCe 7 1,614 06-18-2011, 04:09 PM
Last Post: Coding Support
  Compare Version Numbers cipherwar 3 1,325 05-10-2011, 12:02 PM
Last Post: Modestep
  Generate Random Numbers & Letters [ Small Function ] MYPE 22 3,327 04-02-2011, 05:25 PM
Last Post: Pyratepig

Forum Jump:


Users browsing this thread: 1 Guest(s)