# How to display results in a list box?

• (2 Pages)
• 1
• 2

## 16 Replies - 7566 Views - Last Post: 24 December 2011 - 10:21 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=260674&amp;s=7db1eefa230235708fe5aef4a33c0a39&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 shardooni

Reputation: 0
• 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

• D.I.C Lover

Reputation: 330
• Posts: 1,997
• 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.

### #3 shardooni

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

## Re: How to display results in a list box?

Posted 21 December 2011 - 11:43 AM

maj3091, 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?

### #4 BobRodes

• Lovable Curmudgeon

Reputation: 600
• Posts: 3,069
• 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?

### #5 shardooni

Reputation: 0
• 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?

BobRodes, 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?

### #6 BobRodes

• Lovable Curmudgeon

Reputation: 600
• Posts: 3,069
• Joined: 19-May 09

## Re: How to display results in a list box?

Posted 22 December 2011 - 07:14 AM

### #7 shardooni

Reputation: 0
• 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.

BobRodes, on 22 December 2011 - 07:14 AM, said:

### #8 maj3091

• D.I.C Lover

Reputation: 330
• Posts: 1,997
• 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.

### #9 shardooni

Reputation: 0
• 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.

maj3091, 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.

### #10 maj3091

• D.I.C Lover

Reputation: 330
• Posts: 1,997
• 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.

### #11 BobRodes

• Lovable Curmudgeon

Reputation: 600
• Posts: 3,069
• Joined: 19-May 09

## Re: How to display results in a list box?

Posted 22 December 2011 - 07:59 AM

shardooni, on 22 December 2011 - 02:16 PM, said:

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

BobRodes, 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

### #12 shardooni

Reputation: 0
• 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!

BobRodes, on 22 December 2011 - 07:59 AM, said:

shardooni, on 22 December 2011 - 02:16 PM, said:

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

BobRodes, 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.

### #13 maj3091

• D.I.C Lover

Reputation: 330
• Posts: 1,997
• 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.

### #14 BobRodes

• Lovable Curmudgeon

Reputation: 600
• Posts: 3,069
• 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.

### #15 shardooni

Reputation: 0
• 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.

maj3091, 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.