Coding Help (vb.net)

Talk about your favorite PC games, Steam and building awesome custom rigs!

Moderator: Moderators

Post Reply
ghosstt
Senior Member
Posts: 1551
Joined: Mon Feb 26, 2007 4:14 pm

Coding Help (vb.net)

Post by ghosstt »

Ok. I'm doing a prime number generator again..

Here is what i got...

Code: Select all

Public Class Form1
    Dim intPrime As Integer = 1
    Dim bool As Boolean

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim intDivisor As Integer
        Dim intMod As Integer
        Dim strOutput As String
        bool = True

        Do While bool = True
            intPrime = intPrime + 1
            For intDivisor = 1 To intPrime
                intMod = intDivisor Mod intPrime
                If intMod <> 0 Then
                    strOutput = strOutput & intMod & vbCrLf
                    TextBox1.Text = strOutput
                    Application.DoEvents()
                End If
            Next
        Loop

    End Sub

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Bool = False
    End Sub
End Class
I know its not working.. here are the results

Code: Select all

1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
1
2
3
4
5
6
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1
2
3
4
5
6
7
8
9
10
Kurt_
Portablizer
Posts: 5748
Joined: Thu Nov 24, 2005 10:32 am
Steam ID: kurbert
Location: Ontario, Canada
Contact:

Post by Kurt_ »

Yup, that's wrong all right!
Hey, sup?
ghosstt
Senior Member
Posts: 1551
Joined: Mon Feb 26, 2007 4:14 pm

Post by ghosstt »

well.. do you want to help? and please dont give a function.. or anything of those likes..
bicostp
Moderator
Posts: 10491
Joined: Mon Mar 07, 2005 5:47 pm
Steam ID: bicostp
Location: Spamalot
Contact:

Re: Coding Help (vb.net)

Post by bicostp »

ghosstt wrote:

Code: Select all

Public Class Form1
    Dim intPrime As Integer = 1
    Dim bool As Boolean

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim intDivisor As Integer
        Dim intMod As Integer
        Dim strOutput As String
        bool = True

        Do While bool = True
            intPrime = intPrime + 1
            For intDivisor = 1 To intPrime
                intMod = intDivisor Mod intPrime
                If intMod <> 0 Then
                    strOutput = strOutput & intMod & vbCrLf
                    TextBox1.Text = strOutput
                    Application.DoEvents()
                End If
            Next
        Loop

    End Sub

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Bool = False
    End Sub
End Class
I know its not working.. here are the results

Code: Select all

holycrapabunchofnumbers
You're just adding numbers to the end of your string output variable and dumping it into the text box. Get rid of the text box and replace it with a list box. That way you can add stuff to it fairly easily. (No need to fake this with a text box... ;))


This should do... something. It's not a copy-paste replacement for your code but you get the idea:

Code: Select all

Public Class Form1
    Dim intPrime As Integer = 1
    Dim bool As Boolean

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        Dim intDivisor As Integer
        Dim intMod As Integer
        Dim strOutput As String
        bool = True

        Do While bool = True
            intPrime = intPrime + 1
            For intDivisor = 1 To intPrime
                intMod = intDivisor Mod intPrime
                If intMod <> 0 Then
                    listbox1.items.add(intmod)
                    Application.DoEvents()
                End If
            Next
        Loop

    End Sub

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Bool = False
    End Sub
End Class
It will probably just spit out

1
2
3
4
5
6
...

It's been a while since I took VB, and I was never really good at it, so this probably won't change much besides possibly fixing the number repetition problem. Sorry. :(
ghosstt
Senior Member
Posts: 1551
Joined: Mon Feb 26, 2007 4:14 pm

Post by ghosstt »

it is the same results as last time. Just 1 through X then 1 - Y.

anyone else?
Post Reply