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 ... 49 50 [51] 52 53 ... 59
751
GD / Re: GD
« on: November 09, 2008, 02:34:29 PM »
I noticed the font issue when running the ScriptBasic GD demo on my WinXP box. I'll give this a try under Linux and see if this is a Windows extension module issue only.

Thanks for the post and research !


John

752
Round Table / ScriptBasic developers needed
« on: October 11, 2008, 09:38:28 PM »
The ScriptBasic project needs ANSI C programmers to help maintain the Basic. The author is busy with other projects and has moved on for the most part. If you would like to help keep the ScriptBasic open source project moving forward, your contributions would be appreciated by the many ScriptBasic users that count on the language for their daily tasks.The Basic is solid but the extension modules need to be refreshed with current libraries and new binary distributions for the primary platforms generated.

Please respond here or send me a e-mail to support at this URL if you can help out.

Thanks !

John Spikowski
ScriptBasic Project Manger

753
Tutorials / Runtime error handling
« on: September 24, 2008, 05:53:11 PM »
Q. How does ScriptBasic handle runtime errors?

A. ScriptBasic uses exception handling like most Basic languages. See specifics bellow.

Code: [Select]
ON ERROR GOTO ErrorTrap

ERROR 1

PRINT "This won't print\n"

ErrorTrap:

PRINT "This is the error message.\n"

END

To turn off error handling use the the following directive.

Code: [Select]
ON ERROR GOTO NULL
The RESUME directive will retry the same statement that cause the error.

The RESUME NEXT will execute the next statement after the one that caused the error.

The RESUME label will resume execution of the next statement following the provided label.

ERROR 0  clears the last error value but doesn't turn off error handling or change the resume point.

The ON ERROR RESUME label will resume execution following the provided label.

The ON ERROR RESUME NEXT will try to execute the statement after the one that caused the error.

Error Codes
Code: [Select]
0 = No error
1 = Memory error
2 = Function can not return a whole array
3 = Division by zero or other calculation error
4 = Argument to operator is undefined
5 = The command or sub was called the wrong way
6 = There are not enough arguments for the module function.
7 = The argument passed to a module function is not the correct type.
8 = The argument passed to a module function is out of acceptable range.
9 = The module experiences difficulties reading the file
10 = The module experiences difficulties writing the file.
11 = The module experiences difficulties handling the file.
12 = There is a circular reference in memory.
13 = The module can not be unloaded, because it was not loaded.
14 = Some modules were active and could not be unloaded.
15 = The module can not be unloaded, because it is currently active.
16 = The requested module can not be loaded.
17 = The requested function does not exist in the module.
18 = The module did not initialize correctly
19 = The module was developed for a different version of ScriptBasic.
20 = File number is out of range, it should be between 1 and 512
21 = The file number is already used.
22 = The file can not be opened.
23 = The file is not opened.
24 = The lock type is invalid.
25 = The print command failed. The file may be locked by another process.
26 = Directory can not be created.
27 = The directory or file could not be deleted.
28 = Command is not implemented and no currently loaded extension module defined behaviour for it
29 = The character can not be a joker or wild card character.
30 = The code tried to execute a resume while not being in error correction code.
31 = The directory name in open directory is invalid.
32 = Invalid option for directory open.
33 = The directory can not be opened.
34 = The record length is invalid in the open statement (undefined, zero or negative)
35 = The current directory can not be retrieved for some reason.
36 = The directory name in chdir can not be undef.
37 = Cannot change the current working directory to the desired directory.
38 = The command RETURN can not be executed, because there is no where to return.
39 = The argument for the function address is invalid.
40 = The attribute value or symbol is invalid in the set file command.
41 = The user does not exist.
42 = The chown command is not supported on Win95 and Win98
43 = Can not change owner.
44 = The file name is invalid.
45 = Setting the create time of the file has failed.
46 = Setting the modify time of the file has failed.
47 = Setting the access time of the file has failed
48 = The specified time format is invalid
49 = The time is not valid, cannot be earlier than January 1, 1970. 00:00
50 = Extension specific error: (ext. error code)
51 = The operation can be done on files only and not on sockets.
52 = The embedding application tried to start the code at an invalid location
53 = Mandatory argument is missing
54 = Subprocess did not finish within time limits
55 = The module can not be unloaded
56 = The preprocessor said to abort program compilation or execution.

User Guide - Error Handling

754
Tutorials / Working with files
« on: September 24, 2008, 05:51:58 PM »
Q. What types of files does ScriptBasic support?

A. ScriptBasic supports text and binary files native and a verity of database options with extension modules.

A file is just a byte stream to ScriptBasic. You can open a file for reading, writing, or both of these operations without closing and reopening the file.

Code: [Select]
OPEN file_name FOR access_mode AS [#]file_number [LEN=record_length]

Access Modes:

INPUT
OUTPUT
APPEND
RANDOM
BINARY

You can switch modes for a file while it's open with the following directives.

Code: [Select]
BINMODE [#]file_number

TEXTMODE [#]file_number

To change ScriptBasic's standard IN/OUT modes, these directives can be used.

Code: [Select]
BINMODE INPUT
BINMODE OUTPUT

TEXTMODE INPUT
TEXTMODE OUTPUT

The FREEFILE function returns an available file number.

Code: [Select]
file_number = FREEFILE

The ISDEFINED(file_numeber) or ON ERROR GOTO can be used to determine if a file handle was return by FREEFILE().

When a file is opened in RANDOM or BINARY modes, the SEEK directive may be used to position the file pointer for the next read or write operation.

Code: [Select]
SEEK [#]file_number, position
To return to the beginning of the file, use the SEEK or REWIND directives.

Code: [Select]
SEEK [#]file_number, 0
REWIND [#]file_number

If the file is opened using the optional LEN=record_length option, then the LOF function returns the total number of records for the file otherwise the LOF function returns the total number of bytes for the file.

Code: [Select]
number_of_records = LOF(file_number)
The POS function returns the current record position if the LEN=record_lenght is used otherwise the current byte position is returned.

Code: [Select]
record_position = POS(file_number)
To write to a file, the PRINT directive is used.

Code: [Select]
PRINT #file_number,expression_list
If the file is opened in text mode and a new line character is required at the end of the line, the following syntax can be used.

Code: [Select]
PRINT #file_numebr,"some test to write\n"
PRINTNL #file_numebr,"some test to write"

To read lines from a opened text file, the LINE INPUT directive is used.

Code: [Select]
LINE INPUT #file_number,variable
To read from a binary file use the INPUT function. The function will return the number of bytes specified or the remaining data.

Code: [Select]
variable = INPUT(number_of_bytes,file_number)
The current working directory can be determined with the CURDIR system variable and changed with the CHDIR directive.

Code: [Select]
PRINT CURDIR

CHDIR "directory_path"

ScriptBasic supports advisory locking of files.

Code: [Select]
LOCK #file_number,option
Options:

WRITE
READ
RELEASE

A range of bytes within a file may be locked as well.

Code: [Select]
LOCK RANGE #file_number FROM start_pos TO end_pos FOR option
Options are the same as the LOCK directive.

An open binary file my be truncated with the TRUNCATE directive.

Code: [Select]
TRUNCATE #file_number,new_file_size
A file or empty directory can be removed with the DELETE directive.

Code: [Select]
DELETE "file_name"
DELETE "directory_name"

To remove a directory and everything below it, the DELTREE directive can be used. Be careful with this command as ALL files/directories below the given directory name will be permanently deleted. (no recycle bin use)

To create a directory or a new path made up of multiple sub-directories use the MKDIR directive.

Code: [Select]
MKDIR "dir_name"
MKDIR "dir_name/sub_dir_name"

Returns true if the named file exists.

Code: [Select]
status = FILEEXISTS(file_name)

The FILELEN function returns the length in bytes of an unopened file given it's filename as the argument.

Code: [Select]
file_size = FILELEN("file_name")

File parameters can be set using the SET FILE directive.

Code: [Select]
SET FILE file_name parameter=value
Parameters:

Owner
CreateTime
ModifyTime
AccessTime


Get the time the file was modified last time.

Code: [Select]
fct = FILECREATETIME(file_name)

Get the time the file was accessed last time.

Code: [Select]
fat = FILEACCESSTIME(file_name)

Get the time the file was modified last time.

Code: [Select]
fmt = FILEMODIFYTIME(file_name)

If the destination file already exists then the command overwrites the file. If the destination file is to be created in a directory that does not exist yet then the directory is created automatically.

Code: [Select]
FILECOPY file_name_from, file_name_to

755
Tutorials / Retriving a web page
« on: September 24, 2008, 05:50:34 PM »
Q. How would I go about getting the html from a web page on the net?

A. You have two options. You can use the built in socket support in ScriptBasic or use the cURL extension module.

ScriptBasic Native
Code: [Select]
ON ERROR GOTO SiteError
OPEN "allbasic.info:80" FOR SOCKET AS #1
PRINT #1,"GET http://localhost/ HTTP/1.0\n\n"

WHILE NOT EOF(1)
  LINE INPUT #1, page_line
  PRINT page_line
WEND
CLOSE #1
END

SiteError:
PRINT "The web server allbasic.info on port 80 is not available\n"

cURL Extension Module

Example on All Basic


756
Tutorials / Reading a directory
« on: September 24, 2008, 05:49:31 PM »
Q. How do I get a list of file names in a given directory.

A. Check out the ScriptBasic wiki for directory open & close and the nextfile command to get to get a list of file names. (optionally based on a pattern)

Directory Read Information

Code: [Select]
OPEN DIRECTORY dir_name PATTERN pattern_value OPTION option_value AS dir_number

file_name = NEXTFILE

x = EOD(dir_number)

RESET DIRECTORY #dir_number

CLOSE DIRECTORY #dir_number

OPTIONS
  • SbCollectDirectories Collect the directory names as well as file names into the file list.
  • SbCollectDots Collect the virtual . and .. directory names into the list.
  • SbCollectRecursively Collect the files from the directory and from all the directories below.
  • SbCollectFullPath The list will contain the full path to the file names. This means that the file names returned by the function NextFile will contain the directory path specified in the open directory statement and therefore can be used as argument to file handling commands and functions.
  • SbCollectFiles Collect the files. This is the default behavior.
  • SbSortBySize The files will be sorted by file size.
  • SbSortByCreateTime The files will be sorted by creation time.
  • SbSortByAccessTime The files will be sorted by access time.
  • SbSortByModifyTime The files will be sorted by modify time.
  • SbSortByName The files will be sorted by name. The name used for sorting will be the bare file name without any path even if the option bit SbCollectPath is specified.
  • SbSortByPath The files will be sorted by name including the path. The path is the relative to the directory, which is currently opened. This sorting option is different from the value sbSortByName only when the value sbCollectRecursively is also used.
  • SbSortAscending Sort the file names in ascending order. This is the default behavior.
  • SbSortDescending Sort the file names in descending order.
  • SbSortByNone Do not sort. Specify this value if you do not need sorting. In this case directory opening can be much faster especially for large directories.

Note: Use AND if more then one option is needed with the OPEN DIRECTORY directive.

Here is a bit of code I snagged from my MLS utility that removes old photos of properties that have gone off market. My directory structure is made up of 1000 sub-directories numbered from 000 to 999. The last three digits of the MLS # determines which sub-directory the photo(s) resides in. The following code would read all 1000 directories selecting only .jpg files and print the file names.

Code: [Select]
fn = FREEFILE

FOR d = 0 TO 999
  DName = FORMAT("%~000~",d)
  OPEN DIRECTORY DName PATTERN "*.jpg" OPTION sbCollectFiles AS #fn
  RESET DIRECTORY #fn
  GOSUB READ_DIR
  CLOSE DIRECTORY #fn
NEXT d

END

READ_DIR:

FName = NEXTFILE(fn)
IF FName = undef THEN RETURN
PRINT FName & "\n"
GOTO READ_DIR

757
General Discussions / Re: Having trouble getting execute command to work
« on: September 20, 2008, 05:34:10 PM »
Timm,

You can use FREEFILE() to return the next available file handle.

fhandle = FREEFILE()

You can just close the file when your done and reuse the file handle again if you want.

I think your making this harder then it needs to be.

Check out the ScriptBasic wiki for directory open & close and the nextfile command to get the next file. (optionally based on a pattern)

http://www.scriptbasic.org/wiki/index.php?title=ScriptBasic:UsersGuide_12.14

This way you don't need the execute() at all.

Here is a bit of code I snagged from my MLS utility that removes old photos of properties that have gone off market. My directory structure is made up of 1000 sub-directories numbered from 000 to 999. The last three digits of the MLS # determines which sub-directory the photo(s) resides in. The following code would read all 1000 directories selecting only .jpg files and print the file names.

OPTIONS
  • SbCollectDirectories Collect the directory names as well as file names into the file list.
  • SbCollectDots Collect the virtual . and .. directory names into the list.
  • SbCollectRecursively Collect the files from the directory and from all the directories below.
  • SbCollectFullPath The list will contain the full path to the file names. This means that the file names returned by the function NextFile will contain the directory path specified in the open directory statement and therefore can be used as argument to file handling commands and functions.
  • SbCollectFiles Collect the files. This is the default behavior.
  • SbSortBySize The files will be sorted by file size.
  • SbSortByCreateTime The files will be sorted by creation time.
  • SbSortByAccessTime The files will be sorted by access time.
  • SbSortByModifyTime The files will be sorted by modify time.
  • SbSortByName The files will be sorted by name. The name used for sorting will be the bare file name without any path even if the option bit SbCollectPath is specified.
  • SbSortByPath The files will be sorted by name including the path. The path is the relative to the directory, which is currently opened. This sorting option is different from the value sbSortByName only when the value sbCollectRecursively is also used.
  • SbSortAscending Sort the file names in ascending order. This is the default behavior.
  • SbSortDescending Sort the file names in descending order.
  • SbSortByNone Do not sort. Specify this value if you do not need sorting. In this case directory opening can be much faster especially for large directories.

Note: Use AND if more then one option is needed with the OPEN DIRECTORY directive.

Hope this helps.

Code: [Select]
fn = FREEFILE

FOR D = 0 TO 999
  DName = FORMAT("%~000~",D)
  OPEN DIRECTORY DName PATTERN "*.jpg" OPTION sbCollectFiles AS #fn
  RESET DIRECTORY #fn
  GOSUB READ_DIR
  CLOSE DIRECTORY #fn
NEXT D

END

READ_DIR:

FName = NEXTFILE(FN)
IF FName = undef THEN RETURN
PRINT Fname & "\n"
GOTO READ_DIR


John


758
General Discussions / Re: Having trouble getting execute command to work
« on: September 20, 2008, 11:24:19 AM »
Timm,

I just tried your execute command on my Windows XP box and it worked fine.

Note: only line in program.

a = execute ("cmd /c dir /b > list.txt", -1, pid)

The list.txt file contained the directory contents (filenames only)

What version of ScriptBasic are you using?

My test was with the 2.1 version.


John

759
General Discussions / Re: Having trouble getting execute command to work
« on: September 20, 2008, 10:33:40 AM »
Hi Timm,

I remember having an issue with redirects with execute under Linux where it would output to the screen instead of a file. I mentioned it to Peter and ended up using a shell script that called scriba and did the redirect stuff in a script.

I will give it a try under Windows and see if I can reproduce your problem. There may be a issue with execute and shell redirection and should be reported in the bug tracker.

John

760
General Discussions / Re: Having trouble getting execute command to work
« on: September 18, 2008, 06:32:34 AM »
Thanks Tim for the report on how you solved your problem.

Posting issues/solutions here helps others traveling the same road.


John

761
If all your looking for is a standalone executable, the scriba -E option works great.

Windows:

scriba -Eo hello.exe hello.bas


Linux:

/usr/bin/scriba -Eo hello hello.bas


John

762
Hi Don,

It seems this has been confusing process for some time. Here is another thread Peter responded to.

Scriptbasic - Compiling the generated C code

It would be nice if this process was easier. I was able to create standalone programs with gcc when I first got started with ScriptBasic in 2005 but haven't had much luck with the 2.1 release doing the same. I like Euphoria's method of generating C source and compiling to an executable in a simple two step process.

Once you get yours working, I would appreciate if you could post something here that a full time Basic programmer, part time C maintenance hack like myself can understand.  :) 

Thanks !

John

763
General Discussions / Re: Using dlls
« on: August 06, 2008, 06:14:47 PM »
Chris,

Here is the mysql.bas include file which defines the mysql::xxx function calls.

Code: [Select]
module mysql

declare sub ::RealConnect alias "mys_real_connect" lib "mysql"
declare sub ::Connect alias "mys_config_connect" lib "mysql"
declare sub ::Close alias "mys_close" lib "mysql"
declare sub ::Query alias "mys_query" lib "mysql"
declare sub ::FetchArray alias "mys_fetcharray" lib "mysql"
declare sub ::FetchHash alias "mys_fetchhash" lib "mysql"
declare sub ::AffectedRows alias "mys_affected_rows" lib "mysql"
declare sub ::ChangeUser alias "mys_change_user" lib "mysql"
declare sub ::CharacterSetName alias "mys_character_set_name" lib "mysql"
declare sub ::DataSeek alias "mys_data_seek" lib "mysql"
declare sub ::ErrorMessage alias "mys_error" lib "mysql"
declare sub ::GetClientInfo alias "mys_get_client_info" lib "mysql"
declare sub ::GetHostInfo alias "mys_get_host_info" lib "mysql"
declare sub ::GetProtoInfo alias "mys_get_proto_info" lib "mysql"
declare sub ::GetServerInfo alias "mys_get_server_info" lib "mysql"
declare sub ::Info alias "mys_info" lib "mysql"
declare sub ::InsertId alias "mys_insert_id" lib "mysql"
declare sub ::Kill alias "mys_kill" lib "mysql"
declare sub ::Ping alias "mys_ping" lib "mysql"
declare sub ::EscapeString alias "mys_real_escape_string" lib "mysql"
declare sub ::SelectDatabase alias "mys_select_db" lib "mysql"
declare sub ::Shutdown alias "mys_shutdown" lib "mysql"
declare sub ::Stat alias "mys_stat" lib "mysql"
declare sub ::ThreadId alias "mys_thread_id" lib "mysql"

end module

Look at the interface.c for the mysql extension module to see the code behind these functions.

Peter Verhas created a 'do nothing' extension module interface (trial) as an example that he documented pretty well and should be a big help. The developer guide has a section on building extension modules as well.

Post your progress reports as this forum could use a little activity.  ;)


John

764
Installation / Problems running install script
« on: June 27, 2008, 09:28:36 AM »
Quote

Problem solved.


Good to hear that you worked out your issue.

BTW: What OS / Version were you compiling ScriptBasic on?


John

765
General Discussions / Linux precompile?
« on: June 22, 2008, 04:10:59 PM »
Do you have any development tools installed at all?  :(

I would first try getting scriba to compile which should catch the scriba library and httpd versions as well.

The rest are missing dependencies. If your having problems, compile each module one and a time and look at the dependency file located in each extension directory for what you might be missing. Another problem you might be having is that ScriptBasic may be looking for the .so's in /usr/lib and under Ubuntu they are located in /usr/local/lib. Update your LD config to reflect where your libraries reside.

If your using gcc 4.x then you need to update the source with Peter's fixes. (posted in the download section)

I have a working set so I know if you have your system setup correctly you will achieve a clean compile.  If this seems like too much work for you, I could tar a set of binaries for you to work with till you get things working with your development tools.


John

Pages: 1 ... 49 50 [51] 52 53 ... 59