Date Storage Issue

more a keyword and int value that the value you want it really used and not other one.

In my last adventure with RB, I started to use the Dictionary class and found it had some interesting advantages for coding over trying to find array values. I actually used both arrays and the Dictionary class. The code was more intuitive to follow and to find values and besides the values are stored as variants. I have given thought to use them again. Any thoughts on this subject? I think there are our key/pair options available also.

It sounds like when storing to text files it might be better to use the text format conversion on all sting conversions not just dates. Would that be safer?

What was the file format like? Care to share a code snippet that wrote a few values to the file, just so we can get a better idea of what you’re used to working with?

What kind of keys/values did you use with the dictionaries? Again, a few examples might be instructive and help us guide you more effectively.

I refresh these values and many other temperature, input sensors, and switches on a continuously running cycle timer.

Temperature_Dictionary.value(“Storage Area Temp”) = BK7TR.ReadSensor(“BK7”,2)
Temperature_Dictionary.value(“Floor Intake Temp”) = BK7TR.ReadSensor(“BK7”,3)
Temperature_Dictionary.value(“Ceiling Temp”) = BK7TR.ReadSensor(“BK7”,4)
Temperature_Dictionary.value(“Kitchen Temp”) = BK7TR.ReadSensor(“BK7”,5)
Temperature_Dictionary.value(“Upstairs Temp”) = BK7TR.ReadSensor(“BK7”,6)
Temperature_Dictionary.value(“Bedroom Temp”) = BK7TR.ReadSensor(“BK7”,7)

and then use them in the program something like this;

if value("Ceiling Temp") > fanSpeedSetTemp1 then setFanSpeed1 //Turn the fan on to speed one, two or three depending on passive heat gained at the ceiling. end
My code now becomes intuitive to read and work with rather than array values. The Syntax may be off a bit on this but you get the idea.

I was even storing in some cases these key/pairs as variants on the HD which seemed to work. I recently was reading something about key pair arrays which I will have to explore a little more.

but i would use string constants to prevent typos.

Do you mean convert it like this then use CeilingFanValue

var cellingTempValue as integer or whatever
CeilingTempValue = value(“Ceiling Temp”)

no - its looks like
Value(kCeilingTemp)
and kCeilingTemp is a constant String somewhere added in the project tree.
you can see the text content at mouse over.

[quote=495491:@Markus Rauch]no - its looks like
Value(kCeilingTemp)
and kCeilingTemp is a constant String somewhere added in the project tree.
you can see the text content at mouse over.[/quote]

How or would you assign Value(kCeilingTemp) to value(“Ceiling Temp”) ?
Would that somehow be using attributes and assigning Name and a value or something else?

I’m still a bit confused on this since you are speaking about a constant.

yes, you can add String Constants in the IDE.
if you input
“Ceiling Temp”
“CeilingTemp”
“Ceiing Temp”
because your Keyboard hang & skip a key you have multiple meanings and what you write in the dictionary is not what you will read. these things happen and required unnecessary time for bug hunting.
enumerations are also a good thing.

Using a dictionary this way is a great idea. I’m not sure how it would be incompatible with your array structure.

Were you saving the labels (dictionary keys) to the file along with the value? That would be a very good structure to retain.

dictionary can also be converted to json and then saved.

It took me a moment to grasp what you knew and I didn’t. If I define a constants like :

Const kAppName As String = “MyApp”

I then use the name kAppName and it will self fill as I type it in so mistakes are avoided.

Are these all defined under the constants heading? I do not see a type for date which I might guess could be a number.

You can create constants in a module and use them globally. A date is an object, so you can’t create a constant for it. But you can create a constant as a string or integer representation and build a global date property in app.open.

You’re way ahead of me but I will keep this in mind when I get as knowledgable as you about all of this. Remember I’m at XOJO for Dummies at the moment.

In the global module do you just define like this:

Const kAppName As String = “MyApp”
Const kAppName2 As String = “MyApp2”
Const kAppName3 As String = “MyApp3”

How about an array?
Const kAppName(10) As String = “MyApp(10)”

you could use the same syntax as the datetime output here
.SQLDate
.SQLDateTime
for string constants.
and = DateTime.FromString(…) would return a object from string input

constant objects did not exists by design.

i believe the ide support only a single value for one constant.
but you could write “a,b,c,d” and then .Split(",") and choose one of them.

[quote=495526:@Clifford Coulter]In the global module do you just define like this:

Const kAppName As String = “MyApp”
Const kAppName2 As String = “MyApp2”
Const kAppName3 As String = “MyApp3”
[/quote]
The Const keyword declares a local constant, only accessible to the method it is defined in. To get global scope, use the Insert menu to add a constant to the method. Fill out the Name and Default Value fields. Set the Scope to global. Now you can use it anywhere in your code.

[quote]
How about an array?
Const kAppName(10) As String = “MyApp(10)”[/quote]
No, you cannot create a constant array. Arrays are reference types and cannot be represented by a constant. Nor can you create an array of constants. You can, however, create each constant separately and assemble them into an array in code in App.Open or Window.Open. The array should be a property of the method in order to be globally accessible.

Well, guys, the constant association does work nicely as long as I keep the conversions straight and give them meaningful names. It is an interesting concept once I got it. I’m wondering if it can be taken further such as assigning an instance like d.anObject to myObject.

[quote=495534:@Tim Hare]The Const keyword declares a local constant, only accessible to the method it is defined in. To get global scope, use the Insert menu to add a constant to the method. Fill out the Name and Default Value fields. Set the Scope to global. Now you can use it anywhere in your code.

No, you cannot create a constant array. Arrays are reference types and cannot be represented by a constant. Nor can you create an array of constants. You can, however, create each constant separately and assemble them into an array in code in App.Open or Window.Open. The array should be a property of the method in order to be globally accessible.[/quote]

Just to make sure I’m following correctly. I could not assign EntryMotionSensor to an array item SWBK(14) as a constant.