Author Topic: New FiliIO example  (Read 2461 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Guest
New FiliIO example
« on: March 13, 2018, 06:56:20 AM »
Thank you Charles for adding the msvcrt file IO.
A simple random access example.
The attached is the full O2RadAsm project including needed files. You can compile from the command line if desired.

James

Code: [Select]
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' not needed with O2RadAsm
' $filename "cFileIO.exe"
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
use rtl64
#autodim off
use console
use corewin
'------------------------------------------------------------------------------
'GetFields function from modified OxygenBasic\examples\DataProcessing\GetFields.o2bas app
include "GetFields.o2bas"
'------------------------------------------------------------------------------
Type AddressType
    FirstName     As zstring * 32
    LastName      As zstring * 32
    Company       As zstring * 64
    Address       As zstring * 64
    City        As zstring * 32
    County        As zstring * 32
    State        As zstring * 4
    Zip           As zstring * 12
    Phone1         As zstring * 24
    Phone2         As zstring * 24
    Email         As zstring * 64
    Url           As zstring * 64
End Type
'==============================================================================
Macro LineInput string (s,c)
    s = nuls 1024
    s = (char*)fgets(s,1024,c)
End Macro
'==============================================================================
Function main() As sys
    string sfileIn = "Myus-500tab.csv"
    string sfileOut  = "Address50.bin"
    string sLine
    sys fp1,fp2,fields,Count
    Dim As AddressType Address
    int bytes,where
    fp1 = fopen sfileIn,"r"
    If not fp1 Then
        printl "PROBLEM #1"
        waitkey
        exit function
    End If
    fp2 = fopen sfileOut,"w"
    If not fp2 Then
        printl "PROBLEM #2"
        fclose fp1
        waitkey
        exit function
    End If

    Do
        sLine = LineInput(fp1)
        If Len(sLine) = 0 Then
            fclose(fp1)
            fclose(fp2)
            printl "PROBLEM #3"
            waitkey
            exit function
        End If
        Count++
        If Count > 50 Then
            break
        End If
        fields = GetFields(sLine,chr(9))
        With Address.
            FirstName    = arg(1)
            LastName    = arg(2)
            Company     = arg(3)
            Address        = arg(4)
            City        = arg(5)
            County        = arg(6)
            State        = arg(7)
            Zip            = arg(8)
            Phone1        = arg(9)
            Phone2        = arg(10)
            Email        = arg(11)
            Url            = arg(12)
        End With   
        fwrite(@Address,sizeof(Address),1,fp2)       
    loop
    fclose fp1
    fclose fp2
    printl "Is it done?"
    Printl "Now lets read the first record from the binary file"  cr  "press any key"
    waitkey
    fp1 = fopen sfileOut,"r+"
    If not fp1 Then
        printl "PROBLEM #4"
        waitkey
        exit function
    End If
    fread @Address,sizeof(Address),1,fp1
    Printl "First Name -> " + Address.FirstName
    Printl "Last  Name -> " + Address.LastName
    Printl "State      -> " + Address.State
    Printl ""
    Printl "Now lets read the last record" + cr + "any key to continue"
     waitkey
     where = 49 * sizeof(Address)
     fseek fp1,where,0
     fread @Address,sizeof(Address),1,fp1
    fread @Address,sizeof(Address),1,fp1
    Printl "First Name -> " + Address.FirstName
    Printl "Last  Name -> " + Address.LastName
    Printl "State      -> " + Address.State
    fclose fp1
    Printl cr "any key to continue"
     
    waitkey
End Function
main


chrisc

  • Guest
Re: New FiliIO example
« Reply #1 on: March 13, 2018, 07:14:30 AM »
Excellent example, i will test it out
Thanxx James

Aurel

  • Guest
Re: New FiliIO example
« Reply #2 on: March 13, 2018, 08:24:58 AM »
----
« Last Edit: March 13, 2018, 10:00:49 AM by Aurel »

jcfuller

  • Guest
Re: New FiliIO example
« Reply #3 on: March 13, 2018, 08:57:22 AM »
Aurel,
  Do not use it. It appears it is way beyond your skill level.
  There is nothing I can add here that you would understand if you can not/will not read and understand the readme.txt and the O2RadAsm.htm files.

RE: 64bit. All exe's are 32bit. OS? I havn't used a 32bit OS in 20 years

I'll admit the RadAsm help file can be a bit cryptic.
If you have specific questions I'll try to help but .....
 
James

Aurel

  • Guest
Re: New FiliIO example
« Reply #4 on: March 13, 2018, 09:57:38 AM »
James
There is no need for talks from 'high expert points' .
I am not from yesterday and use many code editors.

Quote
I havn't used a 32bit OS in 20 years
..and heh that is ordinary lie...  ;D

Is there anyone here who compile any Oxygen basic (32bit) program with this editor?
probably only you James...

...anyway editor is good and have lot of build in things
Ok!  ...as conclusion i don't want to bother anyone with this !
good luck!