Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 493
» Latest member: peadenaw@gmail.com
» Forum threads: 2,837
» Forum posts: 26,589

Full Statistics

Latest Threads
Aloha from Maui guys.
Forum: General Discussion
Last Post: bplus
5 hours ago
» Replies: 10
» Views: 213
another variation of "10 ...
Forum: Programs
Last Post: JRace
Today, 03:47 AM
» Replies: 18
» Views: 232
Box_Bash game
Forum: Works in Progress
Last Post: bplus
Today, 01:18 AM
» Replies: 1
» Views: 39
1990's 3D Doom-Like Walls...
Forum: Programs
Last Post: a740g
Yesterday, 09:31 PM
» Replies: 5
» Views: 168
Sound Effects Generator (...
Forum: Petr
Last Post: a740g
Yesterday, 09:05 PM
» Replies: 1
» Views: 58
_SndRaw and _MemFree
Forum: General Discussion
Last Post: a740g
Yesterday, 09:04 PM
» Replies: 1
» Views: 50
Problems with QBJS
Forum: Help Me!
Last Post: bplus
Yesterday, 06:30 PM
» Replies: 4
» Views: 96
which day of the week
Forum: Programs
Last Post: bplus
Yesterday, 06:19 PM
» Replies: 31
» Views: 715
sleep command in compiler...
Forum: General Discussion
Last Post: SMcNeill
Yesterday, 02:57 PM
» Replies: 3
» Views: 92
Another Dir/File compare ...
Forum: Utilities
Last Post: eoredson
Yesterday, 03:48 AM
» Replies: 0
» Views: 48

 
  Primes and patterns into 19-digit integers
Posted by: mnrvovrfc - 03-07-2023, 04:58 PM - Forum: Programs - Replies (5)

This is a program I created when very bored to take a list of 19-digit integers from a text file and figure out if they're prime or not. I was trying to get a palindrome out of one of them but failed so far LOL.

The program is listed below but is worthless without the data files which are part of the attachment.

Code: (Select All)
'by mnrvovrfc, first revision Dec-2020
$CHECKING:OFF
_DEFINE A-Z AS LONG
DIM PRIMEBIT(1 TO 4999995) AS _BIT
DIM PVAL(1 TO 1000) AS _UNSIGNED _INTEGER64
DIM X AS _UNSIGNED _INTEGER64, PLIMIT AS _UNSIGNED LONG, Y AS _UNSIGNED LONG, Z AS _UNSIGNED LONG
DIM fl AS _BIT, ofl AS _BIT, q AS _BYTE

dataf$ = makeuserprof$("%DOCU%/prime19dig-pref.txt")
ifile$ = makeuserprof$("%DOCU%/prime19dig.txt")
outf$ = makeuserprof$("%DOCU%/prime19dig-out.txt")

IF NOT _FILEEXISTS(ifile$) THEN
    PRINT "Cannot run without this file: prime20dig.txt"
    END
END IF

IF _FILEEXISTS(dataf$) THEN
    fi = FREEFILE
    OPEN dataf$ FOR INPUT AS fi
    LINE INPUT #fi, a$
    CLOSE fi
    sop = VAL(LTRIM$(a$))
    IF sop < 1 THEN sop = 1
ELSE
    sop = 1
END IF

PRINT "Please wait, loading ..."
READ Y
READ Y
DO WHILE Y
    Y = (Y - 1) \ 2
    PRIMEBIT(Y) = -1
    READ Y
LOOP
PRINT "Checking input file..."
GOSUB setmytitle
fl = -1
l = 1
u = 1
v = UBOUND(PVAL)
fi = FREEFILE
OPEN ifile$ FOR INPUT AS fi
SEEK #fi, sop
DO UNTIL EOF(fi)
    LINE INPUT #fi, a$
    IF a$ <> "" THEN
        PVAL(u) = VAL(a$)
        u = u + 1
        IF fl THEN fl = 0
        IF u > v THEN sop = SEEK(fi): EXIT DO
    END IF
    l = l + 1
LOOP
IF EOF(fi) THEN sop = 1
CLOSE fi
IF fl THEN
    PRINT "Nothing to do!"
    END
END IF

COLOR 15, 5: CLS
GOSUB setmytitle
_DISPLAY
ofl = 0
FOR u = 1 TO v
    X = PVAL(u)
    IF X = 0 THEN EXIT FOR
    IF u MOD 10 = 0 THEN q = _EXIT
    IF q THEN EXIT FOR
    omb = _MOUSEINPUT
    IF omb THEN
        IF _MOUSEBUTTON(1) THEN ofl = -1
        IF _MOUSEBUTTON(2) THEN ofl = -1
    END IF
    IF ofl THEN
        ofl = 0
        _DISPLAY
    END IF
    fl = -1
    Z = 1
    FOR Y = 1 TO 4999995
        Z = Z + 2
        IF PRIMEBIT(Y) THEN
            IF X MOD Z = 0 THEN fl = 0: EXIT FOR
        END IF
    NEXT
    IF fl THEN
        PLIMIT = FIX(SQR(X * 1.0#))
        FOR Y = 9999993 TO PLIMIT STEP 2
            IF X MOD Y = 0 THEN fl = 0: EXIT FOR
        NEXT
    END IF
    IF fl THEN
        PRINT X
        GOSUB setmytitle
        _DISPLAY
    ELSE
        PVAL(u) = 0
    END IF
NEXT

IF q = 0 THEN
    fo = FREEFILE
    IF _FILEEXISTS(outf$) THEN
        OPEN outf$ FOR APPEND AS fo
    ELSE
        OPEN outf$ FOR OUTPUT AS fo
    END IF
    FOR u = 1 TO v
        IF PVAL(u) > 0 THEN
            PRINT #fo, STR$(PVAL(u))
        END IF
    NEXT
    CLOSE fo
    fo = FREEFILE
    OPEN dataf$ FOR OUTPUT AS fo
    PRINT #fo, sop
    CLOSE fo
    COLOR 14
    PRINT "Completed!"
    _DISPLAY
    _DELAY 3
END IF
SYSTEM

setmytitle:
_TITLE "Prime 20 Digits"
RETURN


FUNCTION makeuserprof$ (s$)
    IF s$ = "" THEN
        makeuserprof$ = ""
        EXIT FUNCTION
    END IF
    mypath$ = s$

    ''added NA27
    IF LEFT$(mypath$, 2) = ".\" OR LEFT$(mypath$, 2) = "./" THEN
        afile$ = "qb64curdir.txt"
        b$ = "%USERPROFILE%"
        IF _FILEEXISTS(afile$) THEN
            c$ = ""
            fi = FREEFILE
            OPEN afile$ FOR INPUT AS fi
            IF NOT EOF(fi) THEN
                LINE INPUT #fi, c$
                c$ = RTRIM$(LTRIM$(c$))
            END IF
            CLOSE fi
            IF c$ <> "" THEN
                IF RIGHT$(c$, 1) = "\" OR RIGHT$(c$, 1) = "/" THEN
                    b$ = LEFT$(c$, LEN(c$) - 1)
                ELSE
                    b$ = c$
                END IF
                mypath$ = b$ + MID$(mypath$, 2)
            END IF
        END IF
    END IF

    u = INSTR(mypath$, "/")
    v = INSTR(mypath$, "\")
    IF u = 0 AND v = 0 THEN
        makeuserprof$ = ""
        EXIT FUNCTION
    END IF
    IF u > 0 THEN
        ReplaceString2 mypath$, "/", "\", 0
    END IF
    u = INSTR(mypath$, "%")
    IF u > 0 THEN
        v = INSTR(u + 1, mypath$, "%\")
    ELSE
        u = 0
    END IF
    IF u = 1 AND v > u THEN
        ''continue function code
    ELSE
        makeuserprof$ = mypath$
        EXIT FUNCTION
    END IF
    a$ = UCASE$(mypath$)
    uprof$ = ENVIRON$("USERPROFILE")
    FOR i = 1 TO 6
        SELECT CASE i
            CASE 1
                b$ = "%USERPROFILE%"
                c$ = uprof$
            CASE 2
                b$ = "%USERPROF%"
                ''c$ same as case 1
            CASE 3
                b$ = "%MUSIC%"
                c$ = uprof$ + "\Music"
            CASE 4
                b$ = "%DOCS%"
                c$ = uprof$ + "\Documents"
            CASE 5
                b$ = "%DOCU%"
                c$ = uprof$ + "\Documents"
            CASE 6
                b$ = "%PIC%"
                c$ = uprof$ + "\Pictures"
        END SELECT
        IF INSTR(a$, b$) THEN
            ReplaceString2 mypath$, b$, c$, 1
            EXIT FOR
        END IF
    NEXT
    makeuserprof$ = mypath$
END FUNCTION

FUNCTION returntfn$ (femplate$)
    STATIC sernum AS LONG, sernumset AS _BIT
    sret$ = ""
    a$ = LTRIM$(RTRIM$(femplate$))
    IF a$ <> "" THEN
        u = INSTR(a$, "|")
        IF u > 0 THEN
            IF LEFT$(a$, 1) = "%" OR INSTR(a$, "/") > 0 THEN
                a$ = makeuserprof$(a$)
            END IF
            IF sernumset = 0 THEN
                sernumset = NOT sernumset
                sernum = 1
            END IF
            IF RIGHT$(a$, 1) <> "\" THEN
                DO
                    n$ = LTRIM$(STR$(sernum))
                    IF LEN(n$) < 4 THEN n$ = LEFT$("0000", 4 - LEN(n$))
                    sret$ = a$
                    ReplaceString2 sret$, "|", n$, 1
                    sernum = sernum + 1
                LOOP UNTIL NOT _FILEEXISTS(sret$)
            END IF
        END IF
    END IF
    returntfn$ = sret$
END FUNCTION

SUB ReplaceString2 (tx AS STRING, sfind AS STRING, repl AS STRING, numtimes AS _UNSIGNED LONG)
    DIM s AS STRING, t AS STRING
    DIM ls AS _UNSIGNED LONG, lx AS _UNSIGNED LONG, count AS _UNSIGNED LONG, j AS _UNSIGNED LONG
    IF (tx = "") OR (sfind = "") OR (sfind = repl) OR (LEN(sfind) > LEN(tx)) THEN EXIT SUB
    s = UCASE$(sfind): t = UCASE$(tx)
    ls = LEN(s)
    count = 0
    goahead = 1
    DO
        u = INSTR(t, s)
        IF u > 0 THEN
            tx$ = LEFT$(tx, u - 1) + repl + MID$(tx, u + ls)
            t = UCASE$(tx)
            IF numtimes > 0 THEN count = count + 1: IF count >= numtimes THEN goahead = 0
        ELSE
            goahead = 0
        END IF
    LOOP WHILE goahead
END SUB

'$INCLUDE: 'tprime.bi'

As the program is presented, it looks for a file named "prime19dig.txt" in the user's Documents directory. This file is over 80MB in size! Do not try to open it in Notepad or any other text editor that cannot handle files larger than 1MB. I created it and a few others with a Lua script, being more interested in patterns of the digits. It's because trying to go sequentially would be very slow and come up with numbers boring to look at or could peel the paint from the walls. Such as 10000000002835706257.

This program only takes numbers from a list and figures out if they're prime or not. If prime they are listed on the screen and they are also sent to an output file called "prime19dig-out.txt". The program should end in 5 to 10 minutes on a dual-core CPU laptop created within the last five years. Then the user could choose to run it again to pick up where it left off. This could be done for a while until it runs out of "candidates" and it starts from the beginning -- then you say give me another 80MB file. This information is saved in a file called "prime19dig-pref.txt", should not be tampered by anybody who hasn't read and understood the source code!

I have indeed created another version of this program that focused only on numbers higher than 18 followed by 18 zeros. But the program posted here is only one example of what could be done with 64-bit integers. Imagine when 128-bit becomes the norm later on...

Note: there was another number 10043560040404043561 that figured in one of my fantasy stories, about a rock band that created a song singing it out. It was supposed to be for LOL's. Imagine like Katy Perry or Springsteen singing, "zero zero four, zero four, zero four, zero four, three five six!" Sorry not a good judge with female solo artists after Madonna and others ruined my sense for pop-rock forever. But that integer is not prime, must add six to it. Wink

(Maybe I should use an external file-sharing service because I made one attempt to upload but it didn't display in the available list of attachments, although it reflected the large jump in size of total attachments. I will have to delete one of the two attempts later, if it could be found.)


.zip   prime19dig-by-mnrvovrfc.zip (Size: 8.64 MB / Downloads: 54)

Print this item

  Spawn of Cardioid
Posted by: CharlieJV - 03-07-2023, 02:32 AM - Forum: QBJS, BAM, and Other BASICs - Replies (3)

A for the giggles mod of @bplushttps://qb64phoenix.com/forum/showthread...2#pid14122

After you open the link below to run the program:

  • to pause the action, click and hold (or touch and hold for touch device) on the program's window
  • to have a new random colour scheme, refresh the page

Spawn of Cardioid

Print this item

  Fastest image refresh
Posted by: TerryRitchie - 03-06-2023, 11:04 PM - Forum: General Discussion - Replies (2)

When using graphics, especially in games, it's often necessary to clear an image from a surface before placing another image in its place because of alpha transparency issues. The method I usually use to do this was way to slow for the current project I'm working on. So I started playing with and timing alternative methods.

Thought I would pass this tidbit of information along.

Using a 512x736 32bit image and each method repeated 10000 times I get the following.

My usual method: 0.644 seconds

Odest = _DEST
_DEST Image
CLS
_DEST Odest


Using LINE BF method: 0.620 seconds (curious that LINE is faster than CLS)

Odest = _DEST
_DEST Image
LINE(0, 0)-(_WIDTH(Image) - 1, _HEIGHT(Image) -1), _RGB32(0, 0, 0), BF
_DEST Odest


Freeing and recreating: 0.042 to 0.061 seconds (no idea why it fluctuates so much)

Iwidth = _WIDTH(Image)
Iheight = _HEIGHT(Image)
_FREEIMAGE Image
Image = _NEWIMAGE(Iwidth, Iheight, 32)

Well, as you can see, the 3rd method is superior. I created a simple subroutine to handle this for me now:

SUB RENEW_IMAGE (Image AS LONG)

    DIM Iwidth AS INTEGER '  width of image
    DIM Iheight AS INTEGER ' height of image

    Iwidth = _WIDTH(Image) '                get width of image
    Iheight = _HEIGHT(Image) '              get height of image
    _FREEIMAGE Image '                      remove the image from RAM
    Image = _NEWIMAGE(Iwidth, Iheight, 32) ' recreate a blank surface

END SUB

Print this item

  Adding multiple files to the EXE
Posted by: Petr - 03-06-2023, 08:29 PM - Forum: Petr - No Replies

To add more files to EXE you will need the programs listed in this thread, but first also the PMF2 compressor program which is in the previous thread:  https://qb64phoenix.com/forum/showthread...5#pid14125

Be careful what you do, I always recommend COPYING the program to another folder and putting the files there. I've tried it all and it's a working procedure. The described procedure assumes that you have already created a PMF2 file that contains all the files you need to include in the EXE file.


STEP 1:

Code: (Select All)
'STEP 1: Your EXE file is named Step1 (for example, but EXE file name must be the same as second parameter for ExtractExe!)
'        Copy to this EXE ExtractEse, and all need sources for PMF2 extractor as in this example
'        DO NOT RUN IT, MAKE EXE FILE ONLY and then goto step 2 in example 2 for completing this operation.


Type Header '                        Header 1
    ID As String * 4 '               file format signature PMF2
    Files_Total As Long '            how much files container contains
End Type

Type File_List '                     Header 2
    FileNameLEN As _Unsigned _Byte 'Lenght for file name (example: Untitled.bas = file name lenght = 12)
    Compress As _Unsigned _Byte '   Compression. 0 = not used, 1 = used (_INFLATE$)
    Offset As Long '                Area in file (offset) where start this file data
    BlockSize As Long '             Byte size (how much bytes is used for this file in PMF2 container, size after compression if used)
End Type




Dim Shared PMF2H As Header
ReDim Shared PMF2FL(0) As File_List 'each added file has its own index in this field

Const Show = -1
Const Unpack_All = 0



ExtractExe "archive.pmf2", "Step1.exe" 'get PMF2 from EXE
_Delay 1 'is need!
UnPack_PMF2 "archive.pmf2", Unpack_All ' get files from PMF2

'your program is here


End


Sub ExtractExe (OutputFile As String, ThisExeFile As String)
    Dim As Long ExeSize
    TEF = FreeFile
    Open ThisExeFile For Binary As #TEF
    Get #TEF, LOF(TEF) - 3, ExeSize
    '  Print "Original EXE size: "; ExeSize
    If ExeSize < 0 Then Print "Invalid record.": End
    OutputFileBinary$ = Space$(LOF(TEF) - ExeSize - 4)
    Get #TEF, ExeSize + 1, OutputFileBinary$
    Close #TEF
    '    Print "V RAM je "; Len(OutputFileBinary$); "bytes"
    Open OutputFile For Binary As #TEF
    Put #TEF, , OutputFileBinary$
    OutputFileBinary$ = ""
    Close #TEF
End Sub

Sub UnPack_PMF2 (ArchiveName As String, METHOD As _Byte)
    'method: -1 = show files in PMF2 file
    '         0 = UnPack all files from PMF2 file
    '       > 0 = Unpack file writed in this position in PMF2 file (-1) - use record number printed in Show mode

    If _FileExists(ArchiveName) Then
        FF = FreeFile
        Open ArchiveName For Binary As FF
        Get FF, , PMF2H '                                       read head 1

        If PMF2H.ID = "PMF2" Then
            If PMF2H.Files_Total > -1 Then
                ReDim As File_List PMF2FL(PMF2H.Files_Total)
                Get FF, , PMF2FL() '                            read head 2
                ReDim As String Names(PMF2H.Files_Total)

                For ReadFileNames = 0 To PMF2H.Files_Total '    read files names in file
                    N$ = Space$(PMF2FL(ReadFileNames).FileNameLEN)
                    Get FF, , N$
                    Names(ReadFileNames) = N$
                    N$ = ""
                Next

                Select Case METHOD '                                                                                 This is information block (Show)
                    Case -1
                        Print "Pos. File name      Compressed          Size in PMF2 file [bytes]"
                        Print "-----------------------------------------------------------------"
                        For ReadContent = 0 To PMF2H.Files_Total
                            F_Name$ = Names(ReadContent)
                            If Len(F_Name$) > 15 Then F_Name$ = Mid$(F_Name$, 1, 12) + "..."
                            If PMF2FL(ReadContent).Compress Then F_Compress$ = "Yes" Else F_Compress$ = "No"
                            F_Size& = PMF2FL(ReadContent).BlockSize

                            ddd = Len(LTrim$(Str$(ReadContent)))
                            Print LTrim$(Str$(ReadContent + 1)) + "."; Spc(4 - ddd); F_Name$; Spc(18 - Len(F_Name$) + ddd); F_Compress$; Spc(12); F_Size&
                            If ReadContent Mod 18 = 0 And ReadContent > 0 Then
                                Print "Press any key for next..."
                                Sleep
                                Cls
                                Print "Pos. File name      Compressed          Size in PMF2 file [bytes]"
                                Print "-----------------------------------------------------------------"
                            End If
                        Next
                    Case 0 '                                        extract it
                        For UnPack = 0 To PMF2H.Files_Total
                            If _FileExists(Names(UnPack)) Then 'add automaticaly parentheses and number, if file exists
                                u = 0
                                Do Until _FileExists(Names(UnPack)) = 0
                                    Dot = InStr(1, Names(UnPack), ".") - 1
                                    Test$ = Mid$(Names(UnPack), 1, Dot) + "(" + _Trim$(Str$(u) + ")") + Right$(Names(UnPack), PMF2FL(UnPack).FileNameLEN - Dot)
                                    If _FileExists(Test$) = 0 Then Names(UnPack) = Test$
                                    Test$ = ""
                                    u = u + 1
                                Loop
                            End If
                            EF = FreeFile
                            Open Names(UnPack) For Binary As EF
                            N$ = Space$(PMF2FL(UnPack).BlockSize)
                            Get FF, , N$
                            If PMF2FL(UnPack).Compress Then Rec$ = _Inflate$(N$) Else Rec$ = N$
                            Put EF, , Rec$
                            N$ = ""
                            Rec$ = ""
                            Close EF
                        Next UnPack
                    Case Is > 0 '                   unpack just one concrete file
                        Fi = METHOD - 1
                        If Fi > UBound(Names) Then Print "Invalid record add as parameter for Unpack_PMF2 SUB!": Sleep 3: End
                        If _FileExists(Names(Fi)) Then 'add automaticaly parentheses and number, if file exists
                            u = 0
                            Do Until _FileExists(Names(Fi)) = 0
                                Dot = InStr(1, Names(Fi), ".") - 1
                                Test$ = Mid$(Names(Fi), 1, Dot) + "(" + _Trim$(Str$(u) + ")") + Right$(Names(Fi), PMF2FL(Fi).FileNameLEN - Dot)
                                If _FileExists(Test$) = 0 Then Names(Fi) = Test$
                                Test$ = ""
                                u = u + 1
                            Loop
                        End If

                        EF = FreeFile
                        Open Names(Fi) For Binary As EF
                        N$ = Space$(PMF2FL(Fi).BlockSize)
                        Seek FF, PMF2FL(Fi).Offset
                        Get FF, , N$
                        If PMF2FL(Fi).Compress Then Rec$ = _Inflate$(N$) Else Rec$ = N$
                        Put EF, , Rec$
                        N$ = ""
                        Rec$ = ""
                        Close EF
                End Select
            Else
                Print "Invalid record: Number of files in PMF2 file: "; PMF2H.Files_Total: Sleep 3: End
            End If
        Else
            Print "Invalid PMF2 file format. ": Sleep 3: End
        End If
    Else
        Print "PMF2 file: "; ArchiveName$; " not exists. Can not continue.": Sleep 3: End
    End If
End Sub

Place to your program PMF2 headers and source code as in this example. COMPILE IT, DO NOT RUN IT! We need EXE file named Step1.exe, this program is named as Step1.bas it is very important for correct function!

Then, when EXE file is done, we can add files to EXE - Step 2:

Code: (Select All)
'STEP 2: USE PMF2 archiver for compress more files to PMF2 and then insert it to EXE file.

AddToExe "pmf2test2023.pmf2", "step1.exe"
End

Sub AddToExe (File As String, ExeFile As String)
    Dim As Long FileSize
    If _FileExists(ExeFile) Then
        If _FileExists(File) Then
            Af = FreeFile
            Open File For Binary As #Af
            FileBin$ = Space$(LOF(Af))
            Get #Af, , FileBin$
            Close #Af
            Af = FreeFile
            Open ExeFile For Binary As #Af
            FileSize = LOF(Af)
            Seek #Af, LOF(Af) + 1
            Put #Af, , FileBin$
            Put #Af, , FileSize
            Close #Af
            FileBin$ = ""
        Else Print "Sorry, file "; File; "not exists"
        End If
    Else Print "Sorry, file "; ExeFile; "not exists."
    End If
End Sub

Program insert archive file pmf2test2023.pmf2 to file test1.exe  

If you do all correct, after running program Step1.exe all files from PMF2 are extracted to harddrive.

If there is interest, I am willing to modify the output of PMF2 so that the files are not saved to the hard disk, but to the computer's memory.

But then of course you have to have your own solution for working with these yours files.

Print this item

  Files packer/unpacker to one file
Posted by: Petr - 03-06-2023, 07:41 PM - Forum: Petr - Replies (2)

Let me introduce the PMF2 (that's my own file format) archiver. It is a compression program, the main advantage of which is that files can be compressed and decompressed using only QB64 directly from the source code. It allows you to view packed files and can unpack just one specific file or all files from the archive. It has a built-in feature that makes sure that if the unzipped file already exists on the hard drive, the new unzipped file will have a parenthesis with a number after the name, just like Windows does.

So you get the option to have many files in a single file with the option to extract just one specific one or all files.
Higher operations, such as updating a specific file in the archive, or deleting one file in the archive are not yet supported, I also saved something for another time, that's clear after all Smile

Well, it's probably dawning on someone. So who asked how to add more files to the EXE? I'll add a new thread directly to that in a moment.  Angel



rewrite in source code file names for your correct files in array FL for trying!

Code: (Select All)
Type Header '                        Header 1
    ID As String * 4 '               file format signature PMF2
    Files_Total As Long '            how much files container contains
End Type

Type File_List '                     Header 2
    FileNameLEN As _Unsigned _Byte 'Lenght for file name (example: Untitled.bas = file name lenght = 12)
    Compress As _Unsigned _Byte '   Compression. 0 = not used, 1 = used (_INFLATE$)
    Offset As Long '                Area in file (offset) where start this file data
    BlockSize As Long '             Byte size (how much bytes is used for this file in PMF2 container, size after compression if used)
End Type




Dim Shared PMF2H As Header
ReDim Shared PMF2FL(0) As File_List 'each added file has its own index in this field

Const Show = -1
Const Unpack_All = 0



Dim FL(13) As String '    add here your own files for test it. Array can not have NONE empty records and must start from zero AND ALL RECORDS IN ARRAY FL() MUST BE VALID, or program automaticaly end, because file not exists.
FL(0) = "mrakyM.gif"
FL(1) = "NEW jezis.gif"
FL(2) = "NEW jezisek.gif"
FL(3) = "NEW sane.gif"
FL(4) = "NEW skret.gif"
FL(5) = "NEW sob.gif"
FL(6) = "New sprez.gif"
FL(7) = "NEWest1.gif"
FL(8) = "NEWest2.gif"
FL(9) = "NEWest3.gif"
FL(10) = "NEWest4.gif"
FL(11) = "NEWest5.gif"
FL(12) = "test.mp3"
FL(13) = "mech.ogg" '!all 13 records must contains valid file names! of course your limit for this array size (all files size) is limited just by your RAM size (tested)
'                    if you add here some 1.3 GB movies, is possible it crash  with message OUT OF MEMORY, but.... why add so much? Solution for so big file but exists:
'                    Break really big file down into smaller units and put it back together as you unpack. But I didn't deal with that here.



Pack_PMF2 "Pmf2test2023", FL() '                   create Pmf2test2023.pmf2 file container
UnPack_PMF2 "Pmf2test2023.pmf2", Show '            just read heads from created file Pmf2test and show you, which files are in PMF2 container and compressed file size in archive pmf2
Sleep

UnPack_PMF2 "Pmf2test2023.pmf2", Unpack_All '      Extract all files from PMF2 container (now is set to add parentheses and number if file already exists on harddrive)
UnPack_PMF2 "Pmf2test2023.pmf2", 2 '               Unpack just file nr.2 from archive


'BUT - You can also extract just one file from archive, not all at once: First look, which number is file, you need extract - use  UnPack_PMF2 "Pmf2test.pmf2", Show
'      look to left to "Pos". Now add this number and use it (for example for file 3 in PMF2)  UnPack_PMF2 "Pmf2test.pmf2", 3

'      next options be added later, but is released now, for free use for you all, so all can do Christmas theme :)
'      So if you can package many files into one file... who asked about how to add multiple files to an EXE file, eh?
End



Sub UnPack_PMF2 (ArchiveName As String, METHOD As _Byte)
    'method: -1 = show files in PMF2 file
    '         0 = UnPack all files from PMF2 file
    '       > 0 = Unpack file writed in this position in PMF2 file (-1) - use record number printed in Show mode

    If _FileExists(ArchiveName) Then
        FF = FreeFile
        Open ArchiveName For Binary As FF
        Get FF, , PMF2H '                                       read head 1

        If PMF2H.ID = "PMF2" Then
            If PMF2H.Files_Total > -1 Then
                ReDim As File_List PMF2FL(PMF2H.Files_Total)
                Get FF, , PMF2FL() '                            read head 2
                ReDim As String Names(PMF2H.Files_Total)

                For ReadFileNames = 0 To PMF2H.Files_Total '    read files names in file
                    N$ = Space$(PMF2FL(ReadFileNames).FileNameLEN)
                    Get FF, , N$
                    Names(ReadFileNames) = N$
                    N$ = ""
                Next

                Select Case METHOD '                                                                                 This is information block (Show)
                    Case -1
                        Print "Pos. File name      Compressed          Size in PMF2 file [bytes]"
                        Print "-----------------------------------------------------------------"
                        For ReadContent = 0 To PMF2H.Files_Total
                            F_Name$ = Names(ReadContent)
                            If Len(F_Name$) > 15 Then F_Name$ = Mid$(F_Name$, 1, 12) + "..."
                            If PMF2FL(ReadContent).Compress Then F_Compress$ = "Yes" Else F_Compress$ = "No"
                            F_Size& = PMF2FL(ReadContent).BlockSize

                            ddd = Len(LTrim$(Str$(ReadContent)))
                            Print LTrim$(Str$(ReadContent + 1)) + "."; Spc(4 - ddd); F_Name$; Spc(18 - Len(F_Name$) + ddd); F_Compress$; Spc(12); F_Size&
                            If ReadContent Mod 18 = 0 And ReadContent > 0 Then
                                Print "Press any key for next..."
                                Sleep
                                Cls
                                Print "Pos. File name      Compressed          Size in PMF2 file [bytes]"
                                Print "-----------------------------------------------------------------"
                            End If
                        Next
                    Case 0 '                                        extract it
                        For UnPack = 0 To PMF2H.Files_Total
                            If _FileExists(Names(UnPack)) Then 'add automaticaly parentheses and number, if file exists
                                u = 0
                                Do Until _FileExists(Names(UnPack)) = 0
                                    Dot = InStr(1, Names(UnPack), ".") - 1
                                    Test$ = Mid$(Names(UnPack), 1, Dot) + "(" + _Trim$(Str$(u) + ")") + Right$(Names(UnPack), PMF2FL(UnPack).FileNameLEN - Dot)
                                    If _FileExists(Test$) = 0 Then Names(UnPack) = Test$
                                    Test$ = ""
                                    u = u + 1
                                Loop
                            End If
                            EF = FreeFile
                            Open Names(UnPack) For Binary As EF
                            N$ = Space$(PMF2FL(UnPack).BlockSize)
                            Get FF, , N$
                            If PMF2FL(UnPack).Compress Then Rec$ = _Inflate$(N$) Else Rec$ = N$
                            Put EF, , Rec$
                            N$ = ""
                            Rec$ = ""
                            Close EF
                        Next UnPack
                    Case Is > 0 '                   unpack just one concrete file
                        Fi = METHOD - 1
                        If Fi > UBound(Names) Then Print "Invalid record add as parameter for Unpack_PMF2 SUB!": Sleep 3: End
                        If _FileExists(Names(Fi)) Then 'add automaticaly parentheses and number, if file exists
                            u = 0
                            Do Until _FileExists(Names(Fi)) = 0
                                Dot = InStr(1, Names(Fi), ".") - 1
                                Test$ = Mid$(Names(Fi), 1, Dot) + "(" + _Trim$(Str$(u) + ")") + Right$(Names(Fi), PMF2FL(Fi).FileNameLEN - Dot)
                                If _FileExists(Test$) = 0 Then Names(Fi) = Test$
                                Test$ = ""
                                u = u + 1
                            Loop
                        End If

                        EF = FreeFile
                        Open Names(Fi) For Binary As EF
                        N$ = Space$(PMF2FL(Fi).BlockSize)
                        Seek FF, PMF2FL(Fi).Offset
                        Get FF, , N$
                        If PMF2FL(Fi).Compress Then Rec$ = _Inflate$(N$) Else Rec$ = N$
                        Put EF, , Rec$
                        N$ = ""
                        Rec$ = ""
                        Close EF
                End Select
            Else
                Print "Invalid record: Number of files in PMF2 file: "; PMF2H.Files_Total: Sleep 3: End
            End If
        Else
            Print "Invalid PMF2 file format. ": Sleep 3: End
        End If
    Else
        Print "PMF2 file: "; ArchiveName$; " not exists. Can not continue.": Sleep 3: End
    End If
End Sub





Sub Pack_PMF2 (ArchiveName As String, FileList() As String) 'Array in input contains file names for add to archive
    If LCase$(Right$(ArchiveName, 5)) <> ".pmf2" Then ArchiveName$ = ArchiveName$ + ".pmf2"
    PMF2H.ID = "PMF2"
    PMF2H.Files_Total = UBound(FileList)

    Dim Binaries(PMF2H.Files_Total) As String, Size As Long, C As _Byte
    Dim Names(PMF2H.Files_Total) As String, Begin As Long

    ReDim PMF2FL(PMF2H.Files_Total) As File_List
    FF = FreeFile
    For Names_And_Sizes = 0 To PMF2H.Files_Total
        If _FileExists(FileList(Names_And_Sizes)) Then
            Open FileList(Names_And_Sizes) For Binary As FF
            Size = LOF(FF) 'if is copression not used, is block size the same as file size
            test$ = Space$(Size)
            Get #FF, , test$
            Close #FF
            Compressed$ = _Deflate$(test$)
            If Len(Compressed$) < Size Then Binaries(Names_And_Sizes) = Compressed$: C = 1: Size = Len(Compressed$) Else Binaries(Names_And_Sizes) = test$: C = 0
            PMF2FL(Names_And_Sizes).BlockSize = Size 'This Size and previous is different, if compression is used, or not (row 200)
            Compressed$ = ""
            test$ = ""
            PMF2FL(Names_And_Sizes).FileNameLEN = Len(FileList(Names_And_Sizes))
            Names(Names_And_Sizes) = FileList(Names_And_Sizes)
            PMF2FL(Names_And_Sizes).Compress = C
            PMF2FL(Names_And_Sizes).Offset = 0&
        Else Print "Error: Can not add file "; FileList(Names_And_Sizes); " to archive, because this file not exists. Operation aborted!": Sleep 3: End
        End If
    Next

    If _FileExists(ArchiveName$) Then Kill ArchiveName$ 'Here is next place for upgrade (dialog File exists: Replace / Rename / Skip / Add files) - now set for rewrite  [PMF2 file with the same name!]
    Open ArchiveName$ For Binary As FF


    Put #FF, , PMF2H
    BytePos = Seek(FF)
    Put #FF, , PMF2FL()

    'insert files names to PMF2
    For NameIt = 0 To PMF2H.Files_Total
        n$ = Names(NameIt)
        Put #FF, , n$
    Next
    n$ = ""

    'insert start offsets and files binary data
    For starts = 0 To PMF2H.Files_Total
        Begin = Seek(FF)
        PMF2FL(starts).Offset = Begin 'record real End Offsets sizes
        n$ = Binaries(starts)
        Put #FF, , n$
        n$ = ""
    Next

    'upgrade END OFFSETs info for all files in PMF2 in head2
    Put #FF, BytePos, PMF2FL() '                     Replace Head 2 - now contains also end offsets for files in PMF2
    Close #FF
End Sub

Print this item

  Getting ready for Pi-Day
Posted by: bplus - 03-06-2023, 07:08 PM - Forum: Programs - Replies (6)

Piral:

Code: (Select All)
_Title "Piral" ' b+ 2023-03-05
p$ = "3.14159265358979323846264338327950288419716939937510"
p$ = p$ + "58209749445923078164062862089986280348253421170679"
p$ = p$ + "82148086513282306647093844609550582231725359408128"
p$ = p$ + "48111745028410270193852110555964462294895493038196"
p$ = p$ + "44288109756659334461284756482337867831652712019091"
p$ = p$ + "45648566923460348610454326648213393607260249141273"
p$ = p$ + "72458700660631558817488152092096282925409171536436"
p$ = p$ + "78925903600113305305488204665213841469519415116094"
p$ = p$ + "33057270365759591953092186117381932611793105118548"
p$ = p$ + "07446237996274956735188575272489122793818301194912"
p$ = p$ + "98336733624406566430860213949463952247371907021798"
p$ = p$ + "60943702770539217176293176752384674818467669405132"
p$ = p$ + "00056812714526356082778577134275778960917363717872"
p$ = p$ + "14684409012249534301465495853710507922796892589235"
p$ = p$ + "42019956112129021960864034418159813629774771309960"
p$ = p$ + "51870721134999999837297804995105973173281609631859"
p$ = p$ + "50244594553469083026425223082533446850352619311881"
p$ = p$ + "71010003137838752886587533208381420617177669147303"
p$ = p$ + "59825349042875546873115956286388235378759375195778"
p$ = p$ + "18577805321712268066130019278766111959092164201989"

Screen _NewImage(710, 710, 32)
_ScreenMove 300, 50
xc = _Width / 2: yc = _Height / 2 - 4
i = 1
lastx = xc: lasty = yc
_PrintString (xc - 4, yc - 8), Mid$(p$, i, 1)
For a = 0 To 23 * _Pi Step .01
    x = xc + a * 5 * Cos(a): y = yc + a * 5 * Sin(a)
    If _Hypot(x - lastx, y - lasty) >= 20 Then
        i = i + 1
        ' Circle (x - 2, y - 2), 10
        _PrintString (x - 4, y - 8), Mid$(p$, i, 1)
        lastx = x: lasty = y
    End If
Next
Sleep

Print this item

  Blockchain
Posted by: Dimster - 03-06-2023, 03:05 PM - Forum: General Discussion - Replies (9)

Wondering if any of you guys have done any coding with Blockchain. As I understand it, there is basically a record which is not written until all records are searched and the new record to be written is deemed valid in someway before it can be written to the chain of records. The two main/key points I take away from this is that VALIDATION before writing the record can be very complex and secondly, the chain must be sequential or there has to be an index table that allows the records to be found in the order in which they were written. So in pseudocode the layout would be something like this:


- compose a validation routine which comprises decisions on what is accurate and acceptable

- Input a record

- Review the present chain
  a:for duplication of inputted record
  b:for a location in chain where the inputted record will be written
  c: subject the inputted record to the validation routine
  d: write the inputted record or reject the record.
  e: keep an index as to where this inputted record can be found

The blockchain that I'm trying to work on is not for public input but rather something which raises the accuracy of the data in the data base and improves retrieval of any given small piece of data stored. In this regard, what I don't have in the above pseudocode layout is a search routine. It would seem I need 2 search routines, one associated with the Review of the chain before writing a record and one associated with a search of data where No record is intended on being written. A number of years ago I started on a blockchain program but found it was going to be extremely large and abandoned it. So I'm looking at it again but trying to conceptualize a smaller program.

Print this item

Brick Sudoki solver
Posted by: BDS107 - 03-06-2023, 12:42 PM - Forum: Programs - Replies (2)

Here is a small program for solving a Sudoku.
Start the program, press "C" to clear the field. Then fill in the sudoku that you can find in newspapers or other media and finally press "S" to solve the sudoku.
You cannot solve it yourself, the computer does all the work for you.
Comments are welcome  Big Grin


.bas   sudoku.bas (Size: 10.37 KB / Downloads: 86)



Attached Files Thumbnail(s)
   
Print this item

  When you try a new lib and get a REQUIRE TO UPDATE
Posted by: NasaCow - 03-06-2023, 02:47 AM - Forum: Site Suggestions - Replies (6)

Would help me notice a new release sooner if latest release hyperline also had the version or have it displayed somewhere on the home page??? Guessing I missed 3.50 altogther  Big Grin

Just my two cents  Cool

BTW, requrie to update is a great touch for peeps like me   Heart

Print this item

  Spring Banner Contest! (2023)
Posted by: SMcNeill - 03-06-2023, 02:19 AM - Forum: General Discussion - Replies (121)

Back in December, we held a Christmas banner contest which Bplus won by blowing away the competition with a very nice Christmas themed banner.  Now that Spring is right around the corner, it's time for folks to showcase their abilities and to have fun creating a Spring themed banner for our site!  

Can Bplus hold on to his accolades and design another winning banner for the Spring season?  Will someone else step up and knock him off his throne as our resident designer?  The world (of QB64 Phoenix Edition, anyway) is anxiously holding its breath to find out!

Rules are rather simple -- Spend the time between now and the 18th of March (2023) to design and create the best logo and share that you can.  A poll will be placed up on Sunday, the 19th of March (Spring-Eve) and folks will have all day to vote for their favorite banner.  The one with the most votes on the 20th will have their banner placed prominently for display so everyone can enjoy their work and effort!

Banner Image size should be 1400x256 to match what we currently have, but with that single limitation in mind, the world is your imagination!  Have fun and see what you can create that screams "Spring" "Phoenix"  "QB64" "Steve is Awesome!!!"... 

Big Grin

Print this item