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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 762
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,034
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,261
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 315
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155

 
  drops
Posted by: James D Jarvis - 07-19-2022, 05:12 PM - Forum: Programs - Replies (5)

Fiddling with the mouse and saw a similar program online so here is  drops.


Code: (Select All)
Screen _NewImage(800, 500, 32)
_Title "drops"
Dim dd(6000, 3)
Color _RGB32(250, 250, 250), _RGB32(0, 0, 255)
dc = 0
Randomize Timer
Do
    Cls
    _Limit 6000
    Do While _MouseInput
        'check for the mouse pointer in the image drawign area

        If _MouseButton(1) Then
            x = _MouseX
            y = _MouseY
            PSet (x, y), _RGB32(100, 100, 100)
            dc = dc + 1
            If dc > 6000 Then dc = 1
            dd(dc, 1) = x
            dd(dc, 2) = y
            dd(dc, 3) = Int(Rnd * 9) + 3

        End If
    Loop
    If dc > 1 Then
        For n = 1 To dc
            If dd(dc, 3) < 255 Then
                Circle (dd(n, 1), dd(n, 2)), dd(n, 3), _RGB32(0, 0, dd(n, 3) * 2)
                If dd(n, 3) < 100 Then Circle (dd(n, 1), dd(n, 2)), dd(n, 3) - Int(Rnd * 3) + 1, _RGB32(200, 200, 255 - Int(dd(n, 3) / 8))
                dd(n, 3) = dd(n, 3) + 3
            Else
                dd(n, 3) = 255
            End If
        Next n

    End If
    Locate 1, 1
    Print dc; " drops, click and drag your mouse,  press <ESC> to quit"
    _Delay 0.05
    _Display

    aa$ = InKey$
Loop Until aa$ = Chr$(27)

Print this item

  Command list
Posted by: vinceg2022 - 07-19-2022, 06:24 AM - Forum: Help Me! - Replies (13)

Hi all

I am new here and hope I am not posting somewhere not relevant.

I keep coming back to QB64 from programming in other languages because of it simplicity and power. Because of its vast array of keywords and commands I find myself spending more time checking the syntax, by going back and forward in the IDE, and as much as its convenient having the help there in the IDE, I find it helpful having some sort of document (PDF or DOC) with the command, a brief one line description and the basic syntax of the command. I have looked around on Google and searched the forum briefly, but cannot see anything that might be similar.

Does anyone know of anywhere I could get such a thing? I was going to just set one up myself, but seemed a bit overkill if it already exists.

Thanks in advance for any help.

Vince

Print this item

  rounding numbers and converting to string (hiding scientific notation)
Posted by: madscijr - 07-18-2022, 05:40 PM - Forum: Help Me! - Replies (9)

A looong time ago, on the old qb64.org forums, we discussed rounding numbers, and out of it came some functions:

For rounding type _FLOAT:
FUNCTION Round## (num##, digits%)
FUNCTION RoundUp## (num##, digits%)
FUNCTION RoundDown## (num##, digits%)
FUNCTION RoundScientific## (num##, digits%)

For rounding up (DOUBLE, SINGLE):
FUNCTION RoundUpDouble# (num#, digits%)
FUNCTION RoundUpSingle! (num!, digits%)

