How to display results in a list box?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 4186 Views - Last Post: 24 December 2011 - 10:21 AM Rate Topic: -----

#1 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

How to display results in a list box?

Posted 21 December 2011 - 11:26 AM

Hey guys,

I had to create a program that calculated prime numbers. The logic is that you have to imput limits n & m and then LOOP and ODD integer P between n & m inclusive. I think I have the code write for calculating the primes, but I just don't know how to display the prime numbers in a list box? I need to know if this code is right first. Help would be highly appreciated! ( I am new at this, ive tried everything to make this work)

Thanks,
S

        Dim Isprime As Integer
        Dim TestLimit As Long
        Dim TestPrime As Long
        Dim TestNum As Long

        
        '   
        ' Eliminate even numbers
        If TestPrime Mod 2 = 0 Then Exit Sub
        '   Loop through ODD numbers starting with 3
        TestNum = 3
        TestLimit = TestPrime
        Do While TestLimit > TestNum

            If TestPrime Mod TestNum = 0 Then
                '   Uncomment this if you really want to know
                '   MsgBox "Divisible by " & TestNum   

                Exit Sub
            End If

            '   There's logic to this.  Think about it.
            TestLimit = TestPrime \ TestNum

            '   Remember, we only bother to check odd numbers
            TestNum = TestNum + 2

        Loop

        '   If we made it through the loop, the number is a prime.
        Isprime = True

    End Sub

End Class


Is This A Good Question/Topic? 0
  • +

Replies To: How to display results in a list box?

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: How to display results in a list box?

Posted 21 December 2011 - 11:39 AM

Check out this link for using the listbox control.

I'm sure you could have found this yourself using google.
Was This Post Helpful? 0
  • +
  • -

#3 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 21 December 2011 - 11:43 AM

View Postmaj3091, on 21 December 2011 - 11:39 AM, said:

Check out this link for using the listbox control.

I'm sure you could have found this yourself using google.


It is way too complicated to understand that website. I read it before.. and ive tried it but nothing works
Does my code look okay?
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: How to display results in a list box?

Posted 21 December 2011 - 09:07 PM

No, it doesn't. Which you probably already know, since you aren't getting any sort of prime number list out of it, right?
Was This Post Helpful? 0
  • +
  • -

#5 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 21 December 2011 - 09:15 PM

ok can u help me fix it?


View PostBobRodes, on 21 December 2011 - 09:07 PM, said:

No, it doesn't. Which you probably already know, since you aren't getting any sort of prime number list out of it, right?

Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: How to display results in a list box?

Posted 22 December 2011 - 07:14 AM

Glad to.
Was This Post Helpful? 0
  • +
  • -

#7 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 22 December 2011 - 07:16 AM

already looked through google, but thanks for treating me like an idiot.



View PostBobRodes, on 22 December 2011 - 07:14 AM, said:


Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: How to display results in a list box?

Posted 22 December 2011 - 07:38 AM

Why do you feel you're being treat like an idiot?

The first link in the google search gives you a fully working example of calculating prime numbers including displaying them on screen.

So please explain your problem?
Was This Post Helpful? 0
  • +
  • -

#9 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 22 December 2011 - 07:43 AM

Because I need LOOPS to calculate the prime numbers. there is no loops in that example AND i have never learnt half the stuff they used in that code.



View Postmaj3091, on 22 December 2011 - 07:38 AM, said:

Why do you feel you're being treat like an idiot?

The first link in the google search gives you a fully working example of calculating prime numbers including displaying them on screen.

So please explain your problem?

Was This Post Helpful? 0
  • +
  • -

#10 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: How to display results in a list box?

Posted 22 December 2011 - 07:50 AM

If you look at the example it uses a For...Next loop.

If you need to use a DO Loop, then have a look at this link which explains the differences between the two and you should be able work it out for yourself on how to change it.

People are offering you assistance, so now it's down to you to make use of some of the advice being given.

At least give it a try and come back with the issues you have.

We're not a group of code-monkeys, so nobody will just write it for you.
Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: How to display results in a list box?

Posted 22 December 2011 - 07:59 AM

View Postshardooni, on 22 December 2011 - 02:16 PM, said:

already looked through google, but thanks for treating me like an idiot.



