Author Topic: BBC BASIC for Windows  (Read 21177 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #15 on: January 15, 2014, 10:04:49 AM »
Richard,

I have been looking at the existing libraries that come with BBCW to get a feel for how things work. I didn't realize that .BBC files need to be edited in the BBCW IDE as they have a binary format to them. I'm still unsure about some of the cryptic syntax outside the functions. The only red flag I've come across so far is the 65 KB string limitation. Is there a solution for dealing with large strings in BBCW?

rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #16 on: January 15, 2014, 11:37:25 AM »
I didn't realize that .BBC files need to be edited in the BBCW IDE as they have a binary format to them.

You can export them as regular text files: File... Save As... BASIC Text File (*.BAS).  But to be acceptable to the INSTALL statement you'll have to reverse the process in order to convert them back to the tokenised .BBC format.

Quote
The only red flag I've come across so far is the 65 KB string limitation. Is there a solution for dealing with large strings in BBCW?

That's a limitation of version 5 of BBC BASIC.  Version 6 has no practical string-length limitation (32-bit length field); I'm working towards releasing that but no date has been set.  The version 6 run-time engine forms part of my (freeware) product 'LB Booster', so is currently available to the end-user but without the convenience of an IDE.

Edit: I should add that, of course, when v6 is released it will be available free-of-charge to everybody who has purchased v5; I never charge for upgrades or bug fixes.

Richard.
« Last Edit: January 15, 2014, 11:47:13 AM by Richard Russell »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #17 on: January 15, 2014, 11:46:00 AM »
That's great news Richard. The 64 KB current string limitation isn't a show stopper, only a future concern which you have elevated with your announcement of 6. I think that IUP will be much easier to work with for BBCW programmers looking for a forms based GUI. I think you have ease of use in graphics nailed.


Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #18 on: January 15, 2014, 12:43:27 PM »
Richard,

Is there an ODBC library for BBCW? My goal with this project is to use BBCW under Wine which includes using the Windows IUP library for the GUI. Wine's ODBC interface is native which means I can connect to my 64 bit MySQL and SQLite3 databases from BBCW.


rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #19 on: January 15, 2014, 01:28:41 PM »
Is there an ODBC library for BBCW?

I know that there have been user-generated libraries for MySQL and SQLite, but personally I have no experience of them and it's not an area in which I have any expertise.  If it's of interest the SQLite3 library is linked from this Wiki page:

http://bb4w.wikispaces.com/Libraries

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #20 on: January 15, 2014, 01:42:08 PM »
Here is something you posted on your forum that didn't seem to go anywhere.

Code: [Select]
      SYS "LoadLibrary", "ODBC32.DLL" TO odbc%
      SYS "GetProcAddress", odbc%, "SQLAllocEnv" TO `SQLAllocEnv`
      SYS "GetProcAddress", odbc%, "SQLAllocConnect" TO `SQLAllocConnect`
      SYS "GetProcAddress", odbc%, "SQLDriverConnect" TO `SQLDriverConnect`
     
      SYS `SQLAllocEnv`, ^glEnv%
      IF glEnv% = 0 ERROR 100, "Unable to initialize ODBC API drivers"
     
      SYS `SQLAllocConnect`, glEnv%, ^glDbc%
      IF glDbc% = 0 ERROR 100, "Unable to allocate memory for connection handle"
     
      Connect$ = "DSN=" + DSN$ + ";UID=" + LoginID$ + ";PWD=" + Password$ + \
      \          ";APP=" + AppCode$ + ";DATABASE=" + Database$
     
      Result$ = STRING$(1024, CHR$0)
     
      SYS `SQLDriverConnect`, glDbc%, @hwnd%, Connect$, LEN(Connect$), \
      \                       Result$, LEN(Result$), ^size%, 0 TO res%
      IF res% ERROR 100, "Unable to connect to database"
     
      Result$ = LEFT$(Result$, size%)

I downloaded the user contributed SQLite library and plan on giving it a try. The ODBC interface is an attractive option for Wine.

rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #21 on: January 15, 2014, 01:59:16 PM »
Here is something you posted on your forum that didn't seem to go anywhere.

I don't recognise it; maybe somebody asked me to translate some C code into BBC BASIC.  For some reason, although I've taken an interest in all sorts of areas during my forty-odd years as a (part-time) programmer, database usage hasn't been one of them.  :)

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #22 on: January 15, 2014, 02:20:58 PM »
It was your reply to an Oracle connection request on the DB board.

I think BBC4W could have a very useful 2nd life under Wine. With XP's funeral in April, Wine and Linux isn't a bad alternative.



rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #23 on: January 15, 2014, 03:43:02 PM »
I think BBC4W could have a very useful 2nd life under Wine.

I'm happy for people to use it under Wine, at their own risk (!), but I don't offer specific support for that platform.  I've got a dual-boot Windows 7 / Ubuntu machine so I can run up Wine if I really need to, but I very rarely do.

When I last tried to update Ubuntu it crashed part way through, and I now have an installation which is neither one version nor another, and it won't update at all!  I'm told the solution is to re-install from a Ubuntu CD, but I'm terrified that if I do that it will bugger up the dual boot - that happened once and I couldn't boot into Windows at all.

And don't get me started on the stupidity of Grub reprogramming the video output of my PC so that my bog-standard Dell monitor won't lock, and simply displays 'No signal'.  Whoever thought that a boot loader should display graphics - even in a standard video mode - needs their head examined.  ::)

