pomoc w budowie kalkulatora

Odpowiedz Nowy wątek
2011-07-26 00:25
0

Witam,
Na początku chciałem się przywitać ponieważ jestem nowym użytkownikiem Waszego forum, więc - witam :)

Mam problem z pewnym kalkulatorem napisanym (chyba) w javie więc prosił o udzielenie pomocy. Nie znam się na programowaniu, mniej więcej się oriętuje tylko i nie wszystko rozumie z kodu.
A więc do rzeczy:
Na stronie http://www.syncnotcher.com/calc/index.html jest pewien kalkulator który chcę przerobić na wersje excelową. Póki co udało mi się "wyciągnąc" z tej strony taki kod:

</script><script type="text/javascript">
 
// This function is called from the onSubmit action of the form
function calculate(parentForm) {
 
    // Only calculate output if the input is valid
    if (!valid(parentForm)) {
        return
    }
 
    // Get input values from the form, referencing form elements by name
    var lengthBetweenInput   = parentForm.lengthBetween.value
    var outsideDiameterInput = parentForm.outsideDiameter.value
    var wallThicknessInput   = parentForm.wallThickness.value
    var angleOfCutAInput     = parentForm.angleOfCutA.value
    var angleOfCutBInput     = parentForm.angleOfCutB.value
 
    // Convert inputs into numbers for calculation
    var lengthBetween   = parseFloat(lengthBetweenInput)
        lengthBetween   = Math.abs(lengthBetween) // Get the absolute value, in case someone decided to be cute
    var outsideDiameter = parseFloat(outsideDiameterInput)
    var wallThickness   = parseFloat(wallThicknessInput)
    var angleOfCutA     = parseInt(angleOfCutAInput)
    var angleOfCutB     = parseInt(angleOfCutBInput)
 
    // Do the calculation, creating temporary variables as needed
    var radius = outsideDiameter / 2
    var notSureWhatThisIs = 1-((1/radius) * wallThickness)
    var asin = Math.asin(notSureWhatThisIs)
    var cos = Math.cos(asin)
    var dividedByMultiplier = cos/(1/radius)
    var setbackMeasurement = radius - dividedByMultiplier
    var setbackMetric = setbackMeasurement * 25.4
 
    // Format the output numbers to a fixed number of decimal places
    var setbackMeasurementOutput = setbackMeasurement.toFixed(2)
    var setbackMetricOutput = setbackMetric.toFixed(0)
 
    // Set the values of the output form fields
 
   // Generate the HTML for the tangent table
    // NOTE: There are better ways to generate HTML in Javascript,
    //       but this is the most straight-forward way.
 var tangentTableHTML = '<table border="0" style="font-size: 11pt">' +
        '<tr><th colspan="2"> <img src="procedure/beginnotch.jpg"><br> Begin Notch A at:  &nbsp; Begin Notch B at:</th></tr>' +
        '<tr>' +
        '</tr>'
 
    tangentTableHTML += '<tr>'
 
       // Cut A
 
    var rowValues = calculateTableRow(angleOfCutA, setbackMeasurement, outsideDiameter, wallThickness, radius)
    tangentTableHTML +=  '<td>' + rowValues['entryLength'].toFixed(2)
    lengthBetween = lengthBetween - rowValues['fromEndOfTube']
 
    // Cut B
    rowValues = calculateTableRow(angleOfCutB, setbackMeasurement, outsideDiameter, wallThickness, radius)
    tangentTableHTML +=  '<td>' + rowValues['entryLength'].toFixed(2)
    lengthBetween = lengthBetween - rowValues['fromEndOfTube']
    tangentTableHTML += '</tr>' +
                                        '</table>'
  tangentTableHTML += '<dl><dt><img src="procedure/finalcut3.jpg"><br><b>Overall cut length:</b></dt><dd>' + lengthBetween.toFixed(2) + '</dd></dl>'
 
    // Add the tangent table to the output
    document.getElementById('tangentTableContainer').innerHTML = tangentTableHTML
 
}
 
// Checks input form values to make sure they're all valid
function valid(parentForm) {
 
    // Get input values from the form, referencing form elements by name
    var lengthBetweenInput   = parentForm.lengthBetween.value
    var outsideDiameterInput = parentForm.outsideDiameter.value
    var wallThicknessInput   = parentForm.wallThickness.value
    var angleOfCutAInput     = parentForm.angleOfCutA.value
    var angleOfCutBInput     = parentForm.angleOfCutB.value
 
    // Make sure the user entered *a* value
    if (!lengthBetweenInput) {
        markInvalid(parentForm.lengthBetween)
        alert("Length between X's is required")
        return false
    }
 
    // Make sure the user entered *a* value
    if (!outsideDiameterInput) {
        markInvalid(parentForm.outsideDiameter)
        alert('Outside Diameter is required')
        return false
    } else {
        // Make sure the entered value is within the valid range
        var outsideDiameter = parseFloat(outsideDiameterInput)
        if (isNaN(outsideDiameter) || outsideDiameter < 1.5 || outsideDiameter > 1.5) {
            markInvalid(parentForm.outsideDiameter)
            alert('Demo Version only allows for 1.5 diameter')
            return false
        } else {
            // This field is valid
            markValid(parentForm.outsideDiameter)
        }
    }
 
    // Make sure the user entered *a* value
    if (!wallThicknessInput) {
        markInvalid(parentForm.wallThickness)
        alert('Wall Thickness is required')
        return false
    } else {
        // Make sure the entered value is within the valid range
        var wallThickness = parseFloat(wallThicknessInput)
        if (isNaN(wallThickness) || wallThickness < 0.04 || wallThickness > 0.25) {
            markInvalid(parentForm.wallThickness)
            alert('Wall Thickness must be between 0.04 and 0.25')
            return false
        } else {
            // This field is valid
            markValid(parentForm.wallThickness)
        }
    }
 
    if (!angleOfCutAInput) {
        markInvalid(parentForm.angleOfCutAInput)
        alert('Angle of Cut A is required')
        return false
    } else {
        // Make sure the angle is valid
        var angleOfCutA = parseInt(angleOfCutAInput)
        if (isNaN(angleOfCutA) || angleOfCutA < 0 || angleOfCutA > 60) {
            markInvalid(parentForm.angleOfCutA)
            alert('Angle of Cut A must be between 0 and 60')
            return false
        }
        // If we get here, angle must be empty or valid
        markValid(parentForm.angleOfCutA)
    }
 
    if (!angleOfCutBInput) {
        markInvalid(parentForm.angleOfCutBInput)
        alert('Angle of Cut B is required')
        return false
    } else {
        // Make sure the angle is valid
        var angleOfCutB = parseInt(angleOfCutBInput)
        if (isNaN(angleOfCutB) || angleOfCutB < 0 || angleOfCutB > 60) {
            markInvalid(parentForm.angleOfCutB)
            alert('Angle of Cut B must be between 0 and 60')
            return false
        }
        // If we get here, angle must be empty or valid
        markValid(parentForm.angleOfCutB)
    }
 
    // All fields are valid
    return true
}
 
