March 28, 2024, 11:47:13 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


SUB seems to require DECLARE if values passed either way

Started by billhsln, April 20, 2011, 09:15:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I wrote a quick and dirty program to catalog DVD's.  In prior versions I did not need a DECLARE statement for every SUB.  Now it seems that not only do I need one but with some commented out, I get Compiler aborts.  Here is the code that I am using, maybe some one can explain why I need the DECLARE or maybe why it gets a compiler abort?  It seems that if the SUB has parameters passed either way, then it requires a DECLARE, if there are no parameters then you don't need the DECLARE.

$MAIN
DEF Version$:STRING
Version$="1.0"
' This program will gather the DVD Info from the first CD-Rom Drive
'  Compile as CONSOL
AUTODEFINE "off"

DECLARE IMPORT,SHGetSpecialFolderLocation(hwnd:UINT,nFolder:INT,ppITEMIDLIST:POINTER),INT
DECLARE IMPORT,SHBrowseForFolder(param1:UINT),INT
DECLARE IMPORT,SHGetPathFromIDList(param1:UINT, param2:UINT),INT
DECLARE IMPORT,CoTaskMemFree(param1:INT),INT
DECLARE IMPORT,RtlZeroMemory(dat:UINT,length:INT),INT
DECLARE IMPORT,SendMessageA(hWnd:UINT, message:UINT, wParam:INT, lparam:UINT),UINT
DECLARE "Kernel32",GetVolumeInformationA(Path:POINTER,VolumeName:POINTER,nVolumeLen:INT,Serial:POINTER,MaxComponentLength:POINTER,FileSystemFlags:POINTER,FileSystemName:POINTER,FileSystemNameLen:INT),INT
DECLARE "kernel32",GetDriveTypeFL ALIAS GetDriveTypeA(dir:STRING),INT
DECLARE "kernel32",GetLogicalDrivesFL ALIAS GetLogicalDrives(),INT

' Comment this out and you get  Variable name: dir has previous declaration in iwbstd.incc
' If I change dir to dirs, I end up with Undefined function
DECLARE GetFilesFL(Path:STRING, Ext:STRING)
' Comment this out and the compiler aborts
DECLARE GetSubDir(SubDir:STRING, Path:STRING, Ext:STRING)
' Comment this out and I get Undefined function
DECLARE GetFolderLocation(nFolder:INT),STRING
' Comment this out and I get Undefined function
DECLARE GetDriveTypeStrFL(dir:STRING),STRING
' Comment this out and I get Undefined function
DECLARE GetAllDrivesStr(),STRING

TYPE BROWSEINFO
UINT hOwner
UINT pidlRoot
POINTER pszDisplayName
POINTER lpszTitle
UINT ulFlags
UINT lpfn
UINT lParam
UINT iImage
ENDTYPE

CONST WM_USER               = 0x400
CONST BFFM_SETSELECTION     = WM_USER + 102
CONST BFFM_INITIALIZED      = 1
CONST BFFM_VALIDATEFAILED   = 3
CONST BIF_RETURNFSANCESTORS = 8
CONST BIF_RETURNONLYFSDIRS  = 1
CONST BIF_NEWDIALOGSTYLE    = 0x40
CONST BIF_DONTGOBELOWDOMAIN = 2
CONST BIF_FLAGS             = WM_USER + BIF_NEWDIALOGSTYLE + BIF_RETURNONLYFSDIRS
'0x441

DEF Ofile:FILE
DEF FileName:STRING
DEF Drives:STRING
DEF Drive, DVD_Path, Catalog_Path, dir, CD_Num, rtn:STRING
DEF sdir[261],odir[261]:ISTRING
DEF CD_No, i, l, cnt, dcnt, tracks:UINT
DEF q, c, qc, qcq, cq:STRING

DEF vl,fsnl:INT
DEF Serial, mcl,fsf,f:INT
DEF fsn:STRING

' ="
q = "\""
' =,
c = chr$(44)
qc = q + c
qcq = qc + q
cq = c + q

OPENCONSOLE

' My Documents Folder
Catalog_Path = GetFolderLocation(5)
PRINT "Catalog_Path = ", Catalog_Path

Drives = GetAllDrivesStr()
l = len(Drives)
FOR i = 1 TO l
dir = MID$(Drives,i,1) + ":\\"
IF GetDriveTypeStrFL(dir) = "CD-ROM"
DVD_Path = dir
PRINT "DVD_Path = ", DVD_Path
i = l + 1
ENDIF
NEXT i

