Wayne Barron
asked on
ASP Classic - VBScript Math 7 1/8 compare 7 2/8
Hello All;
As the title suggest, I need to compare some numbers.
OK, If VBScript does not work, then JavaScript will be welcomed in this project.
OK.
I need to compare numbers, and show the difference between the 2 sets.
However, they are using the "Date Entered" as well.
So, lets say that the following exist.
NewDate = 1/7/2013
OldDate = 1/2/2013
OldDate 7 2/8
NewDate 7 4/8
Resulting in: Gained: 2/8
Between the 2 figures, there is a 2/8 difference.
Now, if it is like this
OldDate 7 2/8
NewDate 7 1/8
Resulting in: Loss: 1/8
So basically, I need it to be like so.
If NewDate<OldDate then
Loss 1/8 (Have to show the amount that is lost)
elseif NewDate>OldDate then
Gained 2/8 (Once again, have to show the amount that is gained.
End if
I hope that this all makes some since to someone.
I really need this mathematical calculations to work in my project, to really add that user friendly feeling to this site.
Thank you
Carrzkiss
As the title suggest, I need to compare some numbers.
OK, If VBScript does not work, then JavaScript will be welcomed in this project.
OK.
I need to compare numbers, and show the difference between the 2 sets.
However, they are using the "Date Entered" as well.
So, lets say that the following exist.
NewDate = 1/7/2013
OldDate = 1/2/2013
OldDate 7 2/8
NewDate 7 4/8
Resulting in: Gained: 2/8
Between the 2 figures, there is a 2/8 difference.
Now, if it is like this
OldDate 7 2/8
NewDate 7 1/8
Resulting in: Loss: 1/8
So basically, I need it to be like so.
If NewDate<OldDate then
Loss 1/8 (Have to show the amount that is lost)
elseif NewDate>OldDate then
Gained 2/8 (Once again, have to show the amount that is gained.
End if
I hope that this all makes some since to someone.
I really need this mathematical calculations to work in my project, to really add that user friendly feeling to this site.
Thank you
Carrzkiss
Does "7 2/8" represent "7.25" (the fields happen to be named "OldDate" and "NewDate" but are not necessarily dates) or are you using a date format I am unfamiliar with?
I'm lost on how "January 7, 2013" becomes "7.5" (7 4/8), etc.
I'm lost on how "January 7, 2013" becomes "7.5" (7 4/8), etc.
Are you trying to figure out quarters? datediff functions
You can use datediff to get days, weeks, quarters, months etc. Maybe that makes it easier?
You can use datediff to get days, weeks, quarters, months etc. Maybe that makes it easier?
ASKER
No, everyone miss understood me.
I guess that is my fault for not making it clear.
Lets try this again.
The dates, when how to look at the numbers.
The numbers are not in dates.
So.
NewDate = 1/7/2013
OldDate = 1/2/2013
(For measurement)
NewMess 7 4/8
OldMess 7 2/8
OK, lets say that on the date:
OldDate (1/2/2013)
You have the measurement of
OldMess ( 7 2/8 )
And then on the New Date
NewDate (1/7/2013)
You have the measurement of
NewMess ( 7 4/8 )
This would result in the measurement being a Gain of 2/8
I am so, very very sorry, that I did not clarify that these are not dates.
It is just that we have to look at the date that is entered, to see if the numbers are lower or higher than a previous date given.
I guess that is my fault for not making it clear.
Lets try this again.
The dates, when how to look at the numbers.
The numbers are not in dates.
So.
NewDate = 1/7/2013
OldDate = 1/2/2013
(For measurement)
NewMess 7 4/8
OldMess 7 2/8
OK, lets say that on the date:
OldDate (1/2/2013)
You have the measurement of
OldMess ( 7 2/8 )
And then on the New Date
NewDate (1/7/2013)
You have the measurement of
NewMess ( 7 4/8 )
This would result in the measurement being a Gain of 2/8
I am so, very very sorry, that I did not clarify that these are not dates.
It is just that we have to look at the date that is entered, to see if the numbers are lower or higher than a previous date given.
So the page would collect a measurement on a particular date and them another measurement on another date.
It would then show the gain or loss over the period.
That's one question.
Does the page need to use fractions?
If so, the trick would be to do all the calculations and then use the excellent function linked by Padas above to generate a result in fractions.
It would then show the gain or loss over the period.
That's one question.
Does the page need to use fractions?
If so, the trick would be to do all the calculations and then use the excellent function linked by Padas above to generate a result in fractions.
Did the link I posted for converting decimal to fractions help. That sounds like what you need.
Hi carrzkiss,
Are the measurements always in 8th's, and is the 7 constant? So, which of these are valid:
7 4/8
7 1/2
.
24 2/8
24 1/4
1/8
0 1/8
if 1/8th's is the granularity, could we use one function to convert to "grains" and then do the calc, and then another function to convert back to wholes and fractions?
HTH
GH
Are the measurements always in 8th's, and is the 7 constant? So, which of these are valid:
7 4/8
7 1/2
.
24 2/8
24 1/4
1/8
0 1/8
if 1/8th's is the granularity, could we use one function to convert to "grains" and then do the calc, and then another function to convert back to wholes and fractions?
HTH
GH
ASKER
@padas, I will check on what you posted in just a moment, since it is not just for dates.
@GH
No, it is going to be different measurements.
Examples:
5 1/8
6 1/2
8 7/8
4 2/8
And so on.
It is going to be on the measurement scale of the 1/8 - 7/8
And when it is half, then it will be 1/2.
Carrzkiss
@GH
No, it is going to be different measurements.
Examples:
5 1/8
6 1/2
8 7/8
4 2/8
And so on.
It is going to be on the measurement scale of the 1/8 - 7/8
And when it is half, then it will be 1/2.
Carrzkiss
ASKER
@padas.
If I use the conversion tool, to convert, how would I then compare the 2 sets of numbers?
If I use the conversion tool, to convert, how would I then compare the 2 sets of numbers?
Hi!
I have hacked up a demo of how to use the Calendar control to collect two measurements on different dates and then do the appropriate calculations.
It uses the decimal to Fractions function as linked by padas. :-)
Save it in a file with the extension .HTA.
It will be recognised as a "Hypertext Application" and executes without any server.
The code and HTML are very similar to ASP pages.
There is very little error chacking so please enter non zero numbers for the denominators! :-)
TRM
I have hacked up a demo of how to use the Calendar control to collect two measurements on different dates and then do the appropriate calculations.
It uses the decimal to Fractions function as linked by padas. :-)
Save it in a file with the extension .HTA.
It will be recognised as a "Hypertext Application" and executes without any server.
The code and HTML are very similar to ASP pages.
There is very little error chacking so please enter non zero numbers for the denominators! :-)
<HTML xmlns:IE>
<HEAD>
<TITLE>Calendar Demonstration</TITLE>
<HTA:APPLICATION
APPLICATIONNAME="Calendar Demo"
ID="CalendarDemo"
ICON="clock.ico"/>
<STYLE>
@media all
{
IE\:Calendar { behavior : url(calendar.htc) }
}
</STYLE>
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Dim dtmDateOne,dtmDateTwo
Dim fltMeasOne,fltMeasTwo
Dim strGainLoss,fltDif
Sub Calendar_OnPropertyChange( )
Dim strDate
strDate = DateSerial(Calendar.Year,Calendar.Month,Calendar.Day)
myLongDate.Value = FormatDateTime( strDate, vbLongDate )
End Sub
Sub TodayButton_OnClick( )
Calendar.Year = Year(Now )
Calendar.Month = Month(Now)
Calendar.Day = Day(Now)
End Sub
Sub Window_OnLoad( )
' Set some of the calendar control's properties
Calendar.DayLength = "short" 'short or long
Calendar.MonthLength = "long" 'short or long
Calendar.ShowDateSelectors = 1
Calendar.ShowDays = 1
Calendar.ShowTitle = 1
' Fill in the date fields below the calendar control
Calendar_OnPropertyChange( )
End Sub
Sub OnClickButtonSelectedDate()
strDate = DateSerial(Calendar.Year,Calendar.Month,Calendar.Day)
MsgBox FormatDateTime(strDate,vbShortDate)
End Sub
Sub OnClickButtonDateOne()
'This method will be called when button "DateOne" is clicked
'Add your code here
dtmDateOne = DateSerial(Calendar.Year,Calendar.Month,Calendar.Day)
Date_One.value=dtmDateOne
End Sub
Sub OnClickButtonDateTwo()
'This method will be called when button "DateTwo" is clicked
'Add your code here
dtmDateTwo = DateSerial(Calendar.Year,Calendar.Month,Calendar.Day)
Date_Two.value=dtmDateTwo
End Sub
Sub OnClickButtonCalculate()
'This method will be called when button "Calculate" is clicked
'Add your code here
message.innerhtml = ""
If dtmDateOne="" Then
message.innerhtml = "Missing date One!"
Exit sub
End If
If dtmDateTwo="" Then
message.innerhtml = "Missing date Two!"
Exit sub
End If
If dtmDateOne=dtmDateTwo Then
message.innerhtml = "The dates are the same!"
Exit sub
End If
fltMeasOne=Meas_One_Whole.value + (Meas_One_Numerator.value / Meas_One_Denominator.value)
fltMeasTwo=Meas_Two_Whole.value + (Meas_Two_Numerator.value / Meas_Two_Denominator.value)
message.innerhtml=dtmDateOne &" "& fltMeasOne &"<BR>" & dtmDateTwo &" "& fltMeasTwo
If dtmDateOne < dtmDateTwo Then
'date of first measurement is before date of second
If fltMeasOne < fltMeasTwo Then
'second measurement is higher
strGainLoss= "Gain"
fltDif = fltMeasTwo - fltMeasOne
Else
'second mesurement is lower
strGainLoss= "Loss"
fltDif = fltMeasOne - fltMeasTwo
End If
Else
'second date is before first date
If fltMeasOne < fltMeasTwo Then
strGainLoss= "Loss"
fltDif = fltMeasTwo - fltMeasOne
Else
strGainLoss= "Gain"
fltDif = fltMeasOne - fltMeasTwo
End If
End If
bigresult.value= strGainLoss & vbTab & DecimalToFraction(fltDif,True)
End Sub
Function DecimalToFraction(dec, mixed)
'Decimal -> Fraction Conversion vbScript Function
'9/20/02, Jamie Begin (jjbegin@infiniteblue.biz)
'[Adapted from an algorithm by John Kennedy (rkennedy@ix.netcom.com)]
'
'Input parameter(s):
' dec [single] The decimal value to be converted to a fraction.
' mixed [boolean]
' True = Return a mixed number if dec > 1
' False = Return an improper fraction if dec > 1
' ex.: 3.25 equals "13/4" as an improper fraction and "3 1/4" as a mixed number.
Dim ds, fn, fd, pd, tmp, acc, oi
ds = 1
If (dec < 0) Then ds = -1
dec = abs(dec)
If mixed Then
oi = cstr(int(dec))
dec = (dec - oi)
End If
If dec = int(dec) Then
fn = (dec * ds)
fd = 1
Else
z = dec : pd = 0 : fd = 1 : acc = .5
Do
acc = (acc * 0.1)
Do
z = 1 / (z - int(z))
tmp = fd
fd = fd * int(z) + pd
pd = tmp
fn = int(dec * fd + 0.5)
Loop Until (abs((dec - (fn / fd))) < acc) or (z = int(z))
fn = (ds * fn)
Loop While Not (fn/fd) = csng(dec)
End If
If mixed Then
DecimalToFraction = oi & " " & cstr(fn) & "/" & cstr(fd)
Else
DecimalToFraction = cstr(fn) & "/" & cstr(fd)
End If
End Function
</SCRIPT>
<BODY>
<IE:Calendar id="Calendar" style="width : 250; height : 250; border : 1px solid black;"></IE:Calendar>
<BR>
Selected Date:<INPUT ID="myLongDate" TYPE="text" SIZE="32" READONLY>
<BR>
<INPUT ID="TodayButton" TYPE="button" VALUE="Today">
<BR>
Select a data on the calendar and enter the whole , numerator and denominator of the first measurement you wish to record
<BR>
<textarea name="Date_One" id="Date_One" rows="1" cols="32"></textarea>
Whole <textarea name="Meas_One_Whole" id="Meas_One_Whole" rows="1" cols="4"></textarea>
Numerator <textarea name="Meas_One_Numerator" id="Meas_One_Numerator" rows="1" cols="4"></textarea>/
Denominator<textarea name="Meas_One_Denominator" id="Meas_One_Denominator" rows="1" cols="4"></textarea>
<input type="button" name="DateOne" id="DateOne" value="Measurement one" onclick="OnClickButtonDateOne">
<BR>
Select a data on the calendar and enter the whole , numerator and denominator of the Second measurement you wish to record
<BR>
<BR>
<textarea name="Date_Two" id="Date_Two" rows="1" cols="32"></textarea>
Whole <textarea name="Meas_Two_Whole" id="Meas_Two_Whole" rows="1" cols="4"></textarea>
Numerator <textarea name="Meas_Two_Numerator" id="Meas_Two_Numerator" rows="1" cols="4"></textarea>/
Denominator<textarea name="Meas_Two_Denominator" id="Meas_Two_Denominator" rows="1" cols="4"></textarea>
<input type="button" name="DateTwo" id="DateTwo" value="Measurement Two" onclick="OnClickButtonDateTwo">
<BR>
<input type="button" name="Calculate" id="Calculate" value="Calculate" onclick="OnClickButtonCalculate">
<br>
<textarea name="BigResult" id="BigResult" rows="1" cols="40"></textarea>
<BR>
<span name="message" id="message"></span>
<BR>
<a href="http://msdn.microsoft.com/en-us/library/ms531943(VS.85).aspx">Reference</a>
<BR><BR>
Edit the <i>calendar.htc</i> file in Notepad to set the days and months names in your local language.
</BODY>
</HTML>
TRM
Do your math first. Then you end up with something like 2.25. Then just run it as a function.
<%
x=2.25
y=DecimalToFraction(x, 1) ' will return 2 1/4
z=DecimalToFraction(x, 0) ' will return 10/4
%>
<%
x=2.25
y=DecimalToFraction(x, 1) ' will return 2 1/4
z=DecimalToFraction(x, 0) ' will return 10/4
%>
Function DecimalToFraction(dec, mixed)
'Decimal -> Fraction Conversion vbScript Function
'9/20/02, Jamie Begin (jjbegin@infiniteblue.biz)
'[Adapted from an algorithm by John Kennedy (rkennedy@ix.netcom.com)]
'
'Input parameter(s):
' dec [single] The decimal value to be converted to a fraction.
' mixed [boolean]
' True = Return a mixed number if dec > 1
' False = Return an improper fraction if dec > 1
' ex.: 3.25 equals "13/4" as an improper fraction and "3 1/4" as a mixed number.
Dim ds, fn, fd, pd, tmp, acc, oi
ds = 1
If (dec < 0) Then ds = -1
dec = abs(dec)
If mixed Then
oi = cstr(int(dec))
dec = (dec - oi)
End If
If dec = int(dec) Then
fn = (dec * ds)
fd = 1
Else
z = dec : pd = 0 : fd = 1 : acc = .5
Do
acc = (acc * 0.1)
Do
z = 1 / (z - int(z))
tmp = fd
fd = fd * int(z) + pd
pd = tmp
fn = int(dec * fd + 0.5)
Loop Until (abs((dec - (fn / fd))) < acc) or (z = int(z))
fn = (ds * fn)
Loop While Not (fn/fd) = csng(dec)
End If
If mixed Then
DecimalToFraction = oi & " " & cstr(fn) & "/" & cstr(fd)
Else
DecimalToFraction = cstr(fn) & "/" & cstr(fd)
End If
End Function
I tried the code I pasted up but it does not work for some reason. :-(
This is teh file re-named to .txt
TRM
ee-test-gainloss.txt
This is teh file re-named to .txt
TRM
ee-test-gainloss.txt
Just being picky...
It looks like you'll need to do a little post-DecimalToFraction-pro cessing to change
"2 1/4"
into
"2 2/8"
Something along the lines of locating any " " and, of course, then the "/" to find the numerator and denominator so you can convert the fraction into 8ths.
Maybe I'm way over thinking it now... are they allowed to enter different fractions? like thirds and quarters? or is everything always in eighths?
It looks like you'll need to do a little post-DecimalToFraction-pro
"2 1/4"
into
"2 2/8"
Something along the lines of locating any " " and, of course, then the "/" to find the numerator and denominator so you can convert the fraction into 8ths.
Maybe I'm way over thinking it now... are they allowed to enter different fractions? like thirds and quarters? or is everything always in eighths?
ASKER
nap0leon
You bring up a really good point.
However, There will be specific instructions, to let the members know, that they can only put in numbers, that are on the tape.
Which is in 1/8
(I DID not mean to write up 1/2 above in my previous posting, it will all be done in 1/8-7/8)
So, what I would need to do, I would think, would be to error check, to make sure that all numbers end in /8
So, everything should be: Example 7 1/8 (or) 22 5/8
And so on.
I will check on the codes provided and will post back.
You bring up a really good point.
However, There will be specific instructions, to let the members know, that they can only put in numbers, that are on the tape.
Which is in 1/8
(I DID not mean to write up 1/2 above in my previous posting, it will all be done in 1/8-7/8)
So, what I would need to do, I would think, would be to error check, to make sure that all numbers end in /8
So, everything should be: Example 7 1/8 (or) 22 5/8
And so on.
I will check on the codes provided and will post back.
ASKER
@Tardisrepairman
I am not really sure what to do with your code.
@padas
The numbers are already listed as Fraction's
7 1/8
So the only thing that I need to do, is to compare the 2 dated Numbers sequences.
I am not really sure what to do with your code.
@padas
The numbers are already listed as Fraction's
7 1/8
So the only thing that I need to do, is to compare the 2 dated Numbers sequences.
how to alter "DeceimalToFractions" to force it to output 8ths:
original line commented out
replace with "fd=8"
original line commented out
replace with "fd=8"
fd = 8
'fd = fd * int(z) + pd
Hi !
Please print out and burn the earlier code. ;-)
This short section shows the logic for the dates and values to show gain or loss.
Please print out and burn the earlier code. ;-)
This short section shows the logic for the dates and values to show gain or loss.
dtmDateOne = DateSerial(2013,1,4)
intWholeone = 1
intNumeratorOne = 3
intDenominoatorOne = 8
fltMeasOne = intWholeone + (intNumeratorOne / intDenominoatorOne)
WScript.Echo dtmDateOne & vbTab & fltMeasOne
dtmDateTwo = DateSerial(2013,1,5)
intWholeTwo = 3
intNumeratorTwo = 4
intDenominoatorTwo = 8
fltMeasTwo = intWholeTwo + (intNumeratorTwo / intDenominoatorTwo)
WScript.Echo dtmDateTwo & vbTab & fltMeasTwo
If dtmDateOne < dtmDateTwo Then
'date of first measurement is before date of second
If fltMeasOne < fltMeasTwo Then
'second measurement is higher
strGainLoss= "Gain"
fltDif = fltMeasTwo - fltMeasOne
Else
'second mesurement is lower
strGainLoss= "Loss"
fltDif = fltMeasOne - fltMeasTwo
End If
Else
'second date is before first date
If fltMeasOne < fltMeasTwo Then
strGainLoss= "Loss"
fltDif = fltMeasTwo - fltMeasOne
Else
strGainLoss= "Gain"
fltDif = fltMeasOne - fltMeasTwo
End If
End If
WScript.Echo strGainLoss & vbTab & DecimalToFraction(fltDif , true)
Function DecimalToFraction(dec, mixed)
'Decimal -> Fraction Conversion vbScript Function
'9/20/02, Jamie Begin (jjbegin@infiniteblue.biz)
'[Adapted from an algorithm by John Kennedy (rkennedy@ix.netcom.com)]
'
'Input parameter(s):
' dec [single] The decimal value to be converted to a fraction.
' mixed [boolean]
' True = Return a mixed number if dec > 1
' False = Return an improper fraction if dec > 1
' ex.: 3.25 equals "13/4" as an improper fraction and "3 1/4" as a mixed number.
Dim ds, fn, fd, pd, tmp, acc, oi
ds = 1
If (dec < 0) Then ds = -1
dec = abs(dec)
If mixed Then
oi = cstr(int(dec))
dec = (dec - oi)
End If
If dec = int(dec) Then
fn = (dec * ds)
fd = 1
Else
z = dec : pd = 0 : fd = 1 : acc = .5
Do
acc = (acc * 0.1)
Do
z = 1 / (z - int(z))
tmp = fd
fd = fd * int(z) + pd
pd = tmp
fn = int(dec * fd + 0.5)
Loop Until (abs((dec - (fn / fd))) < acc) or (z = int(z))
fn = (ds * fn)
Loop While Not (fn/fd) = csng(dec)
End If
If mixed Then
DecimalToFraction = oi & " " & cstr(fn) & "/" & cstr(fd)
Else
DecimalToFraction = cstr(fn) & "/" & cstr(fd)
End If
End Function
You could limit the selections by using a listbox.
Sub OnChangeSelectEighths()
MsgBox Eighths.value
'This method will be called when select "Eights" is changed
'Add your code here
End Sub
</script>
<body bgcolor="white">
<!--Add your controls here-->
<select name="Eighths" id="Eighths" size=1 onchange="OnChangeSelectEighths">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
I would keep all numbers you are processing as decimal and use the fraction only for display. That will be the easy route.
If you are numbers in a drop down for instance, use the function to display 1.25 as 1 1/4 but when it gets posted to the db or form processing page, it gets posted as 1.25. Any other way you are just doing too much work.
If you are numbers in a drop down for instance, use the function to display 1.25 as 1 1/4 but when it gets posted to the db or form processing page, it gets posted as 1.25. Any other way you are just doing too much work.
ASKER
@padas.
That makes a lot of sense.
OK, How would I write out all the fractions?
1/8
2/8
3/8
4/8
5/8
6/8
7/8
(8 is the next number, so that is not included)
@Tardisrepairman
Using the selection box, that never dawned on me, to use it.
Great idea... Good Suggestion on that one.
Also, to your last code, if you can make up an actual working page, that would be great.
As I have no clue on how to use your code.
That makes a lot of sense.
OK, How would I write out all the fractions?
1/8
2/8
3/8
4/8
5/8
6/8
7/8
(8 is the next number, so that is not included)
@Tardisrepairman
Using the selection box, that never dawned on me, to use it.
Great idea... Good Suggestion on that one.
Also, to your last code, if you can make up an actual working page, that would be great.
As I have no clue on how to use your code.
ASKER
What I was thinking about doing, (Please let me know rather this would be a good idea or not)
have 2 drop list.
1 = Whole number
1 = 8
So, you select from the
Whole Number = 7
From the 8 = 2/8
Then when inserted into the database, it will insert as 7 2/8 (or) the Decimal value of the number.
This sounds like a cool way to do it.
It will make it simplified for the user.
-----
Now, about the compare of the 2 numbers.
have 2 drop list.
1 = Whole number
1 = 8
So, you select from the
Whole Number = 7
From the 8 = 2/8
Then when inserted into the database, it will insert as 7 2/8 (or) the Decimal value of the number.
This sounds like a cool way to do it.
It will make it simplified for the user.
-----
Now, about the compare of the 2 numbers.
Keep it simple!! Keep all data in decimal. And convert it only for display
Input form field
Input form field
<label>Pick your stuff</label>
<select name="numbers">
<%
for each x in MyData
' x might = 4.5 so in fraction would be 4 1/2
' if the number needs to be in another denomination like 4 4/8 we can adjust the function
%>
<option value="<%=x%>"><%=DecimalToFraction(x, 1) %></option>
<%
next
%>
</select>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim f
Set f=Server.CreateObject("Scripting.Dictionary")
f.add .0, ""
f.add .125, "1/8"
f.add .25, "2/8"
f.add .375, "3/8"
f.add .5, "4/8"
f.add .625, "5/8"
f.add .75, "6/8"
f.add .875, "7/8"
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<select name="measures">
<%
MinNum=1
MaxNum=50
for theNums=MinNum to MaxNum
for each x in f
'response.write theNums &" "& f.item(x)
response.write "<option value="""&theNums+x&""">"&theNums &" "& f.item(x)&"</option>"
next
next
%>
</select>
</body>
</html>
A drop down for the whole numbers would limit you to the number of options in the list but if the measurements are coming from a tape measure that may not be a problem. :-)
VBScript stores date and time as serial numbers (same as excel) so you can check if one is before the other with a simple compare.
You would have date1, measurement1 and date2,measurement2
to get the result you want, you would use three "IF" statements. nested together.
If date1 < date2 then
' this means the first date is before the second date
if measurement 1 < measurement 2 then
'this means that measurement less than measurement 2
'if the measurement is larger later, then there is a gain!
strLossGain="Gain"
measurementDifference=meas urement2-m easurement 1
' we have already found that measurement2 is larger than measurement1 so
' measurement2-measurement1 will be positive.
else
'if measurement1 is NOT less than measurement 2 then there is a loss
strLossGain = "Loss"
measurementDifference=meas urement1-m easurement 2
' in this case measurement1 is larger than measurement2 so
' measurement1-measurement2 will be positive.
end if
else
' this means the first date is After the second date
if measurement1 < measurement2 then
'this means that measurement1 is less than measurement 2
'if the measurement is smaller later, then there is a loss!
strLossGain="Loss"
measurementDifference=meas urement2-m easurement 1
' we have already found that measurement2 is larger than measurement1 so
' measurement2-measurement1 will be positive.
else
'if measurement1 is more than earlier measurement 2 then there is a Gain!
strLossGain = "Gain"
measurementDifference=meas urement1-m easurement 2
' in this case measurement1 is larger than measurement2 so
' measurement1-measurement2 will be positive.
end if
end if
This works out the gain/loss and also returns the difference in measurement.
VBScript stores date and time as serial numbers (same as excel) so you can check if one is before the other with a simple compare.
You would have date1, measurement1 and date2,measurement2
to get the result you want, you would use three "IF" statements. nested together.
If date1 < date2 then
' this means the first date is before the second date
if measurement 1 < measurement 2 then
'this means that measurement less than measurement 2
'if the measurement is larger later, then there is a gain!
strLossGain="Gain"
measurementDifference=meas
' we have already found that measurement2 is larger than measurement1 so
' measurement2-measurement1 will be positive.
else
'if measurement1 is NOT less than measurement 2 then there is a loss
strLossGain = "Loss"
measurementDifference=meas
' in this case measurement1 is larger than measurement2 so
' measurement1-measurement2 will be positive.
end if
else
' this means the first date is After the second date
if measurement1 < measurement2 then
'this means that measurement1 is less than measurement 2
'if the measurement is smaller later, then there is a loss!
strLossGain="Loss"
measurementDifference=meas
' we have already found that measurement2 is larger than measurement1 so
' measurement2-measurement1 will be positive.
else
'if measurement1 is more than earlier measurement 2 then there is a Gain!
strLossGain = "Gain"
measurementDifference=meas
' in this case measurement1 is larger than measurement2 so
' measurement1-measurement2 will be positive.
end if
end if
This works out the gain/loss and also returns the difference in measurement.
ASKER
@Padas
That is pretty sweet, different from what I was going to do, however, better.
There is still the issue of comparing the 2 values together, to get the sum of the difference rather minus or plus.
That is pretty sweet, different from what I was going to do, however, better.
There is still the issue of comparing the 2 values together, to get the sum of the difference rather minus or plus.
Hi!
to try the html bits of the page you could copy this code to
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_submit
to try the html bits of the page you could copy this code to
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_submit
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp">
First measurement: <input type="date" name="DateOne" >
Units: <input type="number" name="M1Units" min="1" max="20">
Eighths: <input type="number" name="M1Eighths" min="1" max="7">
<br>
First measurement: <input type="date" name="DateTwo" >
Units: <input type="number" name="M2Units" min="1" max="20">
Eighths: <input type="number" name="M2Eighths" min="1" max="7">
<input type="submit" value="Submit">
</form>
<p>Click the "Submit" button and the form-data will be sent to a page on the server called "demo_form.asp".</p>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Tardisrepairman
Thanks for the added information, I will look into what you have provided.
However, on your last post. Http:38765404
I do not really know how to take that one, some people may take offense to it, if they already know hot to process a form.
So, I would really love to hear your reason as to why you posted it for.
@padas
Going to try your code out now.
Thanks for the added information, I will look into what you have provided.
However, on your last post. Http:38765404
I do not really know how to take that one, some people may take offense to it, if they already know hot to process a form.
So, I would really love to hear your reason as to why you posted it for.
@padas
Going to try your code out now.
ASKER
Love it Padas.
Let me run through the code, and make sure that I understand everything, and I will get back with you later on this evening or tomorrow sometime.
You Rock, as Always.
Carrzkiss
Let me run through the code, and make sure that I understand everything, and I will get back with you later on this evening or tomorrow sometime.
You Rock, as Always.
Carrzkiss
ASKER
One thing I just noticed.
OK, you start out with
5 1/8
You choose
9 1/8
Your result is -4
It should be 4
However, if your choose
1 1/8
Your result is: 4
And should be: -4
Were would we need to make this change at?
OK, you start out with
5 1/8
You choose
9 1/8
Your result is -4
It should be 4
However, if your choose
1 1/8
Your result is: 4
And should be: -4
Were would we need to make this change at?
Thanks.
In this area
OldNumber=5.125
OldNumberFrac=MakeFraction (OldNumber )
NewNumber=request.form("me asures")
NewNumberFrac=MakeFraction (NewNumber )
Difference=cdbl(OldNumber) -cdbl(NewN umber)
DifferenceFrac=MakeFractio n(Differen ce)
change
Difference=cdbl(OldNumber) -cdbl(NewN umber)
to
Difference=cdbl(NewNumber) -cdbl(OldN umber)
In this area
OldNumber=5.125
OldNumberFrac=MakeFraction
NewNumber=request.form("me
NewNumberFrac=MakeFraction
Difference=cdbl(OldNumber)
DifferenceFrac=MakeFractio
change
Difference=cdbl(OldNumber)
to
Difference=cdbl(NewNumber)
ASKER
Better.
Will get back with you later on Padas.
Have a rockin evening!
Will get back with you later on Padas.
Have a rockin evening!
ASKER
I seem to have run into a problem, and not really sure as to the cause.
OK, I have 13 total drop menus
So, I created 13 files with the same code in them.
However, each one has a different Library record.
Set f=Server.CreateObject("Scr ipting.Dic tionary")
Set t=Server.CreateObject("Scr ipting.Dic tionary")
exc....
Now, the code breaks on this line here.
MakeFraction= theInt&" "&t.item(theFrac)
With the following error.
Object Required: 't'
So, what can I do to get passed this issue?
All files are different in this case, each showing the same line, with the same error, just corresponding to the library name that is given in each file.
NOW, if you know of a better way to do this, please by all means, let me know.
right now, I have (As stated above), created 13 files, and each file has its own Library name, and <input name=""> as well.
Carrzkiss
OK, I have 13 total drop menus
So, I created 13 files with the same code in them.
However, each one has a different Library record.
Set f=Server.CreateObject("Scr
Set t=Server.CreateObject("Scr
exc....
Now, the code breaks on this line here.
MakeFraction= theInt&" "&t.item(theFrac)
With the following error.
Object Required: 't'
So, what can I do to get passed this issue?
All files are different in this case, each showing the same line, with the same error, just corresponding to the library name that is given in each file.
NOW, if you know of a better way to do this, please by all means, let me know.
right now, I have (As stated above), created 13 files, and each file has its own Library name, and <input name=""> as well.
Carrzkiss
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Damn, I knew there was a better way of doing it.
Sometimes I will do something, and then I sit back for a moment, and think.
Hold it, there is a better way of doing this.
In this case, I was just eating brunch, and was thinking about a way to do this, and I come in, to your coding here.
Sometimes it helps to have someone else to look at what is right or possible wrong, to get the best results out of your work.
Thanks once again Padas.
will get back with you after I test it out.
Sometimes I will do something, and then I sit back for a moment, and think.
Hold it, there is a better way of doing this.
In this case, I was just eating brunch, and was thinking about a way to do this, and I come in, to your coding here.
Sometimes it helps to have someone else to look at what is right or possible wrong, to get the best results out of your work.
Thanks once again Padas.
will get back with you after I test it out.
ASKER
I think we can close this one out now.
Thanks once again Padas, for your assistance, and your rise to the project.
you are a great teacher, and are wonderful at what you do.
I hope and wish the very best for you in your future work and endeavors.
Carrzkiss
Thanks once again Padas, for your assistance, and your rise to the project.
you are a great teacher, and are wonderful at what you do.
I hope and wish the very best for you in your future work and endeavors.
Carrzkiss
Thank you for the kind words!
I think sometimes it is easy to get caught up in trying to figure things out out the way we first thought it should be and the harder it gets, the more we want to figure out the puzzle that way without regards to alternatives. I know for myself as soon as things start getting complex it's time to stop and figure out the easy way.
I think sometimes it is easy to get caught up in trying to figure things out out the way we first thought it should be and the harder it gets, the more we want to figure out the puzzle that way without regards to alternatives. I know for myself as soon as things start getting complex it's time to stop and figure out the easy way.
ASKER
Correct.
Usually, when I get caught into a situation that I cannot find a way around, I will usually step back, play my guitar, go for a walk, watch some TV, or something.
And it is usually when you least expect it, the idea comes in your head.
I try to keep paper and pencil with me all the time, so I can jot down notes, so when I do figure out my issues, I will NOT forget them.
Going to the gym with my son.
Have a good one Padas, and continue doing what you do.
Also, do you have a website? Would love to check out your work.
If you do not want to post it here, you can send it to my email, listed in my profile.
Later.
Carrzkiss
Usually, when I get caught into a situation that I cannot find a way around, I will usually step back, play my guitar, go for a walk, watch some TV, or something.
And it is usually when you least expect it, the idea comes in your head.
I try to keep paper and pencil with me all the time, so I can jot down notes, so when I do figure out my issues, I will NOT forget them.
Going to the gym with my son.
Have a good one Padas, and continue doing what you do.
Also, do you have a website? Would love to check out your work.
If you do not want to post it here, you can send it to my email, listed in my profile.
Later.
Carrzkiss
ASKER
Padas
I have run into a possible issue with the code (I think)
If you change the set number to: 13.625 (13 5/8)
Then you enter (13 4/8)
It gives this as answer: -1 7/8
Would this not be: - 1/8
Or am I missing something?
However, if you choose: 13 6/8 from the list
Then the given value is: 1/8
Like it should be.
I have run into a possible issue with the code (I think)
If you change the set number to: 13.625 (13 5/8)
Then you enter (13 4/8)
It gives this as answer: -1 7/8
Would this not be: - 1/8
Or am I missing something?
However, if you choose: 13 6/8 from the list
Then the given value is: 1/8
Like it should be.
New Math. Like the carpenter's basement, I don't have a site. Been too busy. This year though!
Update the function
Update the function
function MakeFraction(n)
theInt=fix(n)
theFrac=n-theInt
'response.write "N = "&n&" theINT "&theInt &" theFrac "&theFrac&"<br>"
if theInt<>0 then
MakeFraction= theInt&" "&f.item(abs(theFrac))
else
if theFrac<>0 then
MakeFraction= f.item(abs(theFrac))
if n<0 then
MakeFraction="-"&MakeFraction
end if
else
MakeFraction="0" 'everythign is zero
end if
end if
end function
Here is full revised with checking figures after post.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim f
Set f=Server.CreateObject("Scripting.Dictionary")
f.add .0, ""
f.add .125, "1/8"
f.add .25, "2/8"
f.add .375, "3/8"
f.add .5, "4/8"
f.add .625, "5/8"
f.add .75, "6/8"
f.add .875, "7/8"
%>
<%
function MakeFraction(n)
theInt=fix(n)
theFrac=n-theInt
response.write "N = "&n&" theINT "&theInt &" theFrac "&theFrac&"<br>"
if theInt<>0 then
MakeFraction= theInt&" "&f.item(abs(theFrac))
else
if theFrac<>0 then
MakeFraction= f.item(abs(theFrac))
if n<0 then
MakeFraction="-"&MakeFraction
end if
else
MakeFraction="0" 'everythign is zero
end if
end if
end function
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<%
OldNumber=13.625
OldNumberFrac=MakeFraction(OldNumber)
NewNumber=request.form("measures")
NewNumberFrac=MakeFraction(NewNumber)
Difference=cdbl(NewNumber)-cdbl(OldNumber)
DifferenceFrac=MakeFraction(Difference)
response.write "DIF "&Difference
%>
<h2> The old number is <%=OldNumberFrac%>. The number you chose is
<%
if request.form("measures")<>"" then
response.write NewNumberFrac&". The difference is "&DifferenceFrac
else
response.write "No Number"
end if
%>
</h2>
<form method="post">
<select name="measures">
<%
MinNum=1
MaxNum=50
for theNums=MinNum to MaxNum
for each x in f
'response.write theNums &" "& f.item(x)
response.write "<option value="""&theNums+x&""">"&theNums &" "& f.item(x)&"</option>"
next
next
%>
</select>
<input name="Submit" type="submit" value="Submit">
</form>
</body>
</html>
ASKER
Wonderful!!!!
Hopefully this year you will be able to get a site up and running.
For me, it is an expression of one self. Especially if people really enjoy what I have done.
Had a great sleep, now time to get to work.
Take Care Padas.
Carrzkiss
Hopefully this year you will be able to get a site up and running.
For me, it is an expression of one self. Especially if people really enjoy what I have done.
Had a great sleep, now time to get to work.
Take Care Padas.
Carrzkiss
ASKER
An update, for anyone that ever wants to use this code for anything.
To show Loss and Gain, replace a portion of the math.
Thanks once again Padas.
You ROCK!!!!
Carrzkiss
To show Loss and Gain, replace a portion of the math.
if n<0 then
MakeFraction="Loss -"&MakeFraction
elseif n>0 then
MakeFraction="Gain -"&MakeFraction
end if
Thanks once again Padas.
You ROCK!!!!
Carrzkiss
In vbs you would simply use
Open in new window
I think I am missing something in your question. I don't understand the fractions with dates?