Previous Entry Share Next Entry
Is it?
Self portrait
You can modify existing routines to do different jobs. The last program found all the prime factors in a number. This one tells you if a number is a prime.

Function IsPrime(n)
'REM Tests if a number (n) is a prime number.
'If it is, returns the Boolean value, True; otherwise, False.
Dim d as integer, i as integer, v as Boolean
'Test if multiple of 2
if d=0 then
    goto IsPrime100
end if
'Test if multiple of 3
if d=0 then
    goto IsPrime100
end if
'Test if multiple of 6i-1 and 6i+1 to sqr(n)+1
for i=6 to int(sqr(n))+1 step 6
    if d=0 then
        goto IsPrime100
    end if
    if d=0 then
        goto IsPrime100
    end if
next i  
Exit Function
IsPrime100: v=False
End Function

I write code like this t use as tools for other projects. There are a few "Is" functions in LibreOffice Basic but there are many times that I want to test a value for some characteristic or another (such as "Is it prime") and these macro languages are quite lacking in this respect, and LibreOffice and OpenOffice lacks even in comparison to Microsoft Office, so I have to plug the holes.

The main difference between this and the other program is that this one doesn't collect prime factors and all it returns is "True" or "False".

One of the aggravating things about these macro language is that the "True" string that a routine might reurn and the TRUE Boolean value that a spreadsheet function recognizes are not the same thing, so you still have to process the Boolean values returned by homegrown programs.

Recent Posts from This Journal

  • One more time

    Okay. I didn't loose as much as I thought and my external hard disk just needed to be unplugged and plugged back in. What I did loose, though,…

  • Eeeeeeee!Krsh! Crash........burn

    Oh well. There goes another hobby. I'm not very upset. It's not like I don't have other things going on. Fact is, I knew that both…

  • Help!

    Well, excuuuuuuuuuuse me! There are help files for LibreOffice. You can find a download for them on the Home page for LibreOffice. They work just…


Log in

No account? Create an account