Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation 1

Status
Not open for further replies.

tsp1lrk

IS-IT--Management
May 30, 2001
103
US
Hello,

I'm trying to figure out code for a calculation I'm working with- I need to determine a date and a year from the following information: (uses the 2nd number)

237= 2(2002); 37 - 13 = Week 24 of 2002 = June 2002

Another one:
212= 2(2002); 12 - 13 = Week 51 of 2001 = December 2001

Using a different number:
437 = 4(2004); 37 – 13 = Week 24 of 2004 = June 2004

I'm using ASP.net/VB.net and I have 2 textboxes to collect the info. I'm stuck trying to determine how to begin- Can anyone help me? Appreciate any insight on this one-

Thanks,
Lisa
 
One apporach:

Dim strYear As String
Dim strMonth As String
Dim strMyDate As String
Dim intMonth As Integer
Dim intTemp As Integer

mytextbox.text (has a value of, e.g., "437")

strYear = Left(mytexbox.text, 1) 'yields "2"

Note: No way to discriminate whether 2 is '1992' or '2002'
Assume '2002' always

strYear = "200" & strYear 'yields "2002"

strMonth = Right(437, 2) 'yields string ("37")
intMonth = CInt(strMonth) 'yields integer (37)
intMonth = intMonth - 13 'yields week as integer (24)

strMonth = function(Week no --> string name of month)

Not sure of a specific function but you could use:

intTemp = Month(intMonth*7) 'yields number of days
strMonth = Format(intTemp,"mmmm") 'converts number of days to Month string

strMyDate = strMonth & " " & strYear

...I'm sure there are other ways, just do not have a week no --> "Month" function handy.

 
I'm unclear on what exactly you want to do, but typically time calculations are done with DateTime and TimeSpan objects, which contain methods like .AddDays().
 
Thanks Boulder -- I just threw up some VB - hadn't tested it in an asp.net page -- I think tsp just wants to truncate away the week number, and generate a string date format - seems simple enough.
 
Thanks everyone for your input,I'm going to try this out- It's basically a formula to determine the life of a battery based on a number; but now they want it on a webpage, so that's why it's pretty weird looking!Let me try this out and see if I can get it to work! Thanks for all of your input!I will let you know!

Thanks-
Lisa
 
I'm still stuck on this- The 3 digit number they enter is random, but will always be 3 digits and the first number indicates the year always, if that helps anyone! I'm new to this so I'm having trouble getting started AND I suck in Math!

HELP- Thanks again-
Lisa
 
HTH

Public Function FromCodeNumber(ByVal iCodeNumber As Integer) As String
'Tek-Tips problem
' 237= 2(2002); 37 - 13 = Week 24 of 2002 = June 2002

' Another(one)
'212= 2(2002); 12 - 13 = Week 51 of 2001 = December 2001

'Using a different number:
'437 = 4(2004); 37 – 13 = Week 24 of 2004 = June 2004

Dim dResult As New Date(2000, 1, 1) '1 Jan 2001
'add the correct number of years to it
Dim iYears As Integer = Integer.Parse(iCodeNumber.ToString.Chars(0))
dResult = dResult.AddYears(iYears)
'add the correct number of weeks to it
Dim iWeeks As Integer = Integer.Parse(iCodeNumber.ToString.Substring(1)) - 13
dResult = dResult.AddDays(iWeeks * 7)
'then just return the date
Return MonthName(dResult.Month) & " " & dResult.Year.ToString
End Function

Mark [openup]
 
Thank You!! Where does my TextBox come into play here? The users need to enter the 3 digit number into a textbox, so where does that code go to take the value of what they entered and perform the calculation you supplied??? I'm sorry if this sounds stupid, I'm new to this and appreciate the help; I definitely have learned alot from this forum-

Thank You,
Lisa
 
Hi
iCodeNumber is the number passed to the function. It is the only information the function needs to work out the return value. In the original examples if the function were called, iCodeNumber would be 237, 212 or 437 respectively

237= 2(2002); 37 - 13 = Week 24 of 2002 = June 2002

Another one:
212= 2(2002); 12 - 13 = Week 51 of 2001 = December 2001

Using a different number:
437 = 4(2004); 37 – 13 = Week 24 of 2004 = June 2004

Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top