CD_No = GetVolumeInformationA(DVD_Path,CD_Num,255,&serial,&mcl,&fsf,&fsn,255)
PRINT "   CD_No = ", CD_No
'PRINT "DVD_Path = ", DVD_Path
PRINT "  CD_Num = ", CD_Num
'PRINT "      vl = ", vl
'PRINT "  Serial = ", Serial
'PRINT "     mcl = ", mcl
'PRINT "     fsf = ", fsf
'PRINT "     fsn = ", fsn
'PRINT "    fsnl = ", fsnl

FileName = Catalog_Path + "\\Bill's DVD Catalog.CSV"
IF (OPENFILE(Ofile,FileName,"A") <> 0)
PRINT "File: " + FileName + " Not able to Open Output"
GOTO Aborted
ENDIF

dcnt = 0

GetFilesFL(DVD_Path,".AVI")

CLOSEFILE Ofile

GOTO Final
LABEL Aborted
PRINT "---Program Aborted---"
PRINT " "
INPUT "Press Enter when Done", rtn
LABEL Final
CLOSECONSOLE
END

'______________________________________
SUB GetFilesFL(Path:STRING, Ext:STRING)
'______________________________________
DEF Npath, Cpath:STRING
DEF dir, attrib:INT

Npath = Path + "*.*"
dir = FINDOPEN(Npath)
IF (dir)
DO
Cpath = FINDNEXT(dir,attrib)
IF (attrib & @file_directory)
IF (Cpath = "") OR (Cpath = ".") OR (Cpath = "..")
l = 0
ELSE
Npath = Path + Cpath + "\\"
GetSubDir(Cpath, Npath, Ext)
ENDIF
ENDIF
UNTIL Cpath = ""
FINDCLOSE dir
ENDIF

RETURN
ENDSUB

'____________________________________________________
SUB GetSubDir(SubDir:STRING, Path:STRING, Ext:STRING)
'____________________________________________________

DEF filename, temp:STRING
DEF dir, attrib:INT

temp = Path + "*.*"
dir = FINDOPEN(temp)
IF (dir)
DO
filename = FINDNEXT(dir,attrib)
IF (attrib & @file_directory)
IF (filename <> "") AND (filename <> ".") AND (filename <> "..")
GetSubDir(SubDir,Path + filename + "\\",Ext)
ENDIF
ELSE
Ext = UCASE$(RIGHT$(filename,3))
IF Ext = "AVI"
WRITE Ofile, q + CD_Num + qcq + path + qcq + filename + q
cnt = cnt + 1
dcnt = dcnt + 1
ENDIF
ENDIF
UNTIL filename = ""
ENDIF
FINDCLOSE dir

RETURN
ENDSUB

'________________________________________
SUB GetFolderLocation(nFolder:INT),STRING
'________________________________________
DEF path[260]:ISTRING
DEF pidl:POINTER
DEF ppidl:POINTER
path = ""
ppidl = &pidl
SHGetSpecialFolderLocation(NULL,nFolder,ppidl)
SHGetPathFromIDList(pidl,&path)
CoTaskMemFree(pidl)
RETURN path
ENDSUB

'_______________________________________
SUB GetDriveTypeStrFL(dir:STRING),STRING
'_______________________________________
DEF t:STRING
DEF n:INT
t = dir
IF (RIGHT$(dir,1)<>"\\") THEN t = t+"\\"
n = GetDriveTypeFL(t)
SELECT n
CASE 2
RETURN "Removable"
CASE 3
RETURN "Fixed"
CASE 4
RETURN "Remote"
CASE 5
RETURN "CD-ROM"
CASE 6
RETURN "RamDisk"
DEFAULT
RETURN STR$(n)
ENDSELECT
RETURN STR$(n)
ENDSUB

'___________________________
SUB GetAllDrivesStr(),STRING
'___________________________
DEF n, t, s:INT
DEF d:STRING
d = ""
n = GetLogicalDrivesFL()
FOR t=0 TO 25
s = 2 ^ t
IF (n & s)
d += CHR$(65 + t)
ENDIF
NEXT t
RETURN d
ENDSUB


Thanks,
Bill
When all else fails, get a bigger hammer.

sapero

Wow, you've found another bug!
The preceding line of each SUB ends with an underscore, which is used in the first pass to merge lines.
Try adding a space at the end of the comment, if the line ends with "_":'______________________________________<space>
SUB GetFilesFL(Path:STRING, Ext:STRING)
'______________________________________<space>

billhsln

I think I will change it from underscores to dashes, should solve the problem.

Thank you for the quick answer.

Take care,
Bill
When all else fails, get a bigger hammer.