Go Back   Science Forums > Physical Sciences Forums > Computer Science and Technology
Reply
 
LinkBack Thread Tools
Old 03-04-2006   #1 (permalink)
TheBigDog's Avatar
Doing the Impossible

Moderator
Gallery Curator

Location:
Madison, OH (when not in fantasy land)
 
TheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond repute
Send a message via MSN to TheBigDog
 



Not Ranked  0 score     
vb.net Programming

I am starting this thread to share snippets of code that I have written with those who may be interested, and to help/get help with writing in vb.net.

I am not a professional programmer, but I play one at work. I am a hobbiest. To me getting a desired response from a computer is like solving a puzzle. And I dig puzzles.

The first snippet here is a function for finding if a number is true or false.

Code:
    Function IsPrime(ByVal Check As Long) As Boolean
        'this is a function that checks if a number is prime
        'first we check the obvious, 
        'if the number is less than two or a non integer, then it is not prime
        If Check < 2 Or Int(Check) <> Check Then Return False

        'then we cheat and set the first prime number to 2
        KnownPrimes(1) = 2
        If Check = 2 Then Return True

        'then we begin checking against our known list of primes
        Dim a as Long = 0

        Do
            a += 1
            'if the number is evenly divisible by a known prime then it is not prime
            If Check / KnownPrimes(a) = Int(Check / KnownPrimes(a)) Then Return False
            'if we get past the sqrt of the check number
            'and it still isn't evenly divisible
            'then the number is prime
            If Check < KnownPrimes(a) ^ 2 Then Return True
            'when we have exhausted our prime numbers, 
            'but the target is not reached yet
            'then we need to find new primes, add them to the list, and keep searching
        Loop Until a = KnownPrimes.Length - 1

        'begin expanding the list of prime numbers
        Dim Target as Integer = KnownPrimes(a)

        Do
            Target += 1
            a = 0
            Do
                a += 1
                'if the number is evenly divisible by a known prime then it is not prime
                'so we exit this loop and continue the bigger loop
                If Target / KnownPrimes(a) = Int(Target / KnownPrimes(a)) Then Exit Do
                'if we get past the sqrt of the check number
                'and it still isn't evely divisible
                'then the number is prime
                If Target < KnownPrimes(a) ^ 2 Then
                    ReDim Preserve KnownPrimes(KnownPrimes.Length)
                    KnownPrimes(KnownPrimes.Length - 1) = Target
                    If Check / Target = Int(Check / Target) Then Return False
                    Exit Do
                End If
            Loop Until a = KnownPrimes.Length - 1
        Loop Until Check < Target ^ 2
        Return True

    End Function
Inserting that into a program and then calling the function IsPrime(n) will return a true/false for the primeness of n. Its limitation is the values attainable by data type 'Long'.

Bill


----------------
aka TheBigDog - Hypography Full Freaking Moderator
Become a Hypography sponsor!
The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill

TheBigDog's recommended reading: The Science of Success - Charles G. Koch

A neutron goes into a bar and asks the bartender, "How much for a beer?"
The bartender replies, "For you, no charge."
Reply With Quote
Old 03-05-2006   #2 (permalink)
alexander's Avatar
Dedicated Smart-ass

Senior Moderator
Gallery Curator
Dev Team Member

Location:
Just before 0xAA55
 
alexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond repute
Send a message via AIM to alexander
 



Not Ranked  0 score     
Re: vb.net Programming

In c++ i usually use the seive to test for primity, something like:
Code:
#include <iostream>                                                             
#include <bitset>                                                                                                                              

//namespace is too large to include all of it, wasting resources already with bitset
using std::cin;
using std::cout;
                                                                                
int main()                                                                      
{                                                                               
    const unsigned int MAX_VAL = 10000001; //set max val
    unsigned int max=0; //value to display primes up to

    cout << "Max value to check for primity up to (2-10000001): ";            
    cin >> max;
    
    if(max >= MAX_VAL)
    {
        cout << "\nValue entered too high, exiting...\n";
        return 0;
    }

    bitset<MAX_VAL+1> seive; //create a seive
    seive.set(); //set seive

    cout << "\nDisplaying primes in range of 2 to " << max << ":\n";        
                                                                                
    for(int i = 2; i<=max; i++)                                             
    {                                                                       
        if(seive.test(i)) //this actually tests for primity of a number
        {                                                                                                               
             cout << i << " "; //display prime
        }                                                                   
    }

    return 0;
}
simple yet effective...


----------------
Microsoft, the leader in using innovative tactics to promote irksome experience, coupled with antiquated technology that's held together by a pyramid of makeshift afterthoughts.

Apple, the leader in using irksome tactics to promote innovative experience, coupled with an antiquated core that's enhanced by state-of-the-art afterthoughts.

Linux, the leader in not using any tactics to promote user-defined experience, coupled with state-of-the-art core enhanced by innovative afterthoughts.

Reply With Quote
Old 03-05-2006   #3 (permalink)
TheBigDog's Avatar
Doing the Impossible

Moderator
Gallery Curator

Location:
Madison, OH (when not in fantasy land)
 
TheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond repute
Send a message via MSN to TheBigDog
 



Not Ranked  0 score     
Re: vb.net Programming

So seive.test() is a c++ native funtion to tell if a value is Prime. That is easier that building it yourself!

One of the things I forgot to mention is that I did not declare KnownPrimes() in the function. I did that in the header of the program so that I could use the established list of primes within other functions. There is probably a better way of doing that, but is worked for me.

Bill


----------------
aka TheBigDog - Hypography Full Freaking Moderator
Become a Hypography sponsor!
The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill

TheBigDog's recommended reading: The Science of Success - Charles G. Koch

A neutron goes into a bar and asks the bartender, "How much for a beer?"
The bartender replies, "For you, no charge."
Reply With Quote
Old 03-05-2006   #4 (permalink)
alexander's Avatar
Dedicated Smart-ass

Senior Moderator
Gallery Curator
Dev Team Member

Location:
Just before 0xAA55
 
alexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond repute
Send a message via AIM to alexander
 



Not Ranked  0 score     
Re: vb.net Programming

no, no TBG, seive.test is a bitstring function, which is a library of C++, but not very native one, its a datascructure method, as long as you set it up right, it will do its job...


----------------
Microsoft, the leader in using innovative tactics to promote irksome experience, coupled with antiquated technology that's held together by a pyramid of makeshift afterthoughts.

Apple, the leader in using irksome tactics to promote innovative experience, coupled with an antiquated core that's enhanced by state-of-the-art afterthoughts.

Linux, the leader in not using any tactics to promote user-defined experience, coupled with state-of-the-art core enhanced by innovative afterthoughts.

Reply With Quote
Old 03-05-2006   #5 (permalink)
TheBigDog's Avatar
Doing the Impossible

Moderator
Gallery Curator

Location:
Madison, OH (when not in fantasy land)
 
TheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond reputeTheBigDog has a reputation beyond repute
Send a message via MSN to TheBigDog
 



Not Ranked  0 score     
Thumbs up Re: vb.net Programming

Quote:
Originally Posted by alexander
no, no TBG, seive.test is a bitstring function, which is a library of C++, but not very native one, its a datascructure method, as long as you set it up right, it will do its job...
Thus the separation between professional and hobbiest. I learn something new every day. Thanks!

(If I had managed to get C++s in school I might have known this already )

Bill


----------------
aka TheBigDog - Hypography Full Freaking Moderator
Become a Hypography sponsor!
The truth is incontravertible; malice may attack it, ignorance may deride it, but in the end there it is. - Winston Churchill

TheBigDog's recommended reading: The Science of Success - Charles G. Koch

A neutron goes into a bar and asks the bartender, "How much for a beer?"
The bartender replies, "For you, no charge."
Reply With Quote
Old 03-05-2006   #6 (permalink)
alexander's Avatar
Dedicated Smart-ass

Senior Moderator
Gallery Curator
Dev Team Member

Location:
Just before 0xAA55
 
alexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond reputealexander has a reputation beyond repute
Send a message via AIM to alexander
 



Not Ranked  0 score     
Re: vb.net Programming

naah, they dont usually touch advanced datastructures in beginning courses, you might get to classes in class, maybe even build a linked list or a queue or something, but probably wont even touch bitsets...


----------------
Microsoft, the leader in using innovative tactics to promote irksome experience, coupled with antiquated technology that's held together by a pyramid of makeshift afterthoughts.

Apple, the leader in using irksome tactics to promote innovative experience, coupled with an antiquated core that's enhanced by state-of-the-art afterthoughts.

Linux, the leader in not using any tactics to promote user-defined experience, coupled with state-of-the-art core enhanced by innovative afterthoughts.

Reply With Quote
Old 03-05-2006   #7 (permalink)
Buffy's Avatar
Resident Slayer

Administrator

Location:
Sunnydale, CA
 
Buffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond repute
 



Not Ranked  0 score     
Re: vb.net Programming

Nonetheless, if you're going to have fun with programming, drop vb and go with C++ like alexander is encouraging you. Bitstrings are incredibly useful:
Code:
#define MALE 1
#define MARRIED 2
#define HASKIDS 4
#define ISRICH 8
#define CONVICTIONS 16
#define HASEVILMOM 32

int BuffysIdealGuy = MALE | ISRICH;

if (randomdude & HASEVILMOM > 0) {
     avoidlikeplague();
}
Great for efficient, obscure code!

Basic will grow hair on the palms of your hands and cause brain damage. You may use Java if you wish. Python has its advocates, and if you wanna do AI you gotta do Lisp.

You have been warned.

Opinions voiced, I'll shut up.

Not Dim, but //,
Buffy


----------------
"If you do not agree with anything I say, I'll not only retract it, but deny under oath that I ever said it!"
__________________________________________________ ______________-- Tom Lehrer

"No Robbie, not Europe!"


Forum Administrator
Hypography Science Forums - Science for Boys and Girls! Its not for nothing that we hang out here.
Reply With Quote
Old 03-06-2006   #8 (permalink)
Jay-qu's Avatar
Ancora Imparo

Moderator
Editor
Gallery Curator

Location:
Australia
 
Jay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond repute
 



Not Ranked  0 score     
Re: vb.net Programming

I took IT as a subject this year and will be doing solely java, what are your thoughts and opinions on this language compared with vb?


----------------
Jay-qu
::Hypography Moderator of..
Chemistry, Physics & Mathematics, Astronomy & Cosmology, Space and Technology & gadgets Forums

"I don't think much of a man who is not wiser today than he was yesterday."
-Abraham Lincoln

Physics Guides - Physics Resources and help
Reply With Quote
Old 03-06-2006   #9 (permalink)
Buffy's Avatar
Resident Slayer

Administrator

Location:
Sunnydale, CA
 
Buffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond repute
 



Not Ranked  0 score     
Re: vb.net Programming

Quote:
Originally Posted by Jay-qu
...and will be doing solely java, what are your thoughts and opinions on this language compared with vb?
You should use VB if you would like to type more when you're writing code, have a harder time seeing nesting of code blocks, and want to use an extremely weak and limited implementation of objects...

alexander would point out that you should use VB if you want to be locked in to a proprietary language controlled exclusively by the Evil Empire.

You have been warned! Again! Do not use VB, it causes rickets and leads to kidney stones.

Goto considered harmful,
Buffy


----------------
"If you do not agree with anything I say, I'll not only retract it, but deny under oath that I ever said it!"
__________________________________________________ ______________-- Tom Lehrer

"No Robbie, not Europe!"


Forum Administrator
Hypography Science Forums - Science for Boys and Girls! Its not for nothing that we hang out here.
Reply With Quote
Old 03-06-2006   #10 (permalink)
Jay-qu's Avatar
Ancora Imparo

Moderator
Editor
Gallery Curator

Location:
Australia
 
Jay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond reputeJay-qu has a reputation beyond repute
 



Not Ranked  0 score     
Re: vb.net Programming

thanks well thats all well and good, because im using java - but what about some advantages of it, not just disadvantages of vb..


----------------
Jay-qu
::Hypography Moderator of..
Chemistry, Physics & Mathematics, Astronomy & Cosmology, Space and Technology & gadgets Forums

"I don't think much of a man who is not wiser today than he was yesterday."
-Abraham Lincoln

Physics Guides - Physics Resources and help
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Developer Woes: Quirks of Programming Languages saidevo Computer Science and Technology 21 03-07-2006 01:59 AM
Neuro Linguinistic Programming Gulielmus Political sciences 7 10-16-2005 08:27 PM
A disturbing trend? alxian Political sciences 128 08-25-2005 01:30 AM
Programming tarak Computer Science and Technology 33 05-18-2005 07:08 AM
Basic: Programming Language or Corrupting Influence Buffy Computer Science and Technology 33 05-06-2005 04:37 AM

» Advertisement
» Current Poll
Who's the sexiest man alive? Johnny Depp or Robert Pattinson?
Johnny Depp - 30.00%
3 Votes
Robert Pattinson - 0%
0 Votes
Someone else (please specify) - 40.00%
4 Votes
I'm too macho to think a guy is sexy - 30.00%
3 Votes
Total Votes: 10
You may not vote on this poll.


All times are GMT -8. The time now is 07:00 PM.

Hypography?

Hypography [n.]: A combination of "hyperlink" and "bibliography" - ie, a list of links to electronic documents. Comparable to discography and bibliography, but not cartography.

We have been online since May 2000, and aim to be the best place to find and share science-related content of all kinds.

Share the love!

Please add more science to your life. Use our RSS feeds on your blog, your portal, or your favorite feedreader!


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
Copyright © 2000-2009 Hypography
Part of the Hypography - Science for Everyone Network