Liberty BASIC Community Forum
« Search Results »

Welcome Guest. Please Login or Register.
Apr 24th, 2017, 4:05pm


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

--Liberty BASIC Resources--
Liberty BASIC Community WikiSpace
Frequently Asked Questions
Bay Six Software Forum
Liberty BASIC Home Page
Carl Gundel's Blog
Official Liberty BASIC Support
Liberty BASIC Programmer's Encyclopedia
Liberty BASIC on Rosetta Code

Search Results

Total results: 10


 1   Tips and Information / Re: iif( bool , true , false )  on: Today at 3:27pm
Started by bluatigro | Post by tsh73
Quote:
This is a nice idea, and might be made even more readable if you craft versions of the function with carefully chosen names, for example?
...
barColor(i)=computeColor(barValue<X,RED,GREEN)


Nope.
The point is IIF is standard way of doing such things
And as such is as readable as Code:
If condition THEN 
sequence.

Here, using "carefully chosen names" would hide that, obscuring the code.

If I would really want to hide that stuff completely I would write along this
Code:
barColor(i)=computeColor(barValue, X) 


 
  Reply Quote Notify of replies

 2   Database Applications / Re: SQLite  on: Today at 1:18pm
Started by tbohon | Post by Rod
Without the db file it is hard to debug. But in general if you get a protection violation then the struct or api call has the wrong type defined for one of the variables.

Runnable code will get better help, you may need to zip a complete example for folks to try.
 
  Reply Quote Notify of replies

 3   Database Applications / Re: SQLite  on: Today at 11:22am
Started by tbohon | Post by Rod
You are still defining handles as type long instead of type ulong. Even in structs you have to use ulong. You also need to recognise that liberty always expects a return value from any api call. I don't use SQLite often enough to offer more than general advice.
 
  Reply Quote Notify of replies

 4   Database Applications / Examples for LB v4.5.1?  on: Today at 08:01am
Started by CarlGundel | Post by CarlGundel
I'm looking for example programs that I can include with Liberty BASIC v4.5.1 that show how to use SQLite and ODBC with Liberty BASIC.

Any submissions gratefully considered.

Thanks,

-Carl
 
  Reply Quote Notify of replies

 5   Tips and Information / Re: iif( bool , true , false )  on: Today at 07:55am
Started by bluatigro | Post by CarlGundel
on Apr 18th, 2017, 7:34pm, Dan Teel wrote:
https://en.wikipedia.org/wiki/Conditional_(computer_programming)#C-like_languages

It has a much richer history I'm sure, but if you dont need to have an if-then statement after using the Iif function to assign a value to a variable, this would reduce the code, and, in certain situations, increase readability.

For example, I want the a bar in a bar graph to turn red when it goes below X.

Code:
for i = 1 to 10
    barColor(i)=Iif(barValue<X,RED,GREEN)
next i
 


Code:
for i = 1 to 10
    if barValue(i)<X then
      barColor(i)=RED
   else
      barColor(i)=GREEN
   end if
next i
 

This is a nice idea, and might be made even more readable if you craft versions of the function with carefully chosen names, for example?

Code:
for i = 1 to 10
    barColor(i)=computeColor(barValue<X,RED,GREEN)
next i
 


-Carl
 
  Reply Quote Notify of replies

 6   Announcements, Software and Websites / Re: Liberty BASIC v4.5.1 beta 1  on: Today at 07:33am
Started by CarlGundel | Post by CarlGundel
on Yesterday at 09:30am, alincon2001 wrote:
Carl said:
"I will release test versions without heavy testing on my end because this kind of thing slows me down.
Small changes. Frequent releases.
I will rely on community help with weeding out bugs more than I used to."

I'm not sure I like this new plan. It's too much like what some software companies have always done.

I think I would rather Carl spend more time debugging the software and charge more for it.

r.m.

I need to do it differently. I have not been successful doing the same old way.

-Carl
 
  Reply Quote Notify of replies

 7   Database Applications / Re: SQLite  on: Today at 05:27am
Started by tbohon | Post by hessu
Thank you for your answer and advice.

I changed every (DBhnd as long) to DBhnd as ulong

Same resultat

I have 61 field$ in my table.
Maybe that's why it doesn't work





Code:
Struct RS,_
    BOF     as long,_       ' is True when CurrPos = 1
    EOF     as long,_       ' is True when CurrPos = Rows
    Handle  as long,_       ' address of recordset data returned by sqlite3.dll (dont't use)
    Rows    as long,_       ' number of rows in recordset
    Cols    as long,_       ' number of columns in recordset
    CurrPos as long,_       ' current row in recordset
    StrAdr  as long         ' address of data item (pointer to a string)

Open "SQ3_4_LB.dll" for DLL As #sq3

DB$ = "Livs.db"
overwrite = 0
calldll #sq3, "SQ3_4_LB_OpenDB",DB$ as ptr, DBhnd as ulong

' determine count of records
SQL$ = "Select Count(*) As CountOfRecords From Livsmedel"
calldll #sq3, "SQ3_4_LB_GetRecordset", SQL$ as ptr,DBhnd as ulong,RS as struct, ret as long
if ret then
    calldll #sq3, "SQ3_4_LB_GetRecordsetValueByName","CountOfRecords" as ptr, ret as long
        print Winstring(RS.StrAdr.struct);" Records in Livsmedel"
    else
        calldll #sq3, "SQ3_4_LB_GetLastMessage", result as long
        print Winstring(result)
    end if

SQL$ = "Select * From Livsmedel Where Livsmedelgrupp = 2"
calldll #sq3, "SQ3_4_LB_GetRecordset", SQL$ as ptr,DBhnd as ulong,RS as struct, ret as long

    While RS.EOF.struct = 0
    x=x+1
        calldll #sq3, "SQ3_4_LB_GetRecordsetValueOfRow","," as ptr, result as long
        If result then
            print Winstring(RS.StrAdr.struct)
        Else
            calldll #sq3, "SQ3_4_LB_GetLastMessage", result as long
            print Winstring(result)
        End If
        calldll #sq3, "SQ3_4_LB_RecordsetMoveNext", result as void
    Wend
    print x
    calldll #sq3, "SQ3_4_LB_ReleaseRecordset", result as void
' note: above there was not always a GetRecordset followed by a ReleaseRecordset
' because GetRecordset releases the previously used memory by itself.
' but in an event driven program it would be better to explicitly call ReleaseRecordset

calldll #sq3, "SQ3_4_LB_CloseDB", DBhnd as ulong,result as long

close #sq3
end


 


I got this again.

Error log timestamp 4/24/2017 11:12:0

The registers were:
EIP = 0x014b5664
ESP = 0x0012fb9c
EBP = 0x0012fbb8
EAX = 0x00000000
EBX = 0xffffecfb
ECX = 0x10051b24
EDX = 0x014fc9c2
EDI = 0x10051a5c
ESI = 0x1027b27c
CS = 0x0000001b
DS = 0x00000023
ES = 0x00000023
SS = 0x00000023
End Registers



Error log timestamp 4/24/2017 11:12:00
Message 1001:
a non-continuable protection violation has occurred. Check ERROR.LOG file.

And I have no idea what's wrong

 
  Reply Quote Notify of replies

 8   Liberty BASIC Code / Re: Genetic Programming  on: Today at 04:25am
Started by bluatigro | Post by bluatigro
update :
now whit iif() function

not all is in english but it works
[ proof of concept ]

i dont know for sure if gprun$() catches all error's
please report them if you see them

code at :
http://libertybasic.nl/viewtopic.php?f=4&t=649&p=2566#p2566

 
  Reply Quote Notify of replies

 9   Liberty BASIC Code / Re: gaus rnd function  on: Yesterday at 5:09pm
Started by bluatigro | Post by tenochtitlanuk
Not sure what you are asking.
Random decay of radioactive isotopes means the probability of decay in any fixed period of time is always constant.

Not sure therefore where the Gaussian randoms come in ( your function is the same as I used in the k-means postings)

Here's an old LB program of mine that lets a grid of 100 by 100 atoms decay, and draw the curve, which of course approximates an exponential. Might be of some interest/relevance?

Code:
nomainwin

dim lattice$( 100, 100)

global unchanged
unchanged =10000
R         =0.1 +0.9 *rnd( 1)  '   1 for fastest, down to say 0.1 for 10x slower

WindowWidth  =1000
WindowHeight = 680

open "Decaying isotope" for graphics_nsb as #wg

#wg "trapclose q"

#wg "fill 40 40 90 ; backcolor 40 40 90 ; color 10 200 255"
#wg "size 4 ; down"
#wg "font Ubuntu_Mono 16 bold"

for i =0 to 99
    for j =0 to 99
        lattice$( i, j) ="+"
        #wg "set "; 10 +6 *i; " "; 30 +6 *j
    next j
next i

i =0

do
    i =i +1
    if rnd( 1) <R then call decay
    #wg "up ; goto 740 200 ; down ; color white"
    #wg "\"; right$( "     " +str$( unchanged), 6); "   "; i
    '#wg "size 1  ; set "; 650 +int( i /300); " "; 400 -int( unchanged /30)
    #wg "size 1  ; set "; 650 +int( i /300); " "; 600 -int( 500 *unchanged /10000)
    #wg "down ; size 4"
    scan
loop until i >=100000 or unchanged =0

wait

sub decay
    i =int( 100 *rnd( 1))
    j =int( 100 *rnd( 1))

    if lattice$( i, j) ="+" then
        lattice$( i, j) =" "
        #wg "color 255 40 120"
        #wg "set "; 10 +6 *i; " "; 30 +6 *j
        unchanged =unchanged -1
    else
        '#wg "color 10 200 255"
    end if

    '#wg "set "; 10 +6 *i; " "; 30 +6 *j
end sub

sub q h$
    close #wg
    end
end sub
 

 
  Reply Quote Notify of replies

 10   Announcements, Software and Websites / Re: Liberty BASIC v4.5.1 beta 1  on: Yesterday at 2:41pm
Started by CarlGundel | Post by Rod
Stefan, nice to see you back, sounds like a good idea.
 
  Reply Quote Notify of replies


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