Author Topic: reading and writing to a file  (Read 4866 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reading and writing to a file
« Reply #15 on: February 25, 2021, 10:38:03 pm »
Hi

I would also suggest looking at  the open as random option with fixed length user defined types you can build simple database functions that way.  I am planning on using  that for storing game assets.

Brian....

Yep! I agree that would be the next step after getting some basic file reading and writing practiced.

Open fileName$ for Random Access along with setting up a record by learning UDT = User Defined Type definitions.

Offline 191Brian

  • Newbie
  • Posts: 91
    • View Profile
    • My Itch page
Re: reading and writing to a file
« Reply #16 on: February 26, 2021, 08:01:35 am »
BTW UDT's User Defined Types was a revelation to me when I found them going through Terry Ritchie's tutorial http://www.qb64sourcecode.com/

They make the coding much more efficient/easy to read and if you come from a database background they look very familiar.

Without them if you wanted to store say order details (order no, item No, item desc, qty, price) in an array(s) you create one multi dimension array, have to remember which dimension was which field and do type conversions between strings and numbers or create 5 separate arrays for each field.
With UDT you can just create the UDT and an array of the UDT type e.g

Code: QB64: [Select]
  1.  
  2. TYPE ordLine
  3.     ordNo AS INTEGER
  4.     lineNo AS INTEGER
  5.     itemDesc AS STRING * 50 ' Fixed length string
  6.     qty AS SINGLE
  7.     price AS SINGLE
  8.  
  9. REDIM OrderDtl(10) AS ordLine
  10.  
  11.  
  12. OrderDtl(1).ordNo = 156
  13. OrderDtl(1).lineNo = 1
  14. OrderDtl(1).itemDesc = "Some Widget"
  15. OrderDtl(1).qty = 2
  16. OrderDtl(1).price = 2.5
  17.  
  18. PRINT OrderDtl(1).ordNo, OrderDtl(1).lineNo, RTRIM$(OrderDtl(1).itemDesc), OrderDtl(1).qty, OrderDtl(1).qty * OrderDtl(1).price

Brian ...
Brian ...

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: reading and writing to a file
« Reply #17 on: February 26, 2021, 08:14:28 am »
I think everyone is still going beyond the scope of his current project. We don't want to overwhelm him and have him jump into databases and the like before he figures out regular file operations.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: reading and writing to a file
« Reply #18 on: February 26, 2021, 11:28:29 am »
I think everyone is still going beyond the scope of his current project. We don't want to overwhelm him and have him jump into databases and the like before he figures out regular file operations.

NOT(everyone)

Quote
Yep! I agree that would be the next step after getting some basic file reading and writing practiced.

So I am agreeing with you, @SpriggsySpriggs and I bet anyone who disagrees with that is in the minority.
And I think 191B is OK for showing some hints about UDT with a practical example that is in line with OP (= original post or poster)

And further nobody in this thread has suggested otherwise.

It's not like we are talking about API stuff and bringing in all these terms from who knows where or what? ;-))

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: reading and writing to a file
« Reply #19 on: February 26, 2021, 01:05:16 pm »
@bplus
Quote
And further nobody in this thread has suggested otherwise.
I'm just making a statement that we want to keep it extremely basic since he is a beginner. Steve and Atomic Kevin's messages are the two most relevant answers to his question.

Quote
It's not like we are talking about API stuff and bringing in all these terms from who knows where or what? ;-))
Which is exactly why I didn't bring up using the WinAPI. He mentioned he's a beginner and I know that would be asking him to skip many steps.
Shuwatch!