So I'm afraid my experiences with Linux have not been good, and I'm not a fan.

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #24 on: January 15, 2014, 04:00:35 PM »
Damn. That's a sad story.  :o

I'll be your Linux GOTO guy if you need a reference of someone using BBC4W and Wine.

FYI - The SQLite3 library worked fine.



Code: [Select]
INSTALL @lib$+"SQLite"
PROCsqlite_initialise

ON ERROR PROCsqlite_close:PROCsqlite_finalise:PRINT:REPORT:END
ON CLOSE PROCsqlite_close:PROCsqlite_finalise:QUIT

file$=@dir$+"Phonenos.db"
PROCsqlite_open(file$)

PROCsqlite_exec( \
\ "CREATE TABLE IF NOT EXISTS phonenos (" + \
\     "name varchar(100), " + \
\     "phone varchar(100), " + \
\     "email varchar(100))")

PRINT "PhoneNos SQLite Example"
REPEAT
  PRINT '"  1. Create a record"
  PRINT "  2. Update a record"
  PRINT "  3. List all records"
  PRINT "  4. Search for a record"
  PRINT "  5. Delete a record"
  PRINT "  6. Exit"
  INPUT '"Enter 1-6 : "choice
  PRINT
  IF choice = 1 PROCcreate
  IF choice = 2 PROCupdate
  IF choice = 3 PROClist
  IF choice = 4 PROCsearch
  IF choice = 5 PROCdelete
UNTIL choice = 6
PROCsqlite_close
PROCsqlite_finalise
QUIT

DEF PROCcreate
LOCAL name$, phone$, email$
PRINT "Enter details"
INPUT LINE "    Name          : " name$
INPUT LINE "    Phone number  : " phone$
INPUT LINE "    Email address : " email$
name$ = FNsqlite_encodestring(name$)
phone$ = FNsqlite_encodestring(phone$)
email$ = FNsqlite_encodestring(email$)
PROCsqlite_exec( \
\ "INSERT INTO phonenos (name, phone, email) " + \
\ "VALUES ("+name$+","+phone$+","+email$+")")
ENDPROC

DEF PROCdelete
LOCAL id$
INPUT "Enter the RowID of the record to delete : "id$
id$ = FNsqlite_encodestring(id$)
PROCsqlite_exec( \
\ "DELETE FROM Phonenos " + \
\ "WHERE rowid="+id$+"")
ENDPROC

DEF PROClist
LOCAL row, numResults
PROCsqlite_get_array(\
\ "SELECT rowid, name, phone, email " + \
\     "FROM Phonenos ORDER BY name", A%())
numResults = DIM(A%(),1)
IF numResults = 0 THEN
  PRINT "No people found"
ELSE
  FOR row = 1 TO numResults
    PRINT "Person"
    PRINT "    RowID         : " $$A%(row, 0)
    PRINT "    Name          : " $$A%(row, 1)
    PRINT "    Phone number  : " $$A%(row, 2)
    PRINT "    Email address : " $$A%(row, 3)
    PRINT
  NEXT row
ENDIF
PROCsqlite_free_array(A%())
ENDPROC

DEF PROCsearch
LOCAL name$, row, numResults
INPUT"Enter the name to look for : "name$
name$ = FNsqlite_encodestring("%"+name$+"%")
PROCsqlite_get_array( \
\ "SELECT rowid, name, phone, email FROM Phonenos " +\
\ "WHERE name LIKE " + name$, A%())
numResults = DIM(A%(),1)
IF numResults = 0 THEN
  PRINT "Not found"
ELSE
  PRINT "    RowID         : " $$A%(1, 0)
  PRINT "    Name          : " $$A%(1, 1)
  PRINT "    Phone number  : " $$A%(1, 2)
  PRINT "    Email address : " $$A%(1, 3)
ENDIF
PROCsqlite_free_array(A%())
ENDPROC

DEF PROCupdate
LOCAL id$,  numResults, name$, phone$, email$, change$
INPUT"Enter the RowID of the record to update "id$
person$ = FNsqlite_encodestring(id$)
PROCsqlite_get_array( \
\ "SELECT rowid, name, phone, email FROM Phonenos "+ \
\ "WHERE rowid=" + id$, A%())
numResults = DIM(A%(),1)
PRINT
IF numResults = 0 THEN
  PRINT "Not found"