View PostBobRodes, on 22 December 2011 - 07:14 AM, said:


Well, quite frankly, you're behaving like an idiot. I could have cut and pasted the example that was in the second link that my google string provided into a post here, and you would have said thanks very much, and copied it and used it as your own. Here, let me show you how I treat idiots.

Quote

...All right my child, here is your code. I found it by googling "vb6 prime number example". It was on the second link, and I didn't even have to read all the way down the page. When you're a little older, you'll be able to do this too.

Function IsPrime(checkValue As Long) As Boolean
     For testValue = 2 To CLng(Sqr(checkValue)) Step 1
         If checkValue Mod testValue = 0 Then
             IsPrime = False
             Exit Function
         End If
     Next
     IsPrime = True
 End Function


There you are. Glad I could help.


Is that better? In other words, you're behaving like an idiot. Since you're not an idiot, suppose you stop throwing tantrums because we're asking you to use google and solve your own problems like the rest of us and get to work.

Of course, it seems to have worked this time, since you have your code.

This post has been edited by BobRodes: 22 December 2011 - 08:20 AM

Was This Post Helpful? 0
  • +
  • -

#12 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 22 December 2011 - 12:06 PM

all I was trying to say was that I saw that code and it is not much use to me since I don't understand the language of it. Thanks for your help anyways. I won't come back on thie site anymore. I found some understanding and helpful people on VB Forums :)

Good day!



View PostBobRodes, on 22 December 2011 - 07:59 AM, said:

View Postshardooni, on 22 December 2011 - 02:16 PM, said:

already looked through google, but thanks for treating me like an idiot.



View PostBobRodes, on 22 December 2011 - 07:14 AM, said:


Well, quite frankly, you're behaving like an idiot. I could have cut and pasted the example that was in the second link that my google string provided into a post here, and you would have said thanks very much, and copied it and used it as your own. Here, let me show you how I treat idiots.

Quote

...All right my child, here is your code. I found it by googling "vb6 prime number example". It was on the second link, and I didn't even have to read all the way down the page. When you're a little older, you'll be able to do this too.

Function IsPrime(checkValue As Long) As Boolean
     For testValue = 2 To CLng(Sqr(checkValue)) Step 1
         If checkValue Mod testValue = 0 Then
             IsPrime = False
             Exit Function
         End If
     Next
     IsPrime = True
 End Function


There you are. Glad I could help.


Is that better? In other words, you're behaving like an idiot. Since you're not an idiot, suppose you stop throwing tantrums because we're asking you to use google and solve your own problems like the rest of us and get to work.

Of course, it seems to have worked this time, since you have your code.

Was This Post Helpful? 0
  • +
  • -

#13 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: How to display results in a list box?

Posted 22 December 2011 - 02:09 PM

It was a basic VB6 example and you are in a VB6 forum, but you don't understand the language of it?

I'm sorry, but I have to agree with Bob on this. You have done little or nothing to help yourself while being here, having been pointed in the right direction for an answer to your question, but you completely refused to even have a go.

Oh well, I'm glad you found someone to write it for you, which is what you wanted all along.
Was This Post Helpful? 0
  • +
  • -

#14 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: How to display results in a list box?

Posted 24 December 2011 - 09:53 AM

<I found some understanding and helpful people on VB Forums

Why yes, you did. Understanding and helpful is exactly what we are. We understand that you need to learn to do your own work, and we're doing our best to help you do it.
Was This Post Helpful? 0
  • +
  • -

#15 shardooni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 28-October 11

Re: How to display results in a list box?

Posted 24 December 2011 - 09:58 AM

Alright enough with the bickering guys!
Sorry I am a new programmer I just needed a little head start. I never asked ANYONE to write me the code. Sorry for causing so much trouble. :/

Cheers.



View Postmaj3091, on 22 December 2011 - 02:09 PM, said:

It was a basic VB6 example and you are in a VB6 forum, but you don't understand the language of it?

I'm sorry, but I have to agree with Bob on this. You have done little or nothing to help yourself while being here, having been pointed in the right direction for an answer to your question, but you completely refused to even have a go.

Oh well, I'm glad you found someone to write it for you, which is what you wanted all along.

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2