// Marks a field as valid
function markValid(field) {
    field.parentNode.setAttribute('style', 'color:#000;')
}
 
// Marks a field as invalid
function markInvalid(field) {
    field.parentNode.setAttribute('style', 'color:#f00;')
}
 
// Calculates the values for a single row in the output table
function calculateTableRow(degree, setbackMeasurement, diameter, thickness, radius) {
    var rowValues = {}
    var degreeInRadians = degree * Math.PI / 180
 
    rowValues['tan'] = diameter * Math.tan(degreeInRadians)
 
    if (degree == 0) {
        rowValues['entryLength'] = setbackMeasurement
    } else if (degree <= 30) {
        rowValues['entryLength'] = rowValues['tan'] + (setbackMeasurement * ((30 - degree + 1) / 30))
    } else if (degree >= 50) {
        rowValues['entryLength'] = rowValues['tan'] - (thickness * Math.tan(degreeInRadians))
    } else {
        rowValues['entryLength'] = rowValues['tan']
    }
 
    rowValues['entryLengthMetric'] = rowValues['entryLength'] * 25.4
 
    if (degree == 0) {
        rowValues['cutLength'] = 0
    } else {
        rowValues['cutLength'] = (rowValues['tan']/Math.sin(degreeInRadians)).toFixed(2)
    }
 
    // Seperating the calculation steps to match the spreadsheet columns. Makes debugging easier.
    var D = rowValues['tan']
    var E = rowValues['entryLength']
    var O = Math.cos(degreeInRadians)
    var I = (radius/O)
    var J = (D/2 + I)
    var K = J - E
 
    rowValues['fromEndOfTube'] = K
 
    return rowValues
}

jednak po przeanalizowaniu tego wszystkiego (to co potrafiłem to prze konwertowałem do excela), wychodzą mi dziwne liczny nie pasujące do tego co robi kalkulator na stronie.

Szczególnie nie zrozumiały jest dla mnie zapis:

var tangentTableHTML = '<table border="0" style="font-size: 11pt">' +
        '<tr><th colspan="2"> <img src="procedure/beginnotch.jpg"><br> Begin Notch A at:  &nbsp; Begin Notch B at:</th></tr>' +
        '<tr>' +
        '</tr>'
 
    tangentTableHTML += '<tr>'
 
       // Cut A
 
    var rowValues = calculateTableRow(angleOfCutA, setbackMeasurement, outsideDiameter, wallThickness, radius)
    tangentTableHTML +=  '<td>' + rowValues['entryLength'].toFixed(2)
    lengthBetween = lengthBetween - rowValues['fromEndOfTube']
 
    // Cut B
    rowValues = calculateTableRow(angleOfCutB, setbackMeasurement, outsideDiameter, wallThickness, radius)
    tangentTableHTML +=  '<td>' + rowValues['entryLength'].toFixed(2)
    lengthBetween = lengthBetween - rowValues['fromEndOfTube']
    tangentTableHTML += '</tr>' +
                                        '</table>'
  tangentTableHTML += '<dl><dt><img src="procedure/finalcut3.jpg"><br><b>Overall cut length:</b></dt><dd>' + lengthBetween.toFixed(2) + '</dd></dl>'
 
    // Add the tangent table to the output
    document.getElementById('tangentTableContainer').innerHTML = tangentTableHTML
 
}

...gdzie jest tabela która generuje już gotowe liczby.

Proszę o pomoc oraz wrzucam linka do mojego pliku gdzie zrobiłem to co mogłem
http://www.speedyshare.com/files/29579359/Kalkulator_ci_cia.xls

Nie wiem czy m to jakieś znaczenie, ale chciałbym wyniki w mm, oryginalnie są cale.

Pozdrawiam i czekam na pomoc.

[email protected]

PS. Jeszcze raz podkreślam że nie jestem programistą i nie bardzo siew tym orientuje :)

Pozostało 580 znaków

2011-07-26 01:08
bo
0

Tutaj

</script><script type="text/javascript">
masz wymieniony język, to nie jest Java.

Pozostało 580 znaków

2011-07-26 02:00
o_O
0

wersje excelową

Chodzi o wzór do wklejenia w exelu czy gadżet w VB do niego?

Pozostało 580 znaków

2011-07-26 09:10
vr6k3
0

wolał bym w excelu bez VB....

Pozostało 580 znaków

Odpowiedz
Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0