ELSE
  PRINT "Person"
  PRINT "    RowID         : " $$A%(1, 0)
  PRINT "    Name          : " $$A%(1, 1)
  PRINT "    Phone number  : " $$A%(1, 2)
  PRINT "    Email address : " $$A%(1, 3)
  INPUT "Change? (Y/N)" change$
  IF INSTR("Yy", change$) THEN
    PRINT '"Enter new details"
    INPUT LINE "    Name          : " name$
    INPUT LINE "    Phone number  : " phone$
    INPUT LINE "    Email address : " email$
    name$ = FNsqlite_encodestring(name$)
    phone$ = FNsqlite_encodestring(phone$)
    email$ = FNsqlite_encodestring(email$)
    id$ = FNsqlite_encodestring($$A%(1, 0))
    PROCsqlite_exec( \
    \ "UPDATE Phonenos SET " + \
    \     "name=" + name$ + \
    \     ", phone=" + phone$ + \
    \     ", email="+ email$ + \
    \ " WHERE rowid="+id$+"")
  ENDIF
  PROCsqlite_free_array(A%())
ENDIF
ENDPROC
« Last Edit: January 15, 2014, 08:02:20 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
BBC BASIC for Windows - IUP
« Reply #25 on: January 15, 2014, 09:33:11 PM »
I was able to get a IUP Hello World example to work.



Code: [Select]
REM BBC4W IUP Hello World

SYS "GetModuleHandle", "kernel32.dll" TO _hdll%
SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _%
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS _%, _hdll%, "IupOpen" TO IupOpen%
SYS _%, _hdll%, "IupDialog" TO IupDialog%
SYS _%, _hdll%, "IupLabel" TO IupLabel%
SYS _%, _hdll%, "IupAppend" TO IupAppend%
SYS _%, _hdll%, "IupShow" TO IupShow%
SYS _%, _hdll%, "IupMainLoop" TO IupMainLoop%
SYS _%, _hdll%, "IupClose" TO IupClose%

SYS IupOpen%, 0, 0
SYS IupDialog% TO dlg%
SYS IupLabel%, "BBC BASIC for Windows" TO lbl%
SYS IupAppend%, dlg%, lbl%
SYS IupShow%
SYS IupMainLoop%
SYS IupClose%
END

rtrussell

  • Guest
Re: BBC BASIC for Windows - IUP
« Reply #26 on: January 16, 2014, 03:51:34 AM »
Code: [Select]
SYS "GetModuleHandle", "kernel32.dll" TO _hdll%
SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _%
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS _%, _hdll%, "IupOpen" TO IupOpen%
SYS _%, _hdll%, "IupDialog" TO IupDialog%

Unless speed is critical (which it won't be here), feel free to simply use a string abbreviation of "GetProcAddress" rather than going to all the trouble of finding its numeric address:

Code: [Select]
gpa$ = "GetProcAddress"
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS gpa$, _hdll%, "IupOpen" TO IupOpen%
SYS gpa$, _hdll%, "IupDialog" TO IupDialog%

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows - IUP
« Reply #27 on: January 16, 2014, 09:20:58 AM »
Thanks for the tip. I have a few questions before I take this further.

  • IUP creates its own dialog/window as does BBC4W. How do I hide the BBC4W created window?
  • I used the method in the SQLite3 example to load the iup.dll in  the Hello World example. Is there an easier way so I don't have to wrap all the SYS calls into BBC4W functions/procedures so I can nest them in my application code?
  • I would like to create an IUP BBC4W library. What advice would you give creating it?

rtrussell

  • Guest
Re: BBC BASIC for Windows - IUP
« Reply #28 on: January 16, 2014, 10:35:23 AM »
IUP creates its own dialog/window as does BBC4W. How do I hide the BBC4W created window?

This should do it:

Code: [Select]
      SYS "ShowWindow", @hwnd%, 0
If you end up compiling your program you can do it by selecting 'Hidden' as the 'Initial window state' in the Compile dialog.

Quote
I used the method in the SQLite3 example to load the iup.dll in  the Hello World example. Is there an easier way so I don't have to wrap all the SYS calls into BBC4W functions/procedures so I can nest them in my application code?

The only way of 'nesting' DLL function calls is to wrap them in FNs.  See the discussion on the BBC BASIC forum.   

Quote
I would like to create an IUP BBC4W library. What advice would you give creating it?

In what respect?  There's an article on writing libraries at the Wiki:

http://bb4w.wikispaces.com/Guide+to+writing+libraries

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 2422
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows - IUP
« Reply #29 on: January 16, 2014, 11:14:59 AM »
Thanks!

I think I have what I need to build an IUP library for BBC4W. The BBC4W window may come in handy for printing debug messages while in development.