# Beginner Writing Biorythm Prog in VB



## leachim (Apr 21, 2004)

Hi

I have a book on VB, which is a little daunting and am wondering if anyone could point me in the right direction in writing this prog.

To get me going, all I need to know for now is how to get it to store all the data that will be used to calculate.

For instance - each year has 3 numbers which relate to Physical, Emotional and Intellectual

eg 1945 P=8 E=21 I=17

There are a few hundred years to input. Also each day of the year has 3 more numbers attributed to it.

The prog would store all this and use it to calculate depending on what year and date etc. was inputed.

All I need to know for now is what format and in which section of the code I need to type all this info in

Thanks

Mike


----------



## coderitr (Oct 12, 2003)

Hi Mike

You don't want to type in these vakues in your code. Your question addresses a fundamental approach in computing -- data storage. There are, obviously, a variety of methods from simple text files to relational databases. The one you choose depends on a number of factors like: Who is going to use this application when you're done with it? Should they be allowed to change the data at the source instead of going through your application to do it? Will they be allowed to change the data at all? How much if any data security will you implement?

That said, since you're talking about several hundred rows, I would use MS Access to build a database to store the data then retrieve and process it using your program. Are you going to store the result or re-do the calculation each time you run it? If you are going to store the results (not knowing anything about biorythyms I don't know if there is even a result to store) then you can include a column in your database for it. 

If you decide to use a database solution, please consider using ADO. You'll be glad you did later -- trust me on this. With ADO, the programmer and indeed the application does not need to know or care what database provider the target is. The code is written exactly the same way whether you're using MS Access or Oracle. The only database specific code you have to write is the initial connection.

Good luck with your project

Keith


----------



## leachim (Apr 21, 2004)

Thanks

I will answer your questions individually below



coderitr said:


> Hi Mike
> 
> You don't want to type in these vakues in your code. Your question addresses a fundamental approach in computing -- data storage. There are, obviously, a variety of methods from simple text files to relational databases. The one you choose depends on a number of factors like: Who is going to use this application when you're done with it?


Hopefully other people will be able to make use of it if I ever complete it 



coderitr said:


> Should they be allowed to change the data at the source instead of going through your application to do it?


They will not be able to change any of the data. The data should all be enlosed in the programme (.EXE) file (if this is possible)



coderitr said:


> Will they be allowed to change the data at all? How much if any data security will you implement?


As above - don't know much about security, but if the core data was changed then the programme would be inaccurate.



coderitr said:


> That said, since you're talking about several hundred rows, I would use MS Access to build a database to store the data then retrieve and process it using your program. Are you going to store the result or re-do the calculation each time you run it? If you are going to store the results (not knowing anything about biorythyms I don't know if there is even a result to store) then you can include a column in your database for it.


I have used Access before - I hope the programme is able to store results that will be able to be used for future calculations.



coderitr said:


> If you decide to use a database solution, please consider using ADO. You'll be glad you did later -- trust me on this. With ADO, the programmer and indeed the application does not need to know or care what database provider the target is. The code is written exactly the same way whether you're using MS Access or Oracle. The only database specific code you have to write is the initial connection.


Not sure what ADO is ? 

Biorythms are cycles of Physical, Emotional and Intellectual which change from day to day. The prog will basically be a number crunching facility taken from the core data I type into the database. It will use these figures to work out some numbers from a date which the end user will type in to get a result.

Example Feb 20th - P=20 E=7 I=17
Each year also has numbers ie 1945 P=8 E=21 I=17

You add both P numbers together to get 28. Similarly with E and I numbers. Therefore 20th Feb 1945 would be P=28 E=28 I=34

These 3 figures are then used for more calculations.

Thanks for listening so far !

Mike


----------



## coderitr (Oct 12, 2003)

leachim said:


> Biorythms are cycles of Physical, Emotional and Intellectual which change from day to day. The prog will basically be a number crunching facility taken from the core data I type into the database. It will use these figures to work out some numbers from a date which the end user will type in to get a result.
> 
> Example Feb 20th - P=20 E=7 I=17
> Each year also has numbers ie 1945 P=8 E=21 I=17
> ...


That's an awful lot of data. A set for each day of the year and a set for each year if I'm understanding correctly. You *can* store data like that in the EXE if you want to but the first question I would ask is how these figures are calculated to begin with. What makes P = 20 on Feb 20th? From that, you can get a smaller subset of data coded into your program. Otherwise, you are storing a huge amount of data in your program.

Although, I suppose if P = 20 on Feb 20th every year then a matrix of values would work also. Allocate three integer variables contained inside a Private Type and then dimensionalize an array of 366 instances of that type. Like this:


```
Type PEI_VALUES
   P as Integer
   E as Integer
   I as Integer
End Type

Dim arrValues(366) AS PEI_VALUES
arrValues(1).P = 21
arrValues(1).E = 6
arrValues(1).I = 17
```
Obviousy, I just made up those numbers. I have absolutely no idea what the correct values are. My point is that each element of the arrValues array represents a day. Jan 1 is 1, Dec 31 is either 365 or 366 depending on whether or not the given year is a leap year. Of course, this scenario is based on the assumption that the P, E and I values are the same on a given calendar day in any given year. If that assumption is invalid then this approach fails and we're back to figuring out what makes P = 20 on Feb 20th and coding that algorithm into the program itself.

That leaves only the values for the year. That one will require a little more work and I don't know how I would do that yet.

I know I'm babbling a bit but I hope this is helpful.


----------



## leachim (Apr 21, 2004)

Yep, you are on the right track

I suppose I had better make it more understandable, so attach 2 files with the data on

Hope it makes sense then !!

Cheers


----------



## coderitr (Oct 12, 2003)

Wow. That's fairly daunting. It looks like the values are the same every year so the array of values in code will work. The data entry will be tedious and error prone but it is the best way to ensure that the data doesn't get changed. I looks like your tables go through 1999. You have to determine the values for the year as well, right? Do you already know what that value is going to be through like 2025 or something? If not, is there a way to calculate it? What's the next step?


----------



## leachim (Apr 21, 2004)

coderitr said:


> Wow. That's fairly daunting. It looks like the values are the same every year so the array of values in code will work. The data entry will be tedious and error prone but it is the best way to ensure that the data doesn't get changed. I looks like your tables go through 1999. You have to determine the values for the year as well, right? Do you already know what that value is going to be through like 2025 or something? If not, is there a way to calculate it? What's the next step?


OK, I have tables for the other years, so that is not a problem

The first hurdle is knowing how to type this data into the programme, in a form that can be extracted and worked on depending on what dates the end user types in.

Basically, each day of the year has 3 numbers in 3 columns of Physical, Emotional & Intellectual (mental)

Also each year has 3 numbers as above.

Therefore when a date and year is typed in, you end up with 2 numbers for Physical, 2 numbers for Emotional and 2 numbers for Intellectual.

These would be added together as below

*Example

6th July is 
P(22) E(11) I(13)

1883 is 
P(21) E(14) I(24)

Result would be P(43) E(25) I(37)*​
Other calculations would be done after that, but not lets confuse it now !

I did a VB course at an adult education centre 2 years ago, but some of it went over my head !

Cheers


----------



## leachim (Apr 21, 2004)

Hi Keith

I replied to your message on the 22nd

Don't worry, I expect you are busy, and I also see you are a Sports Fan !

Cheers

Mike
UK


----------



## coderitr (Oct 12, 2003)

Sorry, Mike. I haven't had much time to spend on this over the last couple of days.

The most secure way to get this data into your program is to code it. That way the data cannot be changed without decompiling the executable. Again, I suggest building an array as I did above and loading the values with the array index representing the julian day of the year (Jan 1 = 1; Jan 2 = 2, Feb 1 = 32, etc.) Do you know how to do that? For the year values, I would build another array with the index representing a year (1899 = 1, 1900 = 2, etc.) As long as you know where you started, you'll be able to work with that. The hard part is going to be making sure that you key all this data in without making errors. I know that it is extremely easy to flub something like that when you start looking at hundreds of numbers. The all start running together (at least for me that's the way it works  )


----------



## leachim (Apr 21, 2004)

coderitr said:


> I suggest building an array as I did above and loading the values with the array index representing the julian day of the year (Jan 1 = 1; Jan 2 = 2, Feb 1 = 32, etc.) Do you know how to do that? For the year values, I would build another array with the index representing a year (1899 = 1, 1900 = 2, etc.)


Thanks

Apologies for being a bit dim - if you could show me how to start typing in the data into the programme using the info in the jpg images as an example, I should be able get on with it.

I have seen the code you suggested above, but can't understand the second bit - sorry, my brain, not yours. 

Cheers


----------



## coderitr (Oct 12, 2003)

The definition of the values container


```
Public Type BR_VALUES
    P As Integer
    E As Integer
    I As Integer
End Type
```
Declare an array of 366 elements to hold the day-specific values

```
Public DayValues(366) As BR_VALUES
```
This subroutine loads one element of the array


```
Public Sub LoadDayValuesArray(ndx as Long, intP As Integer, intE As Integer, intI As Integer)

   DayValues(ndx).P = intP
   DayValues(ndx).E = intE
   DayValues(ndx).I = intI

End Sub
```
Call the subroutine passing the following:
(1) the index of the array element you want to load
(2) the P value
(3) the E value
(4) the I value

Parameter 1 is the julian day number. Jan 1st is 1; Jan 2nd is 2; Feb 1st is 32; etc. The picture you posted containing the day values is July - December and since July 1st is the 183rd day of the year assuming there is a Feb 29th ...


```
LoadDayValuesArray 183, 4, 16, 18
LoadDayValuesArray 184, 3, 15, 17
LoadDayValuesArray 185, 2, 14, 16
LoadDayValuesArray 186, 1, 13, 15
LoadDayValuesArray 187, 0, 12, 14
LoadDayValuesArray 188, 22, 11, 13
LoadDayValuesArray 190, 21, 10, 12
LoadDayValuesArray 191, 20, 9, 11
```
 and so on until you have all 366 days loaded. I suggest coding as if every year is a leap year and if the user enters a year that is a non-leap year then you add one to the index before you retrieve the data.


----------



## leachim (Apr 21, 2004)

Cheers for that !

I have typed that in as below

*Private Sub Form_Load()

Public Type BR_VALUES
P As Integer
E As Integer
I As Integer
End Type

Public DayValues(366) As BR_VALUES

Public Sub LoadDayValuesArray(ndx As Long, intP As Integer, intE As Integer, intI As Integer)

DayValues(ndx).P = intP
DayValues(ndx).E = intE
DayValues(ndx).I = intI

End Sub

LoadDayValuesArray 183, 4, 16, 18
LoadDayValuesArray 184, 3, 15, 17
LoadDayValuesArray 185, 2, 14, 16
LoadDayValuesArray 186, 1, 13, 15
LoadDayValuesArray 187, 0, 12, 14
LoadDayValuesArray 188, 22, 11, 13
LoadDayValuesArray 190, 21, 10, 12
LoadDayValuesArray 191, 20, 9, 11

End Sub*​
However, being as rusty as I am, I don't want to be coming back to you time after time with silly questions - so can I donate some cash to you via PayPal to get it sort of working ?

I can type in the long data stuff, to save you time

Whaddya say ?

All the Best

Mike


----------



## coderitr (Oct 12, 2003)

Just tell me how much you want me to do.


----------



## leachim (Apr 21, 2004)

coderitr said:


> Just tell me how much you want me to do.


Well all I need is a simple input box for date to be entered DD MM YYYY

then the calculations to be made

Example

6th July is 
P(22) E(11) I(13)

1883 is 
P(21) E(14) I(24)

Preliminary Result would be P(43) E(25) I(37)

If P>=23 then 23 is subtracted from P
If E>=28 then 28 is subtracted from E
If I>=33 then 33 is subtracted from I

The figures resulting from previous paragraph are displayed in 3 boxes "Physical" "Emotional" & "Intellectual"

I have not considered how it could determine a leap year though - it says that dates between Mar 1st and Dec 31st have to add 1 to each of the 3 numbers....

Nothing fancy needed - I suppose a form that has 3 input boxes and 3 result boxes.

As mentioned, I can type in the data stuff.

Don't take this the wrong way, but how much would $20 get me 

Thanks

Mike


----------



## coderitr (Oct 12, 2003)

Let me see what I can put together over the next couple of days. I may not have a lot of time to work on it but what you're asking for isn't that complicated. I'm going to PM you my email address.


----------



## FTamlyn (Feb 26, 2005)

interesting stuff about data storage, but isnt this all missing the point? the thing about biorhythms is that they are supposedly cyclical. So rather than type in a bucketload of data (that was calculated in the first place by a computer) just work it out from basics- which goes like this....

vb will store dates as a number- the integer part of the date is how many days have passed since some arbitrary date in the past....

today = int(now())

your birthdate can be inputted somehow, then converted into a date......

mybirthdate=int(dateserial(1967,5,2) 'for the second of may, 67, for instance

then... if one of the cycles is 28 days long......

PositionInCycle = (today-mybirthdate) mod 28

now, either you have a little lookup table with28 values in, or you go one step further and use a sine thingie.....

value = amplitude* sin(PositionInCycle/28 * 2 * 3.1419)

sooo.... in a few lines of code you save a lifetime of typing <g>....

Personally, when I want to know where I am emotionally and everything, I just look out of the window and see what phase the moon is in.

)


----------

