Page 1 of 1

COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 12:09 am
by ivega718
Hi, I am new user of PureBasic. Only need know how I can use the COMMAND$ or wich variable is similar.

Also how I can emulate the OPEN...FOR RANDOM in other Basic.

Example:

Code: Select all

TYPE EMPLOYES
  CODE AS STRING * 10
  NAME AS STRING * 60
END TYPE

GLOBAL EMPLOYESX AS EMPLOYES

OPEN "FILE.DAT" FOR RANDOM AS #1 LEN=70
GET #1,1,EMPLOYESX


Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 12:54 am
by jassing
Time to read the help file.
You can use OpenFile() or ReadFile()
I have no idea what you mean by "command$"

Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 1:14 am
by luis
ProgramParameter(), FileSeek(), SizeOf(structure_name), ReadData(), WriteData()

Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 1:21 am
by skywalk
I think Command$ =

Code: Select all

RunProgram("cmd.exe")

Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 1:30 am
by Demivec

Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 1:47 am
by ivega718
Thanks to all.

I believe that ProgramParameter() resolve the COMMAND$.

COMMAND$ is used in other BASIC compiler's for extract the parameter of a application when is executed.

By example:

PROG.EXE filename.txt


I will see more about of files.

Re: COMMAND$ and OPEN ...for RANDOM in other BASIC's

Posted: Tue Feb 26, 2013 1:52 am
by netmaestro
In PureBasic you'd usually use a database, but the oldstyle random file access is also possible. Here's a sample:

Code: Select all

Structure EMPLOYEES
  code.s{10}
  name.s{60}
EndStructure

Declare UpdateEmployeeRecord(file, record_number, *record.EMPLOYEES)
Declare ReadEmployeeRecord(file, record_number)

With employee.EMPLOYEES
  \code = "1234"
  \name = "Barry Brigley"
EndWith

If CreateFile(0, "c:\employees.dat")
  For i=1 To 10*SizeOf(EMPLOYEES) ; We'll make the 10 empty records
    WriteByte(0, 0)
  Next
  CloseFile(0)
EndIf

If OpenFile(0, "c:\employees.dat")
  If UpdateEmployeeRecord(0, 4, @employee) ; Store a test record in slot 4
    Debug "Record Successfully Stored"
  EndIf
  CloseFile(0)
EndIf

If ReadFile(0, "c:\employees.dat")
  *record.EMPLOYEES = ReadEmployeeRecord(0, 4) ; Read our test record back
  If *record
    Debug *record\code
    Debug *record\name
    FreeMemory(*record)
  EndIf
  CloseFile(0)
EndIf

End

Procedure ReadEmployeeRecord(file, record_number)
  *result.EMPLOYEES = AllocateMemory(SizeOf(EMPLOYEES))
  FileSeek(file, record_number * SizeOf(EMPLOYEES))
  If ReadData(file, *result, SizeOf(EMPLOYEES)) = SizeOf(EMPLOYEES)
    ProcedureReturn *result
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Procedure UpdateEmployeeRecord(file, record_number, *record.EMPLOYEES)
  FileSeek(file, record_number * SizeOf(EMPLOYEES))
  If WriteData(file, @*record\code, SizeOf(employees\code)) = SizeOf(employees\code) And
     WriteData(file, @*record\name, SizeOf(employees\name)) = SizeOf(employees\name)
    ProcedureReturn 1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure