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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript Calculator Problems

Status
Not open for further replies.

kanin247

Programmer
Apr 23, 2001
113
0
0
US
I'm trying to create a calculator that calculates the impedance of a line. The user selects/inputs data and depending on the type of data selected, the program matches it with a table of values and uses this data to calculate the impedance. I wrote it out using just the JAVA language using numerous 'if' statements and now I am trying to write it using JAVAScript. I was thinking of using drop down boxes for the user to select from instead of checking the user's input each time but do not know how to make the selected choice point to a certain set of data in a table and also to use that data in other calculations.

Here's my problem for clerification purposes...

**********************

Select Conductor Type/Size (drop down box)
- acsr 1351
- acsr '4/0'
- al 477
- cu'1/0'
- cu #2

Select KV (drop down box)
- 230
- 115
- 46
- 33

Enter Mileage (user input)
Enter Spacing (user input)

Resistance (calculated output)
Reactance (calculated output)
Charging (calculated output)

-------------------------------

DATA TABLE
acsr 1351 R=0.0803 X=0.369 B=0.0838
acsr '4/0' R=0.0829 X=0.378 B=0.0855
al 477 R=0.1304 X=0.557 B=0.1079
cu '1/0' R=0.305 X=0.503 B=0.1205
cu #2 R=0.964 X=0.546 B=0.1274

FORMULAS
Resistance = (R*100/KV*KV)*Milg
Reactance = [(X*100/KV*KV)+(0.28*LOG10(Spacing)]*Milg
Charging = [(0.0001*KV*KV)/(B+0.07*LOG10(Spacing)]*Milg

***********************

So, the user selects the conductor type/size. Depending on which one they chose determines which set of data to use in the formula. Then using this data along with the inputed mileage, the program calculates the resistance and impedance.

Well, I hope that I have clerified my problem for you and I hope that you will be able to help. Thanks.

~kanin
 
Hi,

What you need is an array (3*5) in wich you will store R, X and B values for each conductor type. Columns should give the R, X and B and rows should be the index of conductor type/size selector.
Code:
<script  language=JavaScript>
	var data = new Array([0.080,0.369,0.0838], [0.0829,0.378,0.0855], [0.1304,0.557,0.1079],
	[0.305,0.503,0.1205], [0.964,0.546,0.1274]);
	alert(data[4][1]);
</script>
The rows should vary from 0 to 4, the columns should vary from 0 to 2. &quot;data[4][1]&quot; should give the X of cu #2!

Regards,
Luís Silva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top