Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Support

Pages: 1 ... 47 48 [49] 50 51 ... 59
722
Tutorials / ScriptBasic namespace support
« on: October 08, 2009, 10:53:56 AM »
SB supports namespaces using the MODULE / END MODULE statements. All variables, function and subs are localized to the module and the :: syntax must be use to access the modules resources from your main:: program (or other modules) namespace.

Code: [Select]
bar = 1

MODULE foo

PRINT bar,"\n"

bar = 2

FUNCTION modfunc
  LOCAL bar
  bar = 3
  modfunc = bar
END FUNCTION

END MODULE

PRINT bar, "\n"

PRINT foo::bar, "\n"

PRINT foo::modfunc(), "\n"

C:\scriptbasic\test>module
undef
1
2
3

C:\scriptbasic\test>

723
Tutorials / Calling functions and subs implicity
« on: October 08, 2009, 10:51:58 AM »
SB allows you to pass addresses of functions/subs to other functions and call them implicitly within the function with ICALL.

Code: [Select]
FUNCTION addone(x)
  addone = x + 1
END FUNCTION

FUNCTION x10(y)
  x10 = y * 10
END FUNCTION

FUNCTION printit(v,a)
  LOCAL r
  r = ICALL(a,v)
  PRINT r,"\n"
END FUNCTION

f1 = ADDRESS(addone())
f2 = ADDRESS(x10())

printit(1,f1)
printit(1,f2)

C:\scriptbasic\test>icall
2
10

C:\scriptbasic\test>

724
Tutorials / Arrays in ScriptBasic
« on: October 08, 2009, 10:50:15 AM »
Here is an example of using a mix of associative and standard arrays. I see this as a way to build/emulate TYPE/UNION structures in SB.

Code: [Select]
a[1]="John Doe"
a[2]="123 St."
a[3]="Anytown,USA"
a[4,1]="800-THE-SHOP"
a[4,2]="900-OUR-CELL"

cust{"addr_blk"} = a

PRINT cust{"addr_blk"}[1],"\n"
PRINT cust{"addr_blk"}[2],"\n"
PRINT cust{"addr_blk"}[3],"\n"
PRINT cust{"addr_blk"}[4,1],"\n"
PRINT cust{"addr_blk"}[4,2],"\n"

C:\scriptbasic\test>aaa
John Doe
123 St.
Anytown,USA
800-THE-SHOP
900-OUR-CELL
C:\scriptbasic\test>


This example uses three associative arrays to provide a customer address block structure.

Code: [Select]
IMPORT t.bas

p{"shop"} = "800-THE-SHOP"
p{"cell"} = "900-OUR-CELL"

a{"name"} = "John Doe"
a{"addr1"} = "123 St."
a{"addr2"} = "Anytown,USA"
a{"phone"} = p

cust{"addr_blk"} = a

PRINT cust{"addr_blk"}{"name"},"\n"
PRINT cust{"addr_blk"}{"addr1"},"\n"
PRINT cust{"addr_blk"}{"addr2"},"\n"
PRINT cust{"addr_blk"}{"phone"}{"shop"},"\n"
PRINT cust{"addr_blk"}{"phone"}{"cell"},"\n"

xmlstr = t::ArrayToXML(cust)

PRINT xmlstr,"\n"

Code: [Select]
C:\scriptbasic\test>aaaa
John Doe
123 St.
Anytown,USA
800-THE-SHOP
900-OUR-CELL
<?xml version="1.0" encoding="UTF-8"?><V><A l="0" h="1"><S>addr_blk</S><A l="0" h="7"><S>name</S><S>John Doe</S><S>addr1</S><S>123 St.</S><S>addr2</S><S>Anytown,USA</S><S>phone</S><A l="0" h="3"><S>shop</S><S>800-THE-SHOP</S><S>cell</S><S>900-OUR-CELL</S></A></A></A></V>
C:\scriptbasic\test>



Another variation for fun.

Code: [Select]
IMPORT t.bas

n[1] = "name"
n[2] = "addr1"
n[3] = "addr2"
n[4] = "phone"
n[4,1] = "shop"
n[4,2] = "cell"

p{n[4,1]} = "800-THE-SHOP"
p{n[4,2]} = "900-OUR-CELL"

a{n[1]} = "John Doe"
a{n[2]} = "123 St."
a{n[3]} = "Anytown,USA"
a{n[4]} = p

cust{"addr_blk"} = a

PRINT cust{"addr_blk"}{"name"},"\n"
PRINT cust{"addr_blk"}{"addr1"},"\n"
PRINT cust{"addr_blk"}{"addr2"},"\n"
PRINT cust{"addr_blk"}{"phone"}{"shop"},"\n"
PRINT cust{"addr_blk"}{"phone"}{"cell"},"\n"

xmlstr = t::ArrayToXML(cust)

PRINT xmlstr,"\n"


