Understanding VBScript
I have a VBScript that I`m converting to PHP, I hae some part that I don`t understand and don`t know the output of ... Also if possible, provide me with a similar method in HTML/PHP
TextBox1.Value = 1#
txtTurnoverIncl = TextBox1
Format(CDbl(txtTurnoverExcl.Text) * _
CDbl(txtRoyalty.Text) / 100, "#,##0.00")
If txtTurnoverExcl.Text <> "" Then
Format(Round(.Text * 14 / 114, 2), "#,##0.00")
TextBox1 = Now()
TextBox3 = Date
TextBox4 = Format(MyDate, "dddd")
And this function:
Private Function SumCashUp() As Double
Dim i As Long
Dim tmp As Double
For i = 10 To 12
With Me.Controls("TextBox" & i)
If IsNumeric(.Text) Then
tmp = tmp + CDbl(.Text)
End If
End With
Next i
SumCashUp = tmp
E开发者_如何学运维nd Function
I guess thats all.
TextBox1.Value = 1#
- Assign the value 1 in format Double to the textbox control. (thanks MikeD)txtTurnoverIncl = TextBox1
- Assigning reference to the controlTextBox
to variable calledtxtTurnoverIncl
CDbl(txtTurnoverExcl.Text)
- Convert the text inside the textboxtxtTurnoverExcl
to double i.e. numeric value with decimal point e.g. 2.6 - this is useful if you want to perform mathematical operations on the value for example.Format(..., "#,##0.00")
- Format number to look like this:2.60
or8.25
i.e. with two digits after decimal point.Round(.Text * 14 / 114, 2)
- The.Text
means you're insideWith (somecontrol)
block, so it's actuallysomecontrol.Text
i.e. taking the Text of the control. Round function will round the number for exampleRound(662.791, 2)
will return662.79
andRound(662.796, 2)
will return662.8
Now()
- Returns the current date and time on the machine where the code is executingDate
orDate()
- Like Now() but only with the date, time will be 00:00:00Format(MyDate, "dddd")
- Get name of the day of week of MyDate, according to the Culture on the machine. For example for Hebrew culture it will returnיום שלישי
for English culture it will returnTuesday
. In general, Format() given date and string will Format the date according to the string e.g.Format(Now(), "dd/MM/yyyy")
will return14/12/2010
The last function returns the sum of the values of the textboxes named "Textbox10", "Textbox11", and "Textbox12" in a pretty complicated way. I guess in PHP you would do something like this (assuming you are POSTing a form):
function sumCashUp() {
return (double) $_POST['Textbox10'] + (double) $_POST['Textbox11'] + (double) $_POST['Textbox12'];
}
first of all it would be better to analyze what the whole thing is doing (semantically) rather than looking at sequences of code. So the remainder of this post is a bit speculative ....
There are a couple of textboxes displayed on the screen
TextBox1
... initialized with value 1(double), later containing current time (now()
) (imho a sin in itself - brrrr - hope there is good business logic explanation for this)TextBox3
... initialized with the current dateTextBox4
... initialized with "something we don't know" - hopefully a date (MyDate
), and formated as Weekday ("dddd"
)TextBox10
-TextBox12
... seem to be used to calculate a variableSumCashUp
we have some more variables which may be textboxes as well (as sometimes we see a .Text added in the code)
txtTurnoverIncl
txtTurnoverExcl
txtRoyalty
SumCashUp
and a code fragment that calculates a 14% margin from a Gross (*14/114
), rounds and formats the result ... and we have no clue about where this result is used. We can speculate that it may be another form field (because of .Text
) - maybe txtRoyalty - but we don't know.
Basically all the code fragments are about putting values into textboxes displayed on the screen and/or using the values of that text boxes to compute something (like the SumCashUp or a 14% GM).
So I guess the path to the solution must be
- get the source layout of textboxes
- understand the business logic
- create a HTML page containing a form with similar objects (textboxes, a submit button, etc.)
- write PHP code that implements the business logic - most probably as a reaction to a POST event triggered by a Submit button
You already received a couple of code fragments, but one needs to put this into a greater context, otherwise the code blocks won't help.
精彩评论