How handle dates to make a little agenda?

Find quick help here to get you started with Hollywood
User avatar
Juan Carlos
Posts: 887
Joined: Mon Sep 06, 2010 1:02 pm

How handle dates to make a little agenda?

Post by Juan Carlos »

I have this doubt how handle dates as nane, phone, address, mail etc. opening a file with these dates, to read, write, modify, because I only have got handle date files to configs etc. I don't know the programming methods to make possible this a little agenda, it would have been a good example in Hollywood.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How handle dates to make a little agenda?

Post by airsoftsoftwair »

Are you looking for a way to store data? XML might be a good choice for that or the JSON library recently released.
User avatar
Juan Carlos
Posts: 887
Joined: Mon Sep 06, 2010 1:02 pm

Re: How handle dates to make a little agenda?

Post by Juan Carlos »

airsoftsoftwair wrote: Thu Jun 06, 2019 5:47 pm Are you looking for a way to store data? XML might be a good choice for that or the JSON library recently released.
No I don't look that, because I think in the old ways with txt files. The xml is newest for me, but I have work with it, because I need an agenda program to my own style.
Thank you, Andreas.
User avatar
Clyde
Posts: 348
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: How handle dates to make a little agenda?

Post by Clyde »

Then maybe use e.g. semicolon based csv files. These are text files. E.g. the content could be:

name;phone;address;email
Juan;0815;One Way 10;jc@gmail.com
Andreas;1337;AllWays 43;andreas@hw.com
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
User avatar
Juan Carlos
Posts: 887
Joined: Mon Sep 06, 2010 1:02 pm

Re: How handle dates to make a little agenda?

Post by Juan Carlos »

Clyde wrote: Thu Jun 06, 2019 11:44 pm Then maybe use e.g. semicolon based csv files. These are text files. E.g. the content could be:

name;phone;address;email
Juan;0815;One Way 10;jc@gmail.com
Andreas;1337;AllWays 43;andreas@hw.com
Yes it is other option, although i need some example too.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: How handle dates to make a little agenda?

Post by amyren »

I made this example, this will save it as a regular textfile.

Code: Select all

; just adding some data to work with
firstname$={}
lastname$={}
street$={}
housenumber$={}
InsertItem(firstname$, "Richardo")
InsertItem(lastname$, "Stone")
InsertItem(street$, "Hudsonroad")
InsertItem(housenumber$, "675")
InsertItem(firstname$, "John")
InsertItem(lastname$, "Johnson")
InsertItem(street$, "Oceanside")
InsertItem(housenumber$, "842")
InsertItem(firstname$, "Oscar")
InsertItem(lastname$, "Wilde")
InsertItem(street$, "Faraway")
InsertItem(housenumber$, "1214")

;  save To file
	OpenFile(1, "adressbook.data", #MODE_WRITE)
	For i = 0 To ListItems(firstname$)-1
		WriteLine(1, firstname$[i])
		WriteLine(1, lastname$[i])
		WriteLine(1, street$[i])		
		WriteLine(1, housenumber$[i])
	Next
	CloseFile(1)
	
; load from file
		OpenFile(1, "adressbook.data", #MODE_READ)
		While Not Eof(1)
			loadedline$ = ReadLine(1)
			InsertItem(firstname$, loadedline$)
			loadedline$ = ReadLine(1)
			InsertItem(lastname$, loadedline$)
			loadedline$ = ReadLine(1)
			InsertItem(street$, loadedline$)		
			loadedline$ = ReadLine(1)
			InsertItem(housenumber$, loadedline$)						
		Wend	
		CloseFile(1)	

; save again, just for verifying that data was added when loading
; if this worked as intended, the file adressbook.data will now contain two copies of the data 
	OpenFile(1, "adressbook.data", #MODE_WRITE)
	For i = 0 To ListItems(firstname$)-1
		WriteLine(1, firstname$[i])
		WriteLine(1, lastname$[i])
		WriteLine(1, street$[i])
		WriteLine(1, housenumber$[i])		
	Next
	CloseFile(1)
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How handle dates to make a little agenda?

Post by jPV »

Does it have to be human readable text files? If not, you could use WriteTable() and ReadTable() to get a really easy solution.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: How handle dates to make a little agenda?

Post by amyren »

jPV wrote: Tue Jun 11, 2019 5:22 pm Does it have to be human readable text files? If not, you could use WriteTable() and ReadTable() to get a really easy solution.
Could you please make a small working example, similar to the one I posted?
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How handle dates to make a little agenda?

Post by jPV »

for example something like this:

Code: Select all

addressbook = {
    {name="Juan", phone="0815", address="One Way 10", email="jc@gmail.com"},
    {name="Andreas", phone="1337", address="AllWays 43", email="andreas@hw.com"}
}

; Print names and emails just for a test:
For Local i=0 To ListItems(addressbook)-1
    DebugPrint(addressbook[i].name, addressbook[i].email)
Next

; Add a new data:
InsertItem(addressbook, {name="jPV", phone="555", address="Which Way 1", email="jpv@thisway.com"})

; Save the table to a file:
OpenFile(1, "ram:abook.dat", #MODE_WRITE)
WriteTable(1, addressbook)
CloseFile(1)

; Read the saved table:
OpenFile(1, "ram:abook.dat", #MODE_READ)
addressbook = ReadTable(1)
CloseFile(1)

; It still works as supposed :)
For Local i=0 To ListItems(addressbook)-1
    DebugPrint(addressbook[i].name, addressbook[i].email)
Next
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: How handle dates to make a little agenda?

Post by amyren »

Thanks. I hope this also answers Juan's question.
Post Reply