Convert to string, getting rid of scientific notation (DOUBLE, SINGLE):
FUNCTION DblToStr$ (n#)
FUNCTION SngToStr$ (n!)

From what I recall, they were all working. 
This weekend I dug up the code to use in a new program, 
and added the equivalent rounding and convert-to-string for all 3 types (_FLOAT, DOUBLE, SINGLE):

FUNCTION Round## (num##, digits%)
FUNCTION RoundUp## (num##, digits%)
FUNCTION RoundDown## (num##, digits%)
FUNCTION RoundScientific## (num##, digits%)

FUNCTION RoundDouble# (num#, digits%)
FUNCTION RoundUpDouble# (num#, digits%)
FUNCTION RoundDownDouble# (num#, digits%)
FUNCTION RoundScientificDouble# (num#, digits%)

FUNCTION RoundSingle! (num!, digits%) <- not sure this one works: when digits%=3, it rounds .31 to .32
FUNCTION RoundUpSingle! (num!, digits%)
FUNCTION RoundDownSingle! (num!, digits%)
FUNCTION RoundScientificSingle! (num!, digits%)

FUNCTION DblToStr$ (n#)
FUNCTION SngToStr$ (n!)
FUNCTION FloatToStr$ (n##)

Everything seems to work as expected, except for the function RoundUpSingle!, which for some reason rounds 0.31 to 0.32. 

I've been comparing code and checking everything and am not seeing what is causing this, or whether the problem is in RoundUpSingle! or SngToStr$. 

Maybe a second set of eyes would help... 
If someone could spare a couple minutes to look at this and find what's the wrong, it would be most appreciated!
These functions might come in handy for someone. 

Code: (Select All)
' ################################################################################################################################################################
' Rounding test
' ################################################################################################################################################################

' BOOLEAN CONSTANTS
CONST FALSE = 0
CONST TRUE = NOT FALSE

' GLOBAL VARIABLES a$=string, i%=integer, L&=long, s!=single, d#=double
DIM ProgramPath$: ProgramPath$ = LEFT$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\"))
DIM ProgramName$: ProgramName$ = MID$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\") + 1)

' START THE MAIN PROGRAM
main ProgramName$

' FINISH UP
SYSTEM ' return control to the operating system
PRINT ProgramName$ + " finished."
END

' /////////////////////////////////////////////////////////////////////////////
' Rounding and math.
' http://www.qb64.net/forum/index_PHPSESSID_gulg2aoa966472fnfhjkgp4i35_topic_14266-0/
'
' Rounding up to n decimal places?
' https://www.qb64.org/forum/index.php?topic=3605.0

' Quote from: SMcNeill on May 16, 2017, 06:57:17 pm
' Can also try:
'     INT(number * 100)/100
' Now that worked.
'     STR$(INT(myprice * 100) / 100)
' Perfectly drops all the numbers to 2 decimal places.
' What a relief. Thank you so much and everyone else who gave advice. :)

' Quote from: bplus on Today at 02:13:29 PM
' There is round Keyword check Wiki, might be _round
' you have to add 1/2 of 10 ^ DP to x
' EDIT: crap it's .5 * (1/10^DP)

SUB main (ProgName$)
    DIM RoutineName AS STRING:: RoutineName = "main"
    DIM in$
   
    DIM arrOutput(100, 4) AS STRING
    DIM s1!
    DIM s2!
    DIM d1#
    DIM d2#
    DIM f1##
    DIM f2##
    DIM iLine1 AS INTEGER
    DIM iLine2 AS INTEGER
    DIM iLine3 AS INTEGER
    DIM iLine4 AS INTEGER
    DIM iColumn AS INTEGER
    DIM iMaxLines AS INTEGER
    DIM dp% ' # decimal places
   
    Screen _NewImage(1280, 1024, 32)
   
   
   
   
   
   
   
    CLS
    iTotal = 0
    PRINT "Rounding numbers of type _FLOAT."
    PRINT "Thanks to SMcNeill, bplus, and Pete for your help."
    PRINT
   
    dp% = 2 ' ROUND TO 2 DECIMAL PLACES
   
    ' ROUND FLOAT TO dp% DECIMAL PLACES
    iColumn = 1
    iLine1 = 1: arrOutput(iLine1, iColumn) = "Round## FLOAT TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine1 = 2: arrOutput(iLine1, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR f1## = 0.3 TO 0.4 STEP 0.002
        iLine1 = iLine1 + 1
        f2## = Round##(f1##, dp%)
        arrOutput(iLine1, iColumn) = RightPadString$(FloatToStr$(f1##), 10, " ") + " -> " + RightPadString$(FloatToStr$(f2##), 10, " ")
    NEXT f1##
    iMaxLines = iLine1
   
    ' ROUND FLOAT UP TO 3 DECIMAL PLACES
    iColumn = 2
    iLine2 = 1: arrOutput(iLine2, iColumn) = "RoundUp## FLOAT TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine2 = 2: arrOutput(iLine2, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR f1## = 0.3 TO 0.4 STEP 0.002
        iLine2 = iLine2 + 1
        f2## = RoundUp##(f1##, dp%)
        arrOutput(iLine2, iColumn) = RightPadString$(FloatToStr$(f1##), 10, " ") + " -> " + RightPadString$(FloatToStr$(f2##), 10, " ")
       
        IF iLine2 > iMaxLines THEN
            iMaxLines = iLine2
            arrOutput(iLine2, 1) = ""
        END IF
    NEXT f1##
   
    ' ROUND FLOAT DOWN TO 3 DECIMAL PLACES
    iColumn = 3
    iLine3 = 1: arrOutput(iLine3, iColumn) = "RoundDown## FLOAT TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine3 = 2: arrOutput(iLine3, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR f1## = 0.3 TO 0.4 STEP 0.002
        iLine3 = iLine3 + 1
        f2## = RoundDown##(f1##, dp%)
        arrOutput(iLine3, iColumn) = RightPadString$(FloatToStr$(f1##), 10, " ") + " -> " + RightPadString$(FloatToStr$(f2##), 10, " ")
       
        IF iLine3 > iMaxLines THEN
            iMaxLines = iLine3
            arrOutput(iLine3, 1) = ""
        END IF
    NEXT f1##
   
    ' ROUND FLOAT SCIENTIFIC TO 3 DECIMAL PLACES
    iColumn = 4
    iLine4 = 1: arrOutput(iLine4, iColumn) = "RoundScientific## FLOAT TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine4 = 2: arrOutput(iLine4, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR f1## = 0.3 TO 0.4 STEP 0.002
        iLine4 = iLine4 + 1
        f2## = RoundScientific##(f1##, dp%)
        arrOutput(iLine4, iColumn) = RightPadString$(FloatToStr$(f1##), 10, " ") + " -> " + RightPadString$(FloatToStr$(f2##), 10, " ")
       
        IF iLine4 > iMaxLines THEN
            iMaxLines = iLine4
            arrOutput(iLine4, 1) = ""
        END IF
    NEXT f1##
   
    FOR iLine1 = 1 TO iMaxLines
        PRINT "" + _
            RightPadString$(arrOutput(iLine1, 1), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 2), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 3), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 4), 30, " ")
    NEXT iLine1
   
    PRINT
    INPUT "PRESS <ENTER> TO CONTINUE", in$
   
   
   
   
   
   
   
   
   
   
    CLS
    iTotal = 0
    PRINT "Rounding numbers of type DOUBLE."
    PRINT "Thanks to SMcNeill, bplus, and Pete for your help."
    PRINT
   
    dp% = 2 ' ROUND TO 2 DECIMAL PLACES
   
    ' ROUND DOUBLE TO dp% DECIMAL PLACES
    iColumn = 1
    iLine1 = 1: arrOutput(iLine1, iColumn) = "RoundDouble# TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine1 = 2: arrOutput(iLine1, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR d1# = 0.3 TO 0.4 STEP 0.002
        iLine1 = iLine1 + 1
        d2# = RoundDouble#(d1#, dp%)
        arrOutput(iLine1, iColumn) = RightPadString$(DblToStr$(d1#), 10, " ") + " -> " + RightPadString$(DblToStr$(d2#), 10, " ")
    NEXT d1#
    iMaxLines = iLine1
   
    ' ROUND DOUBLE UP TO 3 DECIMAL PLACES
    iColumn = 2
    iLine2 = 1: arrOutput(iLine2, iColumn) = "RoundUpDouble# TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine2 = 2: arrOutput(iLine2, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR d1# = 0.3 TO 0.4 STEP 0.002
        iLine2 = iLine2 + 1
        d2# = RoundUpDouble#(d1#, dp%)
        arrOutput(iLine2, iColumn) = RightPadString$(DblToStr$(d1#), 10, " ") + " -> " + RightPadString$(DblToStr$(d2#), 10, " ")
       
        IF iLine2 > iMaxLines THEN
            iMaxLines = iLine2
            arrOutput(iLine2, 1) = ""
        END IF
    NEXT d1#
   
    ' ROUND DOUBLE DOWN TO 3 DECIMAL PLACES
    iColumn = 3
    iLine3 = 1: arrOutput(iLine3, iColumn) = "RoundDownDouble# TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine3 = 2: arrOutput(iLine3, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR d1# = 0.3 TO 0.4 STEP 0.002
        iLine3 = iLine3 + 1
        d2# = RoundDownDouble#(d1#, dp%)
        arrOutput(iLine3, iColumn) = RightPadString$(DblToStr$(d1#), 10, " ") + " -> " + RightPadString$(DblToStr$(d2#), 10, " ")
       
        IF iLine3 > iMaxLines THEN
            iMaxLines = iLine3
            arrOutput(iLine3, 1) = ""
        END IF
    NEXT d1#
   
    ' ROUND DOUBLE SCIENTIFIC TO 3 DECIMAL PLACES
    iColumn = 4
    iLine4 = 1: arrOutput(iLine4, iColumn) = "RoundScientificDouble# TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine4 = 2: arrOutput(iLine4, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR d1# = 0.3 TO 0.4 STEP 0.002
        iLine4 = iLine4 + 1
        d2# = RoundScientificDouble#(d1#, dp%)
        arrOutput(iLine4, iColumn) = RightPadString$(DblToStr$(d1#), 10, " ") + " -> " + RightPadString$(DblToStr$(d2#), 10, " ")
       
        IF iLine4 > iMaxLines THEN
            iMaxLines = iLine4
            arrOutput(iLine4, 1) = ""
        END IF
    NEXT d1#
   
    FOR iLine1 = 1 TO iMaxLines
        PRINT "" + _
            RightPadString$(arrOutput(iLine1, 1), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 2), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 3), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 4), 30, " ")
    NEXT iLine1
   
    PRINT
    INPUT "PRESS <ENTER> TO CONTINUE", in$
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    CLS
    iTotal = 0
    PRINT "Rounding numbers of type SINGLE."
    PRINT "Thanks to SMcNeill, bplus, and Pete for your help."
    PRINT
   
    dp% = 2 ' ROUND TO 2 DECIMAL PLACES
   
    ' ROUND SINGLE TO dp% DECIMAL PLACES
    iColumn = 1
    iLine1 = 1: arrOutput(iLine1, iColumn) = "RoundSingle! TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine1 = 2: arrOutput(iLine1, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR s1! = 0.3 TO 0.4 STEP 0.002
        iLine1 = iLine1 + 1
        s2! = RoundSingle!(s1!, dp%)
        arrOutput(iLine1, iColumn) = RightPadString$(SngToStr$(s1!), 10, " ") + " -> " + RightPadString$(SngToStr$(s2!), 10, " ")
    NEXT s1!
    iMaxLines = iLine1
   
    ' ROUND SINGLE UP TO 3 DECIMAL PLACES
    iColumn = 2
    iLine2 = 1: arrOutput(iLine2, iColumn) = "RoundUpSingle! TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine2 = 2: arrOutput(iLine2, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR s1! = 0.3 TO 0.4 STEP 0.002
        iLine2 = iLine2 + 1
        s2! = RoundUpSingle!(s1!, dp%)
        arrOutput(iLine2, iColumn) = RightPadString$(SngToStr$(s1!), 10, " ") + " -> " + RightPadString$(SngToStr$(s2!), 10, " ")
       
        IF iLine2 > iMaxLines THEN
            iMaxLines = iLine2
            arrOutput(iLine2, 1) = ""
        END IF
    NEXT s1!
   
    ' ROUND SINGLE DOWN TO 3 DECIMAL PLACES
    iColumn = 3
    iLine3 = 1: arrOutput(iLine3, iColumn) = "RoundDownSingle! TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine3 = 2: arrOutput(iLine3, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR s1! = 0.3 TO 0.4 STEP 0.002
        iLine3 = iLine3 + 1
        s2! = RoundDownSingle!(s1!, dp%)
        arrOutput(iLine3, iColumn) = RightPadString$(SngToStr$(s1!), 10, " ") + " -> " + RightPadString$(SngToStr$(s2!), 10, " ")
       
        IF iLine3 > iMaxLines THEN
            iMaxLines = iLine3
            arrOutput(iLine3, 1) = ""
        END IF
    NEXT s1!
   
    ' ROUND SINGLE SCIENTIFIC TO 3 DECIMAL PLACES
    iColumn = 4
    iLine4 = 1: arrOutput(iLine4, iColumn) = "RoundScientificSingle! TO " + _TRIM$(STR$(dp%)) + " PLACES"
    iLine4 = 2: arrOutput(iLine4, iColumn) = RightPadString$("Original", 10, " ") + "    " + RightPadString$("Rounded", 10, " ")
    FOR s1! = 0.3 TO 0.4 STEP 0.002
        iLine4 = iLine4 + 1
        s2! = RoundScientificSingle!(s1!, dp%)
        arrOutput(iLine4, iColumn) = RightPadString$(SngToStr$(s1!), 10, " ") + " -> " + RightPadString$(SngToStr$(s2!), 10, " ")
       
        IF iLine4 > iMaxLines THEN
            iMaxLines = iLine4
            arrOutput(iLine4, 1) = ""
        END IF
    NEXT s1!
   
    FOR iLine1 = 1 TO iMaxLines
        PRINT "" + _
            RightPadString$(arrOutput(iLine1, 1), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 2), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 3), 30, " ") + "    " + _
            RightPadString$(arrOutput(iLine1, 4), 30, " ")
    NEXT iLine1
   
    PRINT
    INPUT "PRESS <ENTER> TO CONTINUE", in$   
   
   
   
END SUB ' main

' /////////////////////////////////////////////////////////////////////////////
' https://www.qb64.org/forum/index.php?topic=3605.0
' Quote from: SMcNeill on Today at 03:53:48 PM
'
' Sometimes, you guys make things entirely too  complicated.
' There ya go!  Three functions to either round naturally,
' always round down, or always round up, to whatever number of digits you desire.
' EDIT:  Modified to add another option to round scientific,
' since you had it's description included in your example.

' Receives + returns _FLOAT myVar## (-1.18E-4932 to +1.18E+4932)

' =============================================================================
' ROUNDING FUNCTIONS FOR TYPE _FLOAT

FUNCTION Round## (num##, digits%)
    Round## = INT(num## * 10 ^ digits% + .5) / 10 ^ digits%
END FUNCTION

FUNCTION RoundUp## (num##, digits%)
    RoundUp## = _CEIL(num## * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundDown## (num##, digits%)
    RoundDown## = INT(num## * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundScientific## (num##, digits%)
    RoundScientific## = _ROUND(num## * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

' =============================================================================
' ROUNDING FUNCTIONS FOR TYPE DOUBLE

FUNCTION RoundDouble# (num#, digits%)
    RoundDouble# = INT(num# * 10 ^ digits% + .5) / 10 ^ digits%
END FUNCTION

FUNCTION RoundUpDouble# (num#, digits%)
    RoundUpDouble# = _CEIL(num# * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundDownDouble# (num#, digits%)
    RoundDownDouble# = INT(num# * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundScientificDouble# (num#, digits%)
    RoundScientificDouble# = _ROUND(num# * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

' =============================================================================
' ROUNDING FUNCTIONS FOR TYPE SINGLE

FUNCTION RoundSingle! (num!, digits%)
    RoundSingle! = INT(num! * 10 ^ digits% + .5) / 10 ^ digits%
END FUNCTION

' NOTE: not sure this one works: when digits%=3, it rounds .31 to .32
FUNCTION RoundUpSingle! (num!, digits%)
    RoundUpSingle! = _CEIL(num! * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundDownSingle! (num!, digits%)
    RoundDownSingle! = INT(num! * 10 ^ digits%) / 10 ^ digits%
END FUNCTION

FUNCTION RoundScientificSingle! (num!, digits%)
    RoundScientificSingle! = _ROUND(num! * 10 ^ digits%) / 10 ^ digits%
END FUNCTION


' /////////////////////////////////////////////////////////////////////////////
' Integer to string

FUNCTION cstr$ (myValue)
    'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
    cstr$ = _TRIM$(STR$(myValue))
END FUNCTION ' cstr$

' /////////////////////////////////////////////////////////////////////////////
' Scientific notation - QB64 Wiki
' https://www.qb64.org/wiki/Scientific_notation

' Example: A string function that displays extremely small or large exponential decimal values.

FUNCTION DblToStr$ (n#)
    value$ = UCASE$(LTRIM$(STR$(n#)))
    Xpos% = INSTR(value$, "D") + INSTR(value$, "E") 'only D or E can be present
    IF Xpos% THEN
        expo% = VAL(MID$(value$, Xpos% + 1))
        IF VAL(value$) < 0 THEN
            sign$ = "-"
            valu$ = MID$(value$, 2, Xpos% - 2)
        ELSE
            valu$ = MID$(value$, 1, Xpos% - 1)
        END IF
        dot% = INSTR(valu$, ".")
        L% = LEN(valu$)
        IF expo% > 0 THEN
            add$ = STRING$(expo% - (L% - dot%), "0")
        END IF
        IF expo% < 0 THEN
            min$ = STRING$(ABS(expo%) - (dot% - 1), "0")
            DP$ = "."
        END IF
        FOR n = 1 TO L%
            IF MID$(valu$, n, 1) <> "." THEN
                num$ = num$ + MID$(valu$, n, 1)
            END IF
        NEXT n
    ELSE
        DblToStr$ = value$
        EXIT FUNCTION
    END IF
    DblToStr$ = _TRIM$(sign$ + DP$ + min$ + num$ + add$)
END FUNCTION ' DblToStr$

' /////////////////////////////////////////////////////////////////////////////
' Scientific notation - QB64 Wiki
' https://www.qb64.org/wiki/Scientific_notation

' Example: A string function that displays extremely small or large exponential decimal values.

FUNCTION FloatToStr$ (n##)
    value$ = UCASE$(LTRIM$(STR$(n##)))
    Xpos% = INSTR(value$, "D") + INSTR(value$, "E") 'only D or E can be present
    IF Xpos% THEN
        expo% = VAL(MID$(value$, Xpos% + 1))
        IF VAL(value$) < 0 THEN
            sign$ = "-"
            valu$ = MID$(value$, 2, Xpos% - 2)
        ELSE
            valu$ = MID$(value$, 1, Xpos% - 1)
        END IF
        dot% = INSTR(valu$, ".")
        L% = LEN(valu$)
        IF expo% > 0 THEN
            add$ = STRING$(expo% - (L% - dot%), "0")
        END IF
        IF expo% < 0 THEN
            min$ = STRING$(ABS(expo%) - (dot% - 1), "0")
            DP$ = "."
        END IF
        FOR n = 1 TO L%
            IF MID$(valu$, n, 1) <> "." THEN
                num$ = num$ + MID$(valu$, n, 1)
            END IF
        NEXT n
    ELSE
        FloatToStr$ = value$
        EXIT FUNCTION
    END IF
    FloatToStr$ = _TRIM$(sign$ + DP$ + min$ + num$ + add$)
END FUNCTION ' FloatToStr$

' /////////////////////////////////////////////////////////////////////////////
' Scientific notation - QB64 Wiki
' https://www.qb64.org/wiki/Scientific_notation

' Example: A string function that displays extremely small or large exponential decimal values.

FUNCTION SngToStr$ (n!)
    value$ = UCASE$(LTRIM$(STR$(n!)))
    Xpos% = INSTR(value$, "D") + INSTR(value$, "E") 'only D or E can be present
    IF Xpos% THEN
        expo% = VAL(MID$(value$, Xpos% + 1))
        IF VAL(value$) < 0 THEN
            sign$ = "-"
            valu$ = MID$(value$, 2, Xpos% - 2)
        ELSE
            valu$ = MID$(value$, 1, Xpos% - 1)
        END IF
        dot% = INSTR(valu$, ".")
        L% = LEN(valu$)
        IF expo% > 0 THEN
            add$ = STRING$(expo% - (L% - dot%), "0")
        END IF
        IF expo% < 0 THEN
            min$ = STRING$(ABS(expo%) - (dot% - 1), "0")
            DP$ = "."
        END IF
        FOR n = 1 TO L%
            IF MID$(valu$, n, 1) <> "." THEN
                num$ = num$ + MID$(valu$, n, 1)
            END IF
        NEXT n
    ELSE
        SngToStr$ = value$
        EXIT FUNCTION
    END IF
    SngToStr$ = _TRIM$(sign$ + DP$ + min$ + num$ + add$)
END FUNCTION ' SngToStr$

' /////////////////////////////////////////////////////////////////////////////
' By sMcNeill from https://www.qb64.org/forum/index.php?topic=896.0

FUNCTION IsNum% (text$)
    DIM a$
    DIM b$
    a$ = _TRIM$(text$)
    b$ = _TRIM$(STR$(VAL(text$)))
    IF a$ = b$ THEN
        IsNum% = TRUE
    ELSE
        IsNum% = FALSE
    END IF
END FUNCTION ' IsNum%

' /////////////////////////////////////////////////////////////////////////////

FUNCTION RightPadString$ (myString$, toWidth%, padChar$)
    RightPadString$ = LEFT$(myString$ + STRING$(toWidth%, padChar$), toWidth%)
END FUNCTION ' RightPadString$

' ################################################################################################################################################################
' #REFERENCE

' =============================================================================
' SOME USEFUL STUFF FOR REFERENCE:

' Type Name               Type suffix symbol   Minimum value                  Maximum value                Size in Bytes
' ---------------------   ------------------   ----------------------------   --------------------------   -------------
' _BIT                    `                    -1                             0                            1/8
' _BIT * n                `n                   -128                           127                          n/8
' _UNSIGNED _BIT          ~`                   0                              1                            1/8
' _BYTE                   %%                   -128                           127                          1
' _UNSIGNED _BYTE         ~%%                  0                              255                          1
' INTEGER                 %                    -32,768                        32,767                       2
' _UNSIGNED INTEGER       ~%                   0                              65,535                       2
' LONG                    &                    -2,147,483,648                 2,147,483,647                4
' _UNSIGNED LONG          ~&                   0                              4,294,967,295                4
' _INTEGER64              &&                   -9,223,372,036,854,775,808     9,223,372,036,854,775,807    8
' _UNSIGNED _INTEGER64    ~&&                  0                              18,446,744,073,709,551,615   8
' SINGLE                  ! or none            -2.802597E-45                  +3.402823E+38                4
' DOUBLE                  #                    -4.490656458412465E-324        +1.797693134862310E+308      8
' _FLOAT                  ##                   -1.18E-4932                    +1.18E+4932                  32(10 used)
' _OFFSET                 %&                   -9,223,372,036,854,775,808     9,223,372,036,854,775,807    Use LEN
' _UNSIGNED _OFFSET       ~%&                  0                              18,446,744,073,709,551,615   Use LEN
' _MEM                    none                 combined memory variable type  N/A                          Use LEN

' div: int1% = num1% \ den1%
' mod: rem1% = num1% MOD den1%



Attached Files Thumbnail(s)
   
Print this item

  CVSMBF, MKSMBF$, ETC.
Posted by: arnoldhf - 07-18-2022, 01:20 PM - Forum: Help Me! - Replies (6)

Some questions:

1. As I mentioned in another thread, I wrote extensive QB programs Back in the 80s & 90s when RAM and HD space was at a premium. I used MKI$, MKS$ and MKD$ extensively in my databases.

Converting the programs using QB64 I noticed they, MKS$ etc., were not converting back properly with CVI, CVS, and CVD.

I found and tested CVSMBF and that seemed to work. Does that mean to continue accessing/using my existing databases with QB64 EXEs I must modify the syntax by adding MBF to all of the above, e.g. MDS$ becomes MDSMBF$, etc.?

2. Is there a way to position the window of the running program so it always opens to the same spot on the desktop?

3. When the program exits, I sometimes get the message "press any key to continue" when all I want is the window to close.

Thanks,
 
Arnold

Print this item

  Image resizing utility?
Posted by: madscijr - 07-17-2022, 08:04 PM - Forum: General Discussion - Replies (3)

i'm Has anyone done batch resizing of images in QB64? 
I'm looking to make a simple drag and drop exe that you drag one or more pictures onto (or maybe send it a command line parameter with a path, or a path + a pattern) and it will auto-convert all the images in the folder to some predetermined target resolution at a high quality (or maybe be able to choose the quality vs processing time?) and write the converted images to target folder (or the same folder but with some prefix or change to the file name so you can easily separate them). It would support JPEG / PNG maybe also BMP / GIF, maybe specify the output format + quality? 
Bonus if the created file retains the modified date of the original. 

If anyone has done or seen this kind of thing, I would be interested in any samples or advice...!

UPDATE: I think ImageMagick is what I was thinking of. 
It would still be interesting to do this in QB64, but ImageMagick with a batch file should work for now...

https://www.imagemagick.org/script/download.php#windows

imagemagick - Lightweight command-line image resizer? - Stack Overflow

https://stackoverflow.com/questions/3455...ge-resizer

Print this item

  Variable as a reference or value to a function
Posted by: Kernelpanic - 07-17-2022, 07:15 PM - Forum: General Discussion - Replies (22)

Today I looked at passing variables/arguments to functions - by reference and by value. QBasic Reference P. 2.31.

Apparently, passing by value doesn't work for functions.  Huh But with a procedure (Sub) it worked.

Value at Sub: The value is not changed

Code: (Select All)
'Beispiel fuer Uebergabe an Funktionen als Referenz und als Wert
'Funktioniert offenbar nicht mit Funktionen (?)
'17. Juli 2022

Option _Explicit

Declare Function AlsReferenz(eingabe as Integer) as Integer
Declare Sub AlsWert(eingabe as Integer) as Integer

Dim zahlref, zahlwert As Integer

Cls
Print
Print "Referenzbeispiel - Eingabe wird veraendert"
Input "Eingabe: ", zahlref

Print Using "Eingabe vor Funktionsaufruf: ###"; zahlref
Print Using "Eingabe nach Funktionsaufruf (Eingabe x 3): ###"; AlsReferenz(zahlref)

Print
Print "Wertbeispiel - Eingabe wird nicht veraendert"
Input "Eingabe: ", zahlwert

Print Using "Eingabe vor Funktionsaufruf: ###"; zahlwert

'Aufruf mit Wert in Klammern um sie zu einem Ausdruck zu machen
'QBasic Referenz S. 2.31
Call AlsWert((zahlwert))
Print Using "Eingabe nach Funktionsaufruf (Als Ausdruck): ###"; zahlwert

Print
Print "Uebergabe nicht als Ausdruck - keine Klammern (Eingabe + 3)."

'Jetzt nicht als Ausdruck: Ohne extra Klammern
'um die Variable wird die Eingabe veraendert, da
'sie jetzt wieder als Referenz (Standard) uebergeben wird.
Call AlsWert(zahlwert)
Print Using "Eingabe nach Funktionsaufruf: ###"; zahlwert

Function AlsReferenz (eingabe As Integer)

  AlsReferenz = eingabe * 3
End Function

Sub AlsWert (eingabe As Integer)

  'Hat nur Auswirkung, wenn Argument nicht als Ausdruck
  'uebergeben wird
  eingabe = eingabe + 3
End Sub

And now with a function: Passing by value doesn't work.
Code: (Select All)
'Beispiel fuer Uebergabe an Funktionen als Referenz und als Wert
'17. Juli 2022

Option _Explicit

Declare Function AlsReferenz(eingabe as Integer) as Integer
Declare Function AlsWert(eingabe as Integer) as Integer

Dim zahlref, zahlwert As Integer

Cls
Print
Print "Referenzbeispiel - Eingabe wird veraendert"
Input "Eingabe: ", zahlref

Print Using "Eingabe vor Funktionsaufruf: ###"; zahlref
Print Using "Eingabe nach Funktionsaufruf: ###"; AlsReferenz(zahlref)

Print
Print "Wertbeispiel - Eingabe wird nicht veraendert"
Input "Eingabe: ", zahlwert

Print Using "Eingabe vor Funktionsaufruf: ###"; zahlwert
Print Using "Eingabe nach Funktionsaufruf: ###"; AlsWert((zahlwert))

End 'Hauptprogramm

Function AlsReferenz (eingabe As Integer)

  AlsReferenz = eingabe * 3
End Function

Function AlsWert (eingabe As Integer)

  AlsWert = eingabe + 3
End Function

Print this item

  3D Looking Tic-Tac-Toe
Posted by: SierraKen - 07-17-2022, 03:56 PM - Forum: Programs - Replies (2)

I made this a year ago. Smile It uses the mouse and it randomly picks who goes first. 

Code: (Select All)
'I've wanted to make this game for decades and finally am able to!
'This game was made on August 14, 2019 by SierraKen.
'This is Freeware.
'Jan. 28, 2021 update: Choose at random who goes first.
'Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game,
'and added text colors.
'Jan. 30, 2021 update: Added background blue shades. Also added a score in the Title Bar. Turned the game into 3D - Thanks to B+ for the idea!


Dim a(10), b(10)
_Limit 60
_Title "Tic-Tac-Toe     by SierraKen"
Screen _NewImage(600, 480, 32)
Cls
Print: Print: Print
Locate 10, 34: Print "-"
Locate 10, 40: Print "-"
For tic = 1 To 10
    Locate tic, 30: Print "TIC"
    _Delay .1
    Locate tic, 30: Print "   "
Next tic
Locate 10, 30: Print "TIC"
For tac = 20 To 10 Step -1
    Locate tac, 36: Print "TAC"
    _Delay .1
    Locate tac, 36: Print "   "
Next tac
Locate 10, 36: Print "TAC"
For toe = 1 To 10
    Locate toe, 42: Print "TOE"
    _Delay .1
    Locate toe, 42: Print "   "
Next toe
Locate 10, 42: Print "TOE"
computer = 0
you = 0

Print: Print: Print
Print "                              By  SierraKen"
Print: Print: Print
Print "       Play against the computer in this classic game of Tic-Tac-Toe."
Print "                      Whoever gets 3 in a row wins."
Print
Print "                    Choose a sqace by using your mouse."
Print "                     Computer chooses who goes first."

Color _RGB32(255, 255, 255), _ClearColor
_PrintString (220, 430), "Click Here To Start"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)

Do
    _Limit 60
    mouseWheel = 0
    Do While _MouseInput
        mouseX = _MouseX
        mouseY = _MouseY
        mouseLeftButton = _MouseButton(1)
        mouseRightButton = _MouseButton(2)
        mouseMiddleButton = _MouseButton(3)
        mouseWheel = mouseWheel + _MouseWheel
    Loop
    ag$ = InKey$
    If ag$ = Chr$(27) Then End
    If ag$ = " " Then Cls: GoTo start:
    If mouseLeftButton = -1 And mouseX > 220 And mouseX < 370 And mouseY > 430 And mouseY < 446 Then Cls: GoTo start:
Loop

start:
ag$ = ""
t = 0
turn = 0
comp = 0

For cc = 0 To 480
    cl = cl + .5
    Line (0, cc)-(640, cc), _RGB32(0, 0, cl)
Next cc
cl = 0
Randomize Timer
c1 = Int(Rnd * 155) + 100
c2 = Int(Rnd * 155) + 100
c3 = Int(Rnd * 155) + 100

GoSub grid:

whosfirst:
Randomize Timer
first = Int(Rnd * 2) + 1
If first = 1 Then GoTo computerchoice:

Go:
_Limit 60
a$ = InKey$
If a$ = Chr$(27) Then End
mouseWheel = 0
Do While _MouseInput
    mouseX = _MouseX
    mouseY = _MouseY
    mouseLeftButton = _MouseButton(1)
    mouseRightButton = _MouseButton(2)
    mouseMiddleButton = _MouseButton(3)
    mouseWheel = mouseWheel + _MouseWheel
Loop

If mouseLeftButton = -1 Then
    If mouseX > 88 And mouseX < 218 And mouseY > 93 And mouseY < 182 And b(1) = 0 And a(1) = 0 And t = 0 Then GoSub space1:
    If mouseX > 241 And mouseX < 357 And mouseY > 93 And mouseY < 182 And b(2) = 0 And a(2) = 0 And t = 0 Then GoSub space2:
    If mouseX > 381 And mouseX < 509 And mouseY > 93 And mouseY < 182 And b(3) = 0 And a(3) = 0 And t = 0 Then GoSub space3:
    If mouseX > 88 And mouseX < 218 And mouseY > 205 And mouseY < 302 And b(4) = 0 And a(4) = 0 And t = 0 Then GoSub space4:
    If mouseX > 241 And mouseX < 357 And mouseY > 205 And mouseY < 302 And b(5) = 0 And a(5) = 0 And t = 0 Then GoSub space5:
    If mouseX > 381 And mouseX < 509 And mouseY > 205 And mouseY < 302 And b(6) = 0 And a(6) = 0 And t = 0 Then GoSub space6:
    If mouseX > 88 And mouseX < 218 And mouseY > 326 And mouseY < 410 And b(7) = 0 And a(7) = 0 And t = 0 Then GoSub space7:
    If mouseX > 241 And mouseX < 357 And mouseY > 326 And mouseY < 410 And b(8) = 0 And a(8) = 0 And t = 0 Then GoSub space8:
    If mouseX > 381 And mouseX < 509 And mouseY > 326 And mouseY < 410 And b(9) = 0 And a(9) = 0 And t = 0 Then GoSub space9:
End If

If mouseLeftButton = -1 And ending = 1 Then GoTo start:
If mouseRightButton = -1 And ending = 1 Then End

If t = 1 Then GoSub computer:

GoTo Go:

checkwin:
'Check to see if you won.
If a(1) = 1 And a(2) = 1 And a(3) = 1 Then GoTo won:
If a(4) = 1 And a(5) = 1 And a(6) = 1 Then GoTo won:
If a(7) = 1 And a(8) = 1 And a(9) = 1 Then GoTo won
If a(1) = 1 And a(4) = 1 And a(7) = 1 Then GoTo won:
If a(2) = 1 And a(5) = 1 And a(8) = 1 Then GoTo won:
If a(3) = 1 And a(6) = 1 And a(9) = 1 Then GoTo won:
If a(1) = 1 And a(5) = 1 And a(9) = 1 Then GoTo won:
If a(3) = 1 And a(5) = 1 And a(7) = 1 Then GoTo won:
turn = turn + 1
Sound 100, .25
If turn = 9 Then GoTo catsgame:
GoTo Go:
won:
For snd = 300 To 900 Step 50
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
you = you + 1
you$ = Str$(you)
computer$ = Str$(computer)
_Title "You: " + you$ + "   Computer: " + comp$
t = 0
Color _RGB32(255, 0, 0), _ClearColor
Locate 2, 32: Print "Y O U   W I N ! !"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

computer:

'Check to win.
'Last space gone.
If b(1) = 1 And b(2) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If b(4) = 1 And b(5) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If b(7) = 1 And b(8) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(1) = 1 And b(4) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If b(2) = 1 And b(5) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If b(3) = 1 And b(6) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(1) = 1 And b(5) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(3) = 1 And b(5) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
'First space gone.
If b(2) = 1 And b(3) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(5) = 1 And b(6) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If b(8) = 1 And b(9) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If b(4) = 1 And b(7) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(5) = 1 And b(8) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If b(6) = 1 And b(9) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If b(5) = 1 And b(9) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(7) = 1 And b(5) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
'Middle space gone.
If b(1) = 1 And b(3) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If b(4) = 1 And b(6) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(7) = 1 And b(9) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If b(1) = 1 And b(7) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If b(2) = 1 And b(8) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(3) = 1 And b(9) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If b(1) = 1 And b(9) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(3) = 1 And b(7) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:

'Check to block.
'Last space gone.
If a(1) = 1 And a(2) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If a(4) = 1 And a(5) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If a(7) = 1 And a(8) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(1) = 1 And a(4) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If a(2) = 1 And a(5) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If a(3) = 1 And a(6) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(1) = 1 And a(5) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(3) = 1 And a(5) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
'First space gone.
If a(2) = 1 And a(3) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(5) = 1 And a(6) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If a(8) = 1 And a(9) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If a(4) = 1 And a(7) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(5) = 1 And a(8) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If a(6) = 1 And a(9) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If a(5) = 1 And a(9) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(7) = 1 And a(5) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
'Middle space gone.
If a(1) = 1 And a(3) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If a(4) = 1 And a(6) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(7) = 1 And a(9) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If a(1) = 1 And a(7) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If a(2) = 1 And a(8) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(3) = 1 And a(9) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If a(1) = 1 And a(9) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(3) = 1 And a(7) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:

'Computer decides a random space.
computerchoice:
Randomize Timer
comp = Int(Rnd * 9) + 1
If b(comp) = 1 Then GoTo computerchoice:
If a(comp) = 1 Then GoTo computerchoice:
If comp = 1 Then GoTo compspace1:
If comp = 2 Then GoTo compspace2:
If comp = 3 Then GoTo compspace3:
If comp = 4 Then GoTo compspace4:
If comp = 5 Then GoTo compspace5:
If comp = 6 Then GoTo compspace6:
If comp = 7 Then GoTo compspace7:
If comp = 8 Then GoTo compspace8:
If comp = 9 Then GoTo compspace9:

'Cat's Game
catsgame:
For snd = 400 To 300 Step -25
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
t = 0
Color _RGB32(255, 0, 255), _ClearColor
Locate 2, 29: Print "Cat's Game - No Winners"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

'Check to see if the computer won.
check:
If b(1) = 1 And b(2) = 1 And b(3) = 1 Then GoTo compwon:
If b(4) = 1 And b(5) = 1 And b(6) = 1 Then GoTo compwon:
If b(7) = 1 And b(8) = 1 And b(9) = 1 Then GoTo compwon
If b(1) = 1 And b(4) = 1 And b(7) = 1 Then GoTo compwon:
If b(2) = 1 And b(5) = 1 And b(8) = 1 Then GoTo compwon:
If b(3) = 1 And b(6) = 1 And b(9) = 1 Then GoTo compwon:
If b(1) = 1 And b(5) = 1 And b(9) = 1 Then GoTo compwon:
If b(3) = 1 And b(5) = 1 And b(7) = 1 Then GoTo compwon:
turn = turn + 1
If turn = 9 Then GoTo catsgame:
t = 0
GoTo Go:

compwon:
For snd = 900 To 300 Step -50
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
t = 0
computer = computer + 1
you$ = Str$(you)
comp$ = Str$(computer)
_Title "You: " + you$ + "   Computer: " + comp$
Color _RGB32(128, 255, 255), _ClearColor
Locate 2, 33: Print "Computer  Wins"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

'This part draws the computer's circle.
compspace1:
t = 0
b(1) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace2:
t = 0
b(2) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace3:
t = 0
b(3) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace4:
t = 0
b(4) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace5:
t = 0
b(5) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace6:
t = 0
b(6) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace7:
t = 0
b(7) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
compspace8:
t = 0
b(8) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
compspace9:
t = 0
b(9) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
'This last part draws your X.
space1:
a(1) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (115 + s - xx, 104 - xx)-(195 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (195 + s - xx, 104 - xx)-(115 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space2:
a(2) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 104 - xx)-(335 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 104 - xx)-(255 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space3:
a(3) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 104 - xx)-(475 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 104 - xx)-(395 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space4:
a(4) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (110 + s - xx, 224 - xx)-(190 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (190 + s - xx, 224 - xx)-(110 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space5:
a(5) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 224 - xx)-(335 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 224 - xx)-(255 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space6:
a(6) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 224 - xx)-(475 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 224 - xx)-(395 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space7:
a(7) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (110 + s - xx, 339 - xx)-(190 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (190 + s - xx, 339 - xx)-(110 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space8:
a(8) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 339 - xx)-(335 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 339 - xx)-(255 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space9:
a(9) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 339 - xx)-(475 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 339 - xx)-(395 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:

playagain:
Color _RGB32(255, 0, 0), _ClearColor
_PrintString (220, 55), "Click Here To Play Again"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)

Do
    _Limit 60
    mouseWheel = 0
    Do While _MouseInput
        mouseX = _MouseX
        mouseY = _MouseY
        mouseLeftButton = _MouseButton(1)
        mouseRightButton = _MouseButton(2)
        mouseMiddleButton = _MouseButton(3)
        mouseWheel = mouseWheel + _MouseWheel
    Loop
    ag$ = InKey$
    If ag$ = Chr$(27) Then End
    If ag$ = " " Then Cls: GoTo start:
    If mouseLeftButton = -1 And mouseX > 220 And mouseX < 412 And mouseY > 55 And mouseY < 69 Then Cls: GoTo start:
Loop

grid:
'Draw Grid
'Vertical Lines
For xx = .1 To 15 Step .1
    Line (220 - xx, 100 - xx)-(240 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
    Line (360 - xx, 100 - xx)-(380 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
Next xx
For xx = .1 To 15 Step .1
    'Horizontal Lines
    Line (90 - xx, 185 - xx)-(510 - xx, 205 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
    Line (90 - xx, 305 - xx)-(510 - xx, 325 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
Next xx
Return

Print this item

  "EXE has stopped working ..."
Posted by: arnoldhf - 07-16-2022, 03:50 PM - Forum: Help Me! - Replies (6)

I have started converting 3 of a family of inter-related QB programs to QB64 and have run into the issue of getting the Windows message:

"program" has stopped working

A problem caused the program to stop working correctly.
Windows will close the program  etc, etc.

The message is not immediate but comes up within a minute on all 3. 

Each program can start another using RUN. Sometimes the message appears when another program loads but before the program itself displays its screen.

Within one program I do some data file access and after pulling up records a few times the error appears.

Any suggestions on how to diagnose or eliminate the issue?

Thanks,




[Image: Win-error-2.jpg]

Print this item

  Inform
Posted by: SquirrelMonkey - 07-16-2022, 02:28 AM - Forum: Help Me! - Replies (3)

I tried to install Inform, but when I run the setup file, it tries to download files and the server is unreachable. I downloaded the source files on Github and extracted them to my QB64 folder. Although the inform design program works, nothing else works in QB64. I get error message after error message. Who knows how to solve this? Is there an installer that contains all the files?

Print this item

  Ants!!!
Posted by: James D Jarvis - 07-15-2022, 07:21 PM - Forum: Programs - Replies (12)

Endless ants running about inside a window.

Code: (Select All)
'ants!!!
' a program by James D. Jarvis
'just some ants made with the draw command running about
'press any key to quit
_Title "ANTS!!!"
Screen _NewImage(800, 500, 256)
'_FullScreen
Dim Shared ant$, ax(100), ay(100), am(100), aa(100), ascl(100), aklr(100)
loadCMYK
Color 20, 145
Cls
ant$ = "m+4,-2m+4,+2m-4,+2m-4,-2br8r5m+2,-2m+1,+2m-1,+2m-2,-2bm-3,+0e5g5f5h5u5d10u6dg5e5h5"
For a = 1 To 100
    ax(a) = 100 - Int(Rnd * 100)
    ay(a) = Int(Rnd * 300) + 100
    am(a) = Int(Rnd * 3) + 2
    aa(a) = Int(Rnd * 10) - Int(Rnd * 10)
    ascl(a) = Int(Rnd * 6) + 3
    aklr(a) = 20 - Int(Rnd * 4)
Next a
ro = _Pi / 180
Do
    _Limit 30
    Cls
    For a = 1 To 100
        If Rnd * 6 > 4 Then
            ax(a) = ax(a) + ascl(a) * Sin((aa(a) + 90) * ro)
            ay(a) = ay(a) + ascl(a) * Cos((aa(a) + 90) * ro)

            If ax(a) < -20 Or ax(a) > 850 Then
                ax(a) = 0 - (Int(Rnd * 10) + 5)
                ay(a) = Int(Rnd * 300) + 100
                aa(a) = 0
                ascl(a) = Int(Rnd * 6) + 3
            End If
            If ay(a) < -10 Or ay(a) > 650 Then
                ay(a) = Int(Rnd * 300) + 100
                ax(a) = 0 - (Int(Rnd * 10) + 5)
                aa(a) = 0
                ascl(a) = Int(Rnd * 6) + 3
            End If
        End If
        dant aa(a), aklr(a), ascl(a), ax(a), ay(a)
        dc = Int(Rnd * 20) + 1
        Select Case dc
            Case 1 TO 3
                aa(a) = aa(a) - (Int(Rnd * 6) + 2)
            Case 4 TO 17
            Case 18 TO 20
                aa(a) = aa(a) + (Int(Rnd * 6) + 2)
        End Select
    Next a
    aa$ = InKey$
    _Display
Loop Until aa$ <> ""
System




Sub dant (ang, klr, scl, x, y)

    Draw "s" + Str$(scl)
    PSet (x, y)
    Draw "c" + Str$(klr) + "ta" + Str$(ang) + ant$
End Sub

Sub pal_cmyk (pk, c, m, y, k)
    ' create a 256 color palette entry using CMYK
    ' CMYK process color Cyan, Magenta, Yellow, Black  each  expressed as a percent from 0 to 100
    r = 255 * (100 - c)
    r = (r / 100) * ((100 - k) / 100)
    g = 255 * (100 - m)
    g = (g / 100) * ((100 - k) / 100)
    b = 255 * (100 - y)
    b = (b / 100) * ((100 - k) / 100)
    _PaletteColor pk, _RGB32(r, g, b)
End Sub

Sub loadCMYK
    'builing a cmyk pallete
    klr = 0
    c = 0
    m = 0
    y = 0
    k = 0
    For klr = 0 To 255
        Select Case klr
            Case 1 TO 20
                k = k + 5
                c = 0
                m = 0
                y = 0
            Case 21 TO 40
                k = 0
                c = c + 5
                m = 0
                y = 0
            Case 41 TO 60
                k = 0
                c = 0
                m = m + 5
                y = 0
            Case 61 TO 80
                k = 0
                c = 0
                m = 0
                y = y + 5
            Case 81 TO 100
                k = 0
                c = c + 5
                m = m + 5
                y = 0
            Case 101 TO 120
                k = 0
                c = c + 5
                m = 0
                y = y + 5
            Case 121 TO 140
                k = 0
                c = 0
                m = m + 5
                y = y + 5
            Case 121 TO 140
                k = 20
                c = c + 5
                m = m + 5
                y = 0
            Case 141 TO 160
                k = 20
                c = c + 5
                m = 0
                y = y + 5
            Case 161 TO 180
                k = 20
                c = 0
                m = m + 5
                y = y + 5
            Case 181 TO 200
                k = 40
                c = c + 5
                m = m + 5
                y = 0
            Case 201 TO 220
                k = 40
                c = c + 5
                m = 0
                y = y + 5
            Case 221 TO 240
                k = 40
                c = 0
                m = m + 5
                y = y + 5
            Case 241 TO 255
                k = 10 + (klr - 240) * 4
                c = 0
                m = 100
                y = y + 5
        End Select
        pal_cmyk klr, c, m, y, k
        Color 0, klr
    Next klr
End Sub

Print this item