725
Tutorials / Recursive functions and variable scope
« on: October 08, 2009, 10:42:03 AM »
This example shows calling a function recursively and how to define how variables are created in functions by default. (GLOBAL or LOCAL)

Code: [Select]
FUNCTION PlusMinusOne(arg)
  IF limit < 5 THEN
    limit += 1
    arg += 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  ELSE IF arg <> 0 THEN
    arg -= 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  END IF 
  PlusMinusOne = "Done"
END FUNCTION

limit = 0

x = PlusMinusOne(0)

PRINT x,"\n"
PRINTNL
PRINT arg,"\n"
PRINT limit,"\n"

END

C:\scriptbasic\test>recurfunc
1
2
3
4
5
4
3
2
1
0
Done

undef
5

C:\scriptbasic\test>

In this example I define and assign a GLOBAL variable within the function and reference it in main. By default, variables are global unless explicitly declared as LOCAL in SUBs and FUNCTIONs. SB allows switching this functionality so variables are LOCAL by default in functions/subs and you must explicitly declare variables GLOBAL.

Quote from: SB Docs
declare option DefaultLocal

This will mean that all variables inside a function or subroutine following this line will be local unless explicitly declared to be global.

Code: [Select]
FUNCTION PlusMinusOne(arg)
  IF limit < 5 THEN
    limit += 1
    arg += 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  ELSE IF arg <> 0 THEN
    arg -= 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  END IF
  funcvar = "Defined/assigned in the function" 
  PlusMinusOne = "Done"
END FUNCTION

limit = 0

x = PlusMinusOne(0)

PRINT x,"\n"
PRINTNL
PRINT arg,"\n"
PRINT funcvar,"\n"
PRINT limit,"\n"

END

C:\scriptbasic\test>recurfunc
1
2
3
4
5
4
3
2
1
0
Done

undef
Defined/assigned in the function
5

Look what happens when we add DECLARE OPTION DefaultLocal as to the top of the above program. Since limit isn't GLOBAL it's no longer STATIC and breaks the function.

C:\scriptbasic\test>rflocal
Done

undef
undef
0

C:\scriptbasic\test>

Okay, lets fix the program by declaring limit GLOBAL.

Code: [Select]
DECLARE OPTION DefaultLocal

FUNCTION PlusMinusOne(arg)
  GLOBAL limit
  IF limit < 5 THEN
    limit += 1
    arg += 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  ELSE IF arg <> 0 THEN
    arg -= 1
    PRINT arg,"\n"
    PlusMinusOne(arg)
  END IF
  funcvar = "Defined/assigned in the function" 
  PlusMinusOne = "Done"
END FUNCTION

limit = 0

x = PlusMinusOne(0)

PRINT x,"\n"
PRINTNL
PRINT arg,"\n"
PRINT funcvar,"\n"
PRINT limit,"\n"

END

C:\scriptbasic\test>rflocal
1
2
3
4
5
4
3
2
1
0
Done

undef
undef
5

C:\scriptbasic\test>

726
What's New / Re: ScriptBasic News
« on: October 01, 2009, 03:38:26 PM »
I added to the Linux and Windows download threads instructions on installing ScriptBasic.

The forum is here as a means to ask questions, make comments and share code and advice to help others.

It would interesting to hear back what your plans are for ScriptBasic.

  • General purpose Basic command line interpreter
  • ScriptBasic applications server and CGI scripting
  • Embedding ScriptBasic in your application.
  • Other ideas ....



727
General Discussions / Re: DLL available?
« on: September 17, 2009, 05:54:26 PM »
I thought I would update this thread with a link to embedding ScriptBasic.

http://www.allbasic.info/forum/index.php?topic=730.0



728
Installation / Re: Windows 2.1 RC1 install
« on: September 14, 2009, 09:20:35 PM »
We are looking into the issue with SavePNG().

I noticed in Peter's (author) example program he did a raw write of the image string to disk using ScriptBasic standard file IO instead of using gd::SavePNG().  ???

Code: [Select]
fn = 0
open "test.png" for output as fn
binmode fn
print#fn,ImagePng
undef ImagePng
close#fn

I'll update this post when it's fixed.

Thanks for testing ScriptBasic, your feedback is very helpful !


John

729
Installation / Re: Windows 2.1 RC1 install
« on: September 14, 2009, 07:39:39 PM »
My error when building the zip, I included the "Dll_Pack" directory with the files within. Just copy the DLLs in this sub-directory back to \WINDOWS\System32. Sorry. I'll upload a new corrected zip. Here is the gdtest.sb program that comes with the distribution. It worked fine on my Windows XP SP3 box.

Code: [Select]
import gd.bas

brush = gd::Create(10,10)
white = gd::Color(brush,255,255,255)
black = gd::Color(brush,0,240,0)
gd::Line brush,0,0,10,10,black
gd::Line brush,0,10,10,0,black

' gd::SavePng brush,"brush.png"

image = gd::Create(400,300)

white = gd::Color(image,255,255,255)
gd::SetTransparentColor image,white
black = gd::Color(image,0,0,0)
red =  gd::Color(image,255,0,0)
blue =  gd::Color(image,0,0,255)
green = gd::Color(image,0,255,0)

gd::Point image,0,0,black

gd::Rectangle image,200,50,250,100,red
gd::FilledRectangle image,225,75,275,125,green

gd::Rectangle image,324,190,376,290,black
gd::SetTile image,brush
' caused stack overflow on a fine NT? Should be some poor implementation
'gd::FillToBorder image,325,191,black,gd::Tiled

gd::Circle image,350,50,40,blue
gd::FillToBorder image,350,50,blue,green
gd::Fill image,201,51,blue

gd::SetBrush image,brush
gd::Line image,300,200,300,350,gd::Brushed

gd::SetColor image,black

gd::SetFont image,gd::FontTiny
gd::print image,0,0,"THIS PICTURE WAS CREATED FROM ScriptBasic USING THE MODULE GD/PNG"
gd::print image,0,10,"x=",gd::SizeX(image)," y=",gd::SizeY(image)
gd::print image,100,100,"Tiny ",12*3+55

gd::SetFont image,gd::FontSmall
gd::print image,100,120,"Small ",55*63

gd::SetFont image,gd::FontMedium
gd::print image,100,150,"Medium ",24/19

gd::SetFont image,gd::FontLarge
gd::print image,100,190,"Large ",sin(3.1)

gd::SetFont image,gd::FontGiant
gd::print image,100,240,"Giant ",log(1000)


for i=0 to 65 step 5
  gd::Line image,i,20,65-i,75
next i

LineStyle[0] = black
LineStyle[1] = black
LineStyle[2] = undef
LineStyle[3] = undef
LineStyle[4] = red
LineStyle[5] = green
LineStyle[6] = blue
LineStyle[7] = undef
LineStyle[8] = red
LineStyle[9] = red

gd::LineStyle image,LineStyle

gd::Line image,0,90,100,90,undef

for i=0 to 65 step 5
  gd::Line image,i,100,65-i,165,undef
next i


ImagePng = gd::Png(image)

gd::Destroy image

fn = 0
open "test.png" for output as fn
binmode fn
print#fn,ImagePng
undef ImagePng
close#fn

print "done\n"

730
Installation / Re: Windows 2.1 RC1 install
« on: September 14, 2009, 05:37:48 PM »
Quote
the gd commands work fine in the old version, not in the new version

When you say "old version", do you mean the beta 2.1 that installs with a setup program?

731
Installation / Re: Windows 2.1 RC1 install
« on: September 14, 2009, 02:13:16 PM »
Can you post your code so we can have a look at what might be going wrong?

It sounds like your having issues loading the extension module. Use the -d command to debug the extension module loading part of your program before your code even starts to run.

scriba -d yourpgm.bas

732
Download / ScriptBasic 2.1 Linux
« on: September 12, 2009, 11:25:31 PM »
I'm pleased to announce that the first release candidate for ScriptBasic 2.1 Linux is available.

The ODBC interface has changed from unixODBC to iODBC to align with the OS X version.

Download

  • download the compressed tar file to your /usr/src directory
  • In your Linux console, cd to /usr/scr and type bunzip2 SB_2.1_RC1_Linux.tbz
  • this creates a SB_2.1_RC1_Linux.tar file.
  • extract the tar file with tar -xvf SB_2.1_RC1_Linux.tar
  • this creates a scriptbasic directory with everything needed to install ScriptBasic
  • cd into the scriptbasic directory and type ./install.sh


You are now able to use ScriptBasic

733
Download / Updated extension module library DLL pack
« on: September 12, 2009, 10:37:40 PM »
Quote from: AIR
This dll pack contains the required dlls for the updated modules.

Code: [Select]
bgd.dll
comerr32.dll
gssapi32.dll
iconv.dll
k5sprt32.dll
krb5_32.dll
libcurl.dll
libeay32.dll
libexslt.dll
libiconv-2.dll
libintl-8.dll
libmysql.dll
libpq.dll
libxml2.dll
libxmlsec-mscrypto.dll
libxmlsec-openssl.dll
libxmlsec.dll
libxslt.dll
ssleay32.dll
zlib1.dll

Download - (unzip into the \WINDOWS\System32 directory) Updated Zip


734
Download / ScriptBasic 2.1 RC3 OS X (Intel)
« on: September 12, 2009, 10:31:54 PM »
ScriptBasic 2.1 RC3 OS X has been released.

Download

Note: I replaced the zip I created with the .tbz that Armando sent me. I will update this post with install instructions shortly. (use Linux install as a guide till then)

735
Installation / Re: Windows 2.1 RC1 install
« on: September 12, 2009, 09:41:52 PM »
FYI

ScriptBasic 2.1 RC2 Windows was released.

Download

Pages: 1 ... 47 48 [49] 50 51 ... 59