Liberty BASIC Community Forum
« Sample Program .bas code »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 10:49am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3 4  ...  7 Notify Send Topic Print
 locked  Author  Topic: Sample Program .bas code  (Read 1442 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program colorex.bas
« Reply #15 on: Aug 6th, 2017, 03:24am »

colorex.bas

Show the new color features, I don't like color controls :)

Code:
    'BackgroundColor$ and ForegroundColor$ are set once only
    'TextboxColor$,ComboboxColor$,ListboxColor$,TexteditorColor$
    'can be set per control. All must be set before the window
    'is opened, so cannot be chanaged mid program

    nomainwin

    BackgroundColor$ = "darkgreen"
    ForegroundColor$ = "green"

    WindowWidth = 376
    WindowHeight = 175
    TextboxColor$ = "darkgreen"
    textbox #dial.textbox4, 102, 16, 248, 25
    TextboxColor$ = "yellow"
    textbox #dial.textbox5, 102, 46, 248, 25
    TextboxColor$ = "buttonface"
    textbox #dial.textbox6, 102, 76, 248, 25
    button #dial.button7, "Accept", [button7Click], UL, 294, 111, 58, 25
    statictext #dial.statictext1, "Name:", 22, 26, 40, 20
    statictext #dial.statictext2, "Phone #:", 22, 56, 64, 20
    statictext #dial.statictext3, "Email:", 22, 86, 48, 20

    open "Colors example" for dialog as #dial
    #dial "trapclose [quit]"

    #dial.textbox4 "Press Tab to move to next Textbox"
    #dial.textbox5 "You need to choose colors carefully"
    #dial.textbox6 "Best adopt users default colors"
    wait


[button7Click]   'Perform action for the button named 'button7'
    'Insert your own code here
    wait

[quit]
    close #dial
    end


 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program combo.bas
« Reply #16 on: Aug 6th, 2017, 08:28am »

combo.bas

Thought original was a bit confusing, added an item to the list.


Code:
    'demonstrate the use of a combobox control
    nomainwin
    dim array$(10)
    array$(0) = "the quick brown"
    array$(1) = "fox jumped over"
    array$(2) = "the lazy dog"
    nextplace=3

    WindowWidth = 400
    WindowHeight = 240
    combobox #main.combo, array$(), [action], 30, 60, 210, 140
    textbox #main.addto, 30, 20, 210, 25
    textbox #main.selec, 30, 145,210,25
    button #main.addtolist, "Add to List", [addToList], UL, 250, 20, 120, 25

    open "Combobox example" for window as #main
    #main "trapclose [quit]"

    'note that a combobox only fires if the selection is changed
    'un rem this line and try to select the lazy dog
    '#main.combo "select ";"the lazy dog"
    wait


[action]
    'get the selected item and show it
    #main.combo "contents? text$"
    #main.selec text$
    wait

[addToList]
    'update array$() and reload combobox
    #main.addto "!contents? text$"
    array$(nextplace)=text$
    nextplace=nextplace+1
    #main.combo "reload"
    wait

[quit]
    close #main
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program combobox.bas
« Reply #17 on: Aug 6th, 2017, 08:40am »

combobox.bas

Simple tidy nomainwin [quit] and a few changes to the instructions.

Code:
    'COMBOBOX.BAS  - a short combobox demo
    nomainwin

    WindowWidth = 360
    WindowHeight = 270

    array$(0) = "This"
    array$(1) = "is"
    array$(2) = "a"
    array$(3) = "test"
    array$(4) = "of"
    array$(5) = "the"
    array$(6) = "emergency"
    array$(7) = "broadcast"
    array$(8) = "system"

    combobox #main.testcb, array$(), [selected], 26, 16, 136, 200
    textbox #main.index, 182, 16, 136, 25
    button #main, "Index Selection", [accept], UL, 182, 51, 136, 25
    statictext #main.instruct, "Hey", 182, 86, 136, 200

    open "Combobox" for dialog as #main
    #main "trapclose [quit]"

    'print instructions to the statictext control
    instruct$ = "Select an item in the combobox on the left and watch the " + _
        "index number change, change the number and hit Index " + _
        "Selection to go the other way."
    #main.instruct instruct$
    wait

[selected]
    #main.testcb "selectionindex? xVar"
    #main.index xVar
    wait

[accept]
    #main.index "!contents? yVar"
    #main.testcb "selectindex "; yVar
    wait

[quit]
    close #main
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program console.bas
« Reply #18 on: Aug 7th, 2017, 03:50am »

console.bas

This simply did not work so has quite a few changes, normal timer call for the cursor and a good few bugs knocked out.

Code:
    'A graphicbox set to look like a console interface
    'for scrolling, single line input or output
    'paper teletype style
    nomainwin
    dim screen$(25)
    for x = 0 to 24
        screen$(x) = space$(80)
    next x
    curX = 1
    curY = 0
    curYCache = 12
    lineCache$ = screen$(0)
    WindowWidth=344
    WindowHeight=412
    graphicbox #main.graphics, 1, 1, DisplayWidth, DisplayHeight
    open "Console" for window as #main
    #main "trapclose [quit]"
    #main.graphics "font courier_new 10"
    #main.graphics "autoresize"
    #main.graphics "down ; color white ; backcolor black"
    #main.graphics "fill black"
    #main.graphics "when characterInput [getChar]"

    timer 500, [cursor]
    wait

[draw]
    if curVisible then  curVisible = switchCursor(curVisible, curX, curY)
    screen$(curY) = lineCache$
    scrollUp=0
    gosub [displayAll]
    wait

[cursor]
    curVisible = switchCursor(curVisible, curX, curY)
    #main.graphics "setfocus"
    wait


[displayAll]
    #main.graphics "cls"
    for x = 0 to 23
        if scrollUp then screen$(x) = screen$(x + 1)
        #main.graphics "place 2 "; 15 * x + 12
        #main.graphics "|"; screen$(x)
    next x
    #main.graphics "flush"
    return


[getChar]
    char$ = Inkey$
    if len(char$) <> 1 then wait

  [oneChar]
    if curVisible = 1 then curVisible = switchCursor(curVisible, curX, curY)
    if char$ = chr$(_VK_RETURN) then [cr]
    if char$ = chr$(_VK_BACK) and curX > 1 then [backspace]
    if char$ > chr$(31) then [visibleChar] else wait

[visibleChar]
    lineCache$ = left$(lineCache$, curX - 1) + char$ + mid$(lineCache$, curX + 1)
    #main.graphics "place "; (curX - 1) * 8 + 2; " "; curYCache
    #main.graphics "|"; char$
    curX = curX + 1
    if curX >=41 then goto [cr] 'wrap at 40
    wait

[backspace]
    curX = curX - 1
    lineCache$ = left$(lineCache$, curX - 1) + " " +  mid$(lineCache$, curX + 1)
    #main.graphics "place "; (curX - 1) * 8 + 2; " "; curYCache
    #main.graphics "|"; " "
    wait

[cr]
    curX = 1
    if curY < 23 then
        screen$(curY) = lineCache$
        curY = curY + 1
        curYCache = curY * 15 + 12
    else
        screen$(curY) = lineCache$
        scrollUp=1
    end if
    lineCache$=""
    gosub [displayAll]
    wait



[quit]
    close #main
    end


function switchCursor(switchCursor, drawX, drawY)

    #main.graphics "place "; (drawX - 1)*8+2; " "; drawY*15+12
    #main.graphics "down ; north ; size 2 ; rule xor ; color black ; go 14 ; color white ; rule over"
    switchCursor = abs(switchCursor - 1)   'trade 0 for 1, or 1 for 0

end function


 

« Last Edit: Aug 7th, 2017, 03:52am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program ContactMgr424.bas
« Reply #19 on: Aug 7th, 2017, 03:59am »

ContactMgr424.bas

Given its size and copyright I don't plan to change this at all. It also runs well.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program coolfractals.bas
« Reply #20 on: Aug 7th, 2017, 04:29am »

coolfractals.bas

Just a tidy, removed button and made screen properly full screen.


Code:
    'This program draws fractal based shapes in multiple colors
    nomainwin
    dim col$(12)
    WindowWidth = DisplayWidth
    WindowHeight = DisplayHeight
    UpperLeftX = int((DisplayWidth-WindowWidth)/2)
    UpperLeftY = int((DisplayHeight-WindowHeight)/2)
    midx=int(WindowWidth/2)
    midy=int(WindowHeight/2)
    open "Fractals - press Space to restart" for graphics_fs_nsb as #1
    #1 "trapclose [quit]"
    #1 "when characterInput [keyPressed]"
    #1 "setfocus"

    [clear]
    #1 "down ; fill black"

    [draw]
    'set up some random colors
    for c=0 to 12
    col$(c)="color "+str$(int(rnd(0)*256))+" "+str$(int(rnd(0)*256))+" "+str$(int(rnd(0)*256))
    next c

    'set up some random starting positions
    a=rnd(0)
    b=0.9998
    c=2-2*a
    dots=12000
    x=j=0
    y=rnd(0)*12+0.1

    'calculate and draw the points
    for i=0 to dots
        scan 'break out if required
        z=x
        x=b*y+j
        j=a*x+c*(x^2)/(1+x^2)
        y=j-z
        xp=(x*20)+midx
        yp=(y*20)+midy
        #1 col$(i/1000)
        #1 "set ";xp;" ";yp
        'stop the drawing filling memory
        #1 "discard"
    next i
    'do it all again
    goto [draw]

[keyPressed]
    if Inkey$ = " " then
        goto [clear]
    else
        goto [draw]
    end if


[quit]
    close #1
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program dice.bas
« Reply #21 on: Aug 7th, 2017, 04:36am »

dice.bas

Should be named statusbar.bas

First faultless program!

Code:
'LB has no statusbar control, but it can be cloned
'with a statictext
'this demo places time and date on right side, but
'any info can be placed on the fake statusbar

nomainwin

'set window size
WindowWidth=400:WindowHeight=400

'create statictext to function as statusbar
'command must be placed before open window command
'allow 20 pixels for titlebar, 20 pixels for menu
'when locating statictext
statictext #1.s, "",0,338,400,25

'add a texteditor, can add any other controls
texteditor #1.te, 1,1,392,335

'open window
Open "Statusbar Clone" for window_nf as #1

'issue font command
#1 "font ms_sans_serif 8"

'trap close event
#1 "trapclose [quit]"

'set up timer
timer 1000, [doTime]

'wait for user events
wait

'close window, END
[quit] timer 0:close #1:end

'update clock on statusbar
[doTime]
    t$=time$()
    d$=date$()
    #1.s space$(83)+t$+space$(10)+d$
    wait

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program dir.bas
« Reply #22 on: Aug 7th, 2017, 04:39am »

dir.bas


Second faultless program!


Code:
    'demonstrate the files command

    'first predimension the array we need
    dim dir$(10,3)

    'now get the file info and stick it into the array
    files "c:\", "*.*", dir$()

    'items in dir$(0,?) now have information we can use
    qtyFiles = val(dir$(0, 0))
    print qtyFiles; " files"
    qtySubDirs = val(dir$(0, 1))
    print qtySubDirs; " subdirectories"
    print dir$(0, 2); dir$(0, 3)

    if qtyFiles = 0 then [printSubdirectoryInfo]

    'reformat the file information
    for x = 1 to qtyFiles
        dir$(x, 1) = right$("        " + dir$(x, 1), 9)
    next x

    'now sort the files in the array
    sort dir$(), 1, qtyFiles, 1

    'now print out the file information
    for x =  qtyFiles to 1 step -1
        print left$(dir$(x, 0) + "            ", 13) ; "  "; dir$(x, 1); "  "; dir$(x, 2)
    next x

[printSubdirectoryInfo]

    print
    print "Subdirectories:"
    if qtySubDirs > 0 then
        for x = qtyFiles + 1  to qtyFiles + qtySubDirs
            print dir$(x, 1)
        next x
    else
        print "No subdirectories."
    end if

    end


 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program Draw_R.bas
« Reply #23 on: Aug 7th, 2017, 04:56am »

Draw_R.bas

Should now be named Draw.bas, Draw1.bas and DrawX.bas should be deleted.


A few changes, move to wait rather than goto input loop, changed size of starting window to show full graphicbox.


Code:
    nomainwin

    lineThickness$ = "1"

    menu #1, &Object, "&Line", [setForLine], &Ellipse, [setForEllipse], &Box, [setForBox]
    menu #1, &Color, &Red, [colorRed], &Yellow, [colorYellow], &Green, [colorGreen], &Blue, [colorBlue]
    menu #1, &Drawing, "&Line Thickness", [lineThickness], "&Print", [printIt]

    bmpbutton #1, "bmp\redbttn.bmp", [colorRed], UL, 5, 5
    bmpbutton #1, "bmp\yllwbttn.bmp", [colorYellow], UL, 40, 5
    bmpbutton #1, "bmp\grnbttn.bmp", [colorGreen], UL, 75, 5
    bmpbutton #1, "bmp\bluebttn.bmp", [colorBlue], UL, 110, 5
    bmpbutton #1, "bmp\panbttn.bmp", [setForPan], UR, 110, 5
    bmpbutton #1, "bmp\circbttn.bmp", [setForEllipse], UR, 40, 5
    bmpbutton #1, "bmp\sqrbttn.bmp", [setForBox], UR, 5, 5
    bmpbutton #1, "bmp\linebttn.bmp", [setForLine], UR, 75, 5

    graphicbox #1.graph, 5, 37, 300, 200

    WindowWidth = 325
    WindowHeight = 300

    open "Liberty Draw" for window as #1
    #1 "trapclose [quit]"
    #1.graph "down"
    #1.graph "fill white ; flush"
    #1.graph "when rightButtonUp [cls]"
    #1.graph "color black"
    #1.graph "backcolor red"
    #1 "resizehandler [resized]"
    goto [setForLine]



[startDraw]
    startX = MouseX
    startY = MouseY
    #1.graph "place "; startX; " "; startY
    wait

[firstLine]
    #1.graph "when leftButtonMove [trackLine]"
    #1.graph "line "; startX; " "; startY; " "; MouseX; " "; MouseY
    oMouseY = MouseY
    oMouseX = MouseX
    wait

[firstFrame]
    #1.graph "when leftButtonMove [trackBox]"
    #1.graph "box "; MouseX; " "; MouseY
    oMouseY = MouseY
    oMouseX = MouseX
    wait

[trackBox]
    #1.graph "color white"
    #1.graph "box "; oMouseX; " "; oMouseY
    #1.graph "color black"
    #1.graph "place "; startX; " "; startY
    #1.graph "box "; MouseX; " "; MouseY
    oMouseY = MouseY
    oMouseX = MouseX
    wait

[trackLine]
    #1.graph "color white"
    #1.graph "line "; startX; " "; startY; " "; oMouseX; " "; oMouseY
    #1.graph "color black"
    #1.graph "place "; startX; " "; startY
    #1.graph "line "; startX; " "; startY; " "; MouseX; " "; MouseY
    oMouseY = MouseY
    oMouseX = MouseX
    wait

[finishLine]
    #1.graph "when leftButtonMove [firstLine]"
    #1.graph "discard"
    #1.graph "line "; startX; " "; startY; " "; MouseX; " "; MouseY
    #1.graph "flush ; redraw"
    wait

[finishBox]
    #1.graph "when leftButtonMove [firstFrame]"
    #1.graph "discard"
    #1.graph "boxfilled "; MouseX; " "; MouseY
    #1.graph "flush ; redraw"
    wait

[finishEllipse]
    #1.graph "when leftButtonMove [firstFrame]"
    #1.graph "discard"
    #1.graph "place "; int((startX+MouseX)/2); " ";  int((startY+MouseY)/2)
    #1.graph "ellipsefilled "; abs(MouseX-startX); " "; abs(MouseY-startY)
    #1.graph "flush ; redraw"
    wait

[cls]
    #1.graph "cls"
    #1.graph "fill white ; flush"
    wait


[setForLine]

    #1.graph "when leftButtonDown [startDraw]"
    #1.graph "when leftButtonMove [firstLine]"
    #1.graph "when leftButtonUp [finishLine]"
    wait

[setForBox]

    #1.graph "when leftButtonDown [startDraw]"
    #1.graph "when leftButtonMove [firstFrame]"
    #1.graph "when leftButtonUp [finishBox]"
    wait

[setForEllipse]

    #1.graph "when leftButtonDown [startDraw]"
    #1.graph "when leftButtonMove [firstFrame]"
    #1.graph "when leftButtonUp [finishEllipse]"
    wait

[setForPan]

    filedialog "Get *.bmp file", "bmp\*.bmp", panFile$
    if panFile$ = "" then [inputLoop]

    loadbmp "panWithMe", panFile$
    #1.graph "when leftButtonDown [drawBmp]"
    #1.graph "when leftButtonMove [drawBmp]"
    #1.graph "when leftButtonUp [flushBmp]"
    wait

[drawBmp]

    #1.graph "drawbmp panWithMe "; MouseX; " "; MouseY
    wait

[flushBmp]

    #1.graph "flush"
    wait

[colorRed]

    #1.graph "backcolor red"
    wait


[colorYellow]

    #1.graph "backcolor yellow"
    wait


[colorGreen]

    #1.graph "backcolor green"
    wait


[colorBlue]

    #1.graph "backcolor blue"
    wait


[lineThickness]

    prompt "Line Thickness"; lineThickness$
    #1.graph "size "; lineThickness$
    wait


[printIt]

    #1.graph "print"
    wait


[resized]
    #1.graph "locate 4 36 "; WindowWidth - 8; " "; WindowHeight - 8 - 32
    #1 "refresh"
    wait

[quit]
    close #1
    end

 
« Last Edit: Aug 7th, 2017, 05:00am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program drives.bas
« Reply #24 on: Aug 7th, 2017, 05:03am »

drives.bas

tiny change, nomainwin


Code:
    'a simple example illustrating the use of the Drives$ variable
    nomainwin

    dim letters$(25)
    index = 0
    while word$(Drives$, index + 1) <> ""
        letters$(index) = word$(Drives$, index + 1)
        index = index + 1
    wend
    statictext #choose, "Double-click to pick a drive:", 10, 10, 200, 20
    listbox #choose.list, letters$(, [selectionMade], 10, 35, 100, 150
    open "Scan drive" for dialog as #choose
    #choose "trapclose [quit]"
    wait

[selectionMade]
    #choose.list "selection? whatsIt$"
    notice "You selected drive "; whatsIt$

[quit]
    close #choose
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program elapsed.bas
« Reply #25 on: Aug 7th, 2017, 06:32am »

elapsed.bas

no change.


Code:
    'this short program demonstrates how to measure elapsed
    'time in milliseconds

    start = time$("ms")
    while a < 250000
        a = a + 1
    wend
    print "Elapsed time: "; time$("ms")-start
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program ellipses.bas
« Reply #26 on: Aug 7th, 2017, 06:37am »

ellipses.bas


Only a tidy,


Code:
    ' draw some ellipses
    nomainwin

    colorPool$ = "red green blue"
    open "Ellipses" for graphics_nsb as #1
    #1 "trapclose [quit]"
    #1 "down"
    #1 "place 130 130"
    for x = 30 to 230 step 10
        gosub [nextColor]
        #1 "ellipse "; x ; " "; 260 - x
    next x
    #1 "flush"
    wait

[nextColor]
   'pick the next in the cycle of colors
    while color$ = ""
        colorIndex = colorIndex + 1
        color$ = word$(colorPool$, colorIndex)
        if color$ = "" then colorIndex = 0
    wend
    #1 "color "; color$
    color$ = ""
    return

[quit]
    close #1
    end
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program enumwindows.bas
« Reply #27 on: Aug 7th, 2017, 08:47am »

enumwindows.bas

A few changes, got rid of the code opening user32.dll, changed the counting routine to a simple array() count inside the function. Made it clearer that it only list first 10 found.

Not sure if this needs further work, I think it just used to list open windows, now it seems to list all open processes. Might need more work by an expert.

Code:
    'This program lists all open processes on your PC
    'here we list the first 10
    nomainwin

    dim count(1)
    WindowWidth=300
    WindowHeight=400
    texteditor #win.te, 10, 10, 260, 250
    open "Enumerate Windows" for window as #win
    #win "trapclose [quit]"

    'set the variable named address to be the memory address for
    'enumWndProc() using types handle and ulong, and set
    'the return type of enumWndProc() to be a boolean
    callback address, enumWndProc(handle, ulong), boolean

    'call EnumWindows, which in turn calls back into the
    'BASIC function at address.
    calldll #user32, "EnumWindows", _
        address as ulong, _
        0 as long, _
        result as boolean
    wait

[quit]
    close #win
    end

function enumWndProc(hwnd, lparam)
    labelBuffer$ = space$(261)
    calldll #user32, "GetWindowTextA", _
        hwnd as ulong, _
        labelBuffer$ as ptr, _
        260 as long, _
        result as long
    if left$(labelBuffer$, 1) <> chr$(0) then
        #win.te labelBuffer$
        count(0)=count(0)+1
    end if
    if count(0) = 10 then
        enumWndProc = 0   'returning 0 causes EnumWindows to return
      else
        enumWndProc = 1
    end if
end function
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program erhandlr.bas
« Reply #28 on: Aug 7th, 2017, 09:00am »

erhandlr.bas

Should be called ComErr.bas

Few changes so it runs without error even if no serial port exists

Code:
    'enable the com error handler
    oncomerror [handleIt]

    'open com2
    open "COM2:9600,n,8,1" for random as #1
    portopenflag=1

    'try to open com2 again, triggering handler
    open "COM2:9600,n,8,1" for random as #2
    portopenflag=2

    'we never get this far because of the error
    print "we never get this far because of the error"
    input r$

[handleIt]

    'disable the com error handler
    oncomerror

    'print out the error and port
    print "Error: "; ComError$
    print "Port number: "; ComPortNumber

    if portopenflag=2 then close #2
    if portopenflag=1 then close #1
    print "Program ends gracefully"
    end
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: Sample Program exit for.bas
« Reply #29 on: Aug 7th, 2017, 09:04am »

exit for.bas

Should be called exitloop.bas, exit for.bas exit while.bas not required.


Code:
  'The correct way to leave a loop early
  'Needed for leaving For Next, While and Do loops.


  
    for x = 1 to 100
        if x = 50 then exit for
        print x
    next x

    for x = 1 to 5
        print "run number "; x
        a = 0
        while a < 50
            a = a + 1
            print a
            if rnd(1) > 0.7 then exit while
        wend
    next x

    wait
 
« Last Edit: Aug 7th, 2017, 09:10am by Rod » User IP Logged

Pages: 1 2 3 4  ...  7 Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls