Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > Visual Basic 2010 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old October 27th, 2010, 07:44 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Yep. You got it.

But you know, he gives you the C++ code for it. There's no reason you can't use Visual C++, compile that code into a library, and then invoke that library function from VB.

EDIT: No, I take that back. He said he uses a #define to set the number of places of accuracy, so you'd have to change even his code if you wanted to convert it into a callable library with arbitrary precision.

Last edited by Old Pedant; October 27th, 2010 at 07:46 PM.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #12 (permalink)  
Old October 27th, 2010, 07:44 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I hope you noted that he said it took 15 hours on his PC to get 1,000,000 places.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #13 (permalink)  
Old October 27th, 2010, 07:55 PM
Authorized User
 
Join Date: Oct 2010
Location: "Great" Britain
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Send a message via MSN to SamC
Default

Quote:
Originally Posted by Old Pedant View Post
I hope you noted that he said it took 15 hours on his PC to get 1,000,000 places.
Aye, but that's really not much when you consider the vast amount of calculations involved. I only really wanted to find enough to fill the first 25 lines of the console window, even with the algorithm I was using that should take only a matter of seconds... I think I shall abandon this project and leave it for when I have a better understanding of programming.

In the mean time I think I may make another Prime Generator, this time using the Sieve of Atkin. That should be quite simple right?

PS: If I want to create a .txt file to save the prime numbers in what would be the best way of going about this?
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction."
- Albert Einstein
Reply With Quote
  #14 (permalink)  
Old October 27th, 2010, 08:08 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

http://msdn.microsoft.com/en-us/libr...eamwriter.aspx

Code:
Dim outf As New StreamWriter("c:\full\pat\to\yourfile.txt")
outf.WriteLine("the next prime number is " & n )
... repeat...
outf.Close()
Or variations on that theme. Learn to use the MSDN docs. They really are amazingly complete.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #15 (permalink)  
Old October 27th, 2010, 08:10 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Never used Sieve of Atkin.

Used to use Sieve of Erastothenes as a benchmarking program. Can't tell you how many languages I wrote that in. But in those days (1970s, early 80s), we were happy to get the primes up to about 16,000.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #16 (permalink)  
Old October 27th, 2010, 08:23 PM
Authorized User
 
Join Date: Oct 2010
Location: "Great" Britain
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Send a message via MSN to SamC
Default

Cool, I use Prime95 for stability testing overclocks all the time, I guess it must be generating some pretty huge primes!

Do you think Sieve of Eratosthenes would be a better option then? It is simpler to implement.
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction."
- Albert Einstein
Reply With Quote
  #17 (permalink)  
Old October 27th, 2010, 08:41 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

The big limitation back in the day was the amount of memory needed. You need an array element for each number from 1 to N. (Well, we "cheated" by only looking at odd numbers, so we needed half that number of elements, but you get the idea.)

In the BASICs of that day, where many implemented only a single numeric data type which was, of course, floating point, that meant the you were using 4 or 6 or 8 bytes per array element. In a 64KB machine, you usually only had a MAX of 32KB left for variables, so even 32K divided by 4 meant a top end of 8000 array elements.

In a modern machine, you can surely devout a few hundred megabytes to the array *AND* with VB.NET (for example) your array elements can each be only 1 byte long (that is, use an array of BYTE data type). So sure...it's thus trivial to implement and you can get up into the range of 1,000,000,000 as a max prime (esp. if you pull the same trick: Don't use an array element for the even numbers).

Actually, VB.NET is fast enough that if you wanted to get a bit more clever you could extend the range by a factor of 8 by using only 1 BIT per odd number. A little more coding work, but not hard.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #18 (permalink)  
Old October 28th, 2010, 02:23 PM
Authorized User
 
Join Date: Oct 2010
Location: "Great" Britain
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Send a message via MSN to SamC
Default

Could you modify my code so that it will display 28 decimal places of π please? That would be awesome.

Also how would I write a routine which sorts an array of strings into alphabetical order? It's really bugging me!
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction."
- Albert Einstein
Reply With Quote
  #19 (permalink)  
Old October 28th, 2010, 02:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
Originally Posted by SamC View Post
Could you modify my code so that it will display 28 decimal places of π please? That would be awesome.
Tell the truth, I've never used DECIMAL with VB before. But I would imagine all you have to do is change all the variables to DECIMAL. Oh, and get rid of Math.Pow(). Just have to do that "by hand" with multiplies, instead.

Quote:
Also how would I write a routine which sorts an array of strings into alphabetical order? It's really bugging me!
Remember what I said about learning to use MSDN??

http://msdn.microsoft.com/en-us/libr...tem.array.aspx

http://msdn.microsoft.com/en-us/library/6tf1f0bc.aspx

You don't HAVE to "write a routine". The .NET framework has it built in.
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
SamC (October 30th, 2010)
  #20 (permalink)  
Old October 28th, 2010, 02:38 PM
Authorized User
 
Join Date: Oct 2010
Location: "Great" Britain
Posts: 29
Thanks: 23
Thanked 0 Times in 0 Posts
Send a message via MSN to SamC
Default

I was aware of that function, I wanted to write the routine myself because my tutor had challenged me to do so over half-term. I could get it to work easily for numerical values, but it didn't work for Strings...
__________________
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction."
- Albert Einstein
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Number with 2 decimal places only pallone SQL Server 2000 4 July 3rd, 2007 07:29 AM
Display Decimal Places rsm42 ASP.NET 1.0 and 1.1 Basics 3 January 7th, 2007 09:46 AM
Round to 2 decimal places adman JSP Basics 0 June 30th, 2005 07:24 AM
Two decimal places only pallone Javascript How-To 5 February 1st, 2005 11:35 PM
output only 2 decimal places Toka1 Javascript How-To 2 February 20th, 2004 10:44 AM



All times are GMT -4. The time now is 11:46 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.