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

Just starting out? Need help? Post your questions and find answers here.
ivega718
User
User
Posts: 15
Joined: Mon Feb 25, 2013 9:29 pm

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

Post 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

jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

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

Post by jassing »

Time to read the help file.
You can use OpenFile() or ReadFile()
I have no idea what you mean by "command$"
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post by luis »

ProgramParameter(), FileSeek(), SizeOf(structure_name), ReadData(), WriteData()
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post by skywalk »

I think Command$ =

Code: Select all

RunProgram("cmd.exe")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
ivega718
User
User
Posts: 15
Joined: Mon Feb 25, 2013 9:29 pm

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

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post 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
BERESHEIT
Post Reply