脚本程序计算器
⑴ 用python操作Windows的计算器。
pyhook可以抓到键。
不过这里只需要消息就可以了,win32api中的windows的message
使用vc中的消息 工具,抓键盘消息。然后再把这个消息包装一下用pywin32中的API发送过去。
我以前用pyhook加pywin32, 控制过一个游戏,做外挂。
也用pywin32的com接口控制过excel
⑵ 怎样用shell脚本写一个简单的计算器
while (true); do
read -p "输入算式: " var
[[ $var == q ]] && break || echo "等于: "$(echo "scale=2;$var"|bc)
done
输入算式就能给出结果,输入q退出
⑶ 刚学shell脚本写了个小 计算器,加减除都可以,乘法不行,哪儿错了
你的问题在:elif [ $fangfa = " \* " ]; 这句并不能判断到“*“乘号;
正确的结果如下:
#!/bin/bash
echo "first number"
read a
echo "fangfa"
read fangfa
echo "second number"
read b
if [ "$fangfa" = "+" ];then
echo $(($a+$b))
elif [ "$fangfa" = "-" ];then
echo $(($a-$b))
elif [ "$fangfa" = "*" ];then
echo $(($a*$b))
elif [ "$fangfa" = "/" ];then
echo $(($a/$b))
fi
===============================================
脚本优化版本:
#!/bin/bash
read -p "input first number: " num1
read -p "input operator: " operator
read -p "input second number: " num2
if [ "$operator" == "+" ];then
echo " num1 + num2 = $(($num1+$num2))"
elif [ "$operator" == "-" ];then
echo "num1 - num2 = $(($num1-$num2))"
elif [ "$operator" == "*" ];then
echo "num1 * num2 = $(($num1*$num2))"
elif [ "$operator" == "/" ];then
echo "num1 / num2 = $(($num1/$num2))"
fi
⑷ 求flash脚本编写 做简易计算器
已发消息给你,请查看。
⑸ 在ASP中用VB脚本语言怎么做计算器
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Calculate</title>
<script language="VBSCRIPT">
Function Show(m)
If (Myform.Expression.Value = "" AND InStr(". + - * / ",m)) Then
Myform.Expression.Value = ""
ElseIf (InStr("+ - * / . ",Right(Myform.Expression.Value,1)) And InStr("+ - * / ",m)) Then
ElseIf (m = ".") Then
If (InStr("+ - * / . ",Right(Myform.Expression.Value,1))) Then
ElseIf ((InstrRev(Myform.Expression.Value,".") > InstrRev(Myform.Expression.Value,"+")) And (InstrRev(Myform.Expression.Value,".") > InstrRev(Myform.Expression.Value,"-")) And (InstrRev(Myform.Expression.Value,".") > InstrRev(Myform.Expression.Value,"*")) And (InstrRev(Myform.Expression.Value,".") > InstrRev(Myform.Expression.Value,"/"))) Then
Else
Myform.Expression.Value = Myform.Expression.Value + m
End If
Else
Myform.Expression.Value = Myform.Expression.Value + m
END If
End Function
Function Sqrt()
If (Myform.Expression.Value = "") Then
Myform.Expression.Value = ""
ElseIf (InStr(". + - * / ",Right(Myform.Expression.Value,1))) Then
Else
Myform.Expression.Value = Eval(Myform.Expression.Value)^2
End If
End Function
Function Result()
If (Myform.Expression.Value = "") Then
Myform.Expression.Value = ""
ElseIf (InStr(". + - * / ",Right(Myform.Expression.Value,1))) Then
Else
Myform.Expression.Value = Eval(Myform.Expression.Value)
End If
End Function
Function Clean()
Myform.Expression.Value = ""
End Function
</script>
<style type="text/css">
<!--
.style5 {font-size: 18px}
-->
</style>
</head>
<body bgcolor="#ffffee" text=#000000>
<form name="myform" method="post" action="">
<div align="center">
<table bgcolor="#C0e0ff" width="214" height="245" border="4">
<tr>
<th width="206" scope="col"><H2><font color="#0000A0"> 计算器 </font></H2></th>
</tr>
<tr>
<th height="36" scope="col"><table width="200" border="1">
<tr>
<td colspan="4"><div align="center">
<input name="expression" type="text" value="" size="28" maxlength="28" >
</div></td>
</tr>
<tr>
<td><div align="center">
<INPUT TYPE="button" id="seven"
onClick="Show('7')" VALUE=" 7 ">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 8 "
onClick="Show('8')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 9 "
onClick="Show('9')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" / "
onClick="Show('/')">
</div></td>
</tr>
<tr>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 4 "
onClick="Show('4')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 5 "
onClick="Show('5')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 6 "
onClick="Show('6')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" * "
onClick="Show('*')">
</div></td>
</tr>
<tr>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 1 "
onClick="Show('1')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 2 "
onClick="Show('2')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 3 "
onClick="Show('3')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" - "
onClick="Show('-')">
</div></td>
</tr>
<tr>
<td><div align="center">
<INPUT TYPE="button" VALUE=" 0 "
onClick="Show('0')">
</div></td>
<td><div align="center">
<INPUT TYPE="button" VALUE=" . "
onClick="Show('.')">
</div></td>
<td><div align="center">
<input type="button" value="sqr"
onClick="sqrt()">
</div></td>
<td><div align="center">
<input type="button" value=" + "
onClick="Show('+')">
</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<INPUT TYPE="button" VALUE=" AC "
onClick="clean()">
</div></td>
<td colspan="2"><div align="center">
<INPUT TYPE="button" VALUE=" = "
onClick="result()">
</div></td>
</tr>
</table></th>
</tr>
</table>
</div>
</form>
</body>
</html>
⑹ 利用javaScript脚本语言编写一个简单的“网页计算器”
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function jsq(fh)
{
var num1,num2;
num1=parseFloat(document.form1.text1.value);
num2=parseFloat(document.form1.text2.value);
if(fh=="+")
document.form1.text3.value=num1+num2;
if(fh=="-")
document.form1.text3.value=num1-num2;
if(fh=="*")
document.form1.text3.value=num1*num2;
if(fh=="/")
if(num2!=0)
{
document.form1.text3.value=num1/num2;
}
else
{
alert ("除数不能为零!")
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input name="text1" type="text" id="text1" />
</label>
<p>
<label>
<input name="text2" type="text" id="text2" />
</label>
</p>
<p>
<label>
<input name="Button1" type="Button" id="Button1" value="+" onClick="jsq('+')">
<input name="Button2" type="Button" id="Button2" value="-" onClick="jsq('-')"/>
<input name="Button3" type="Button" id="Button3" value="*" onClick="jsq('*')"/>
<input name="Button4" type="Button" id="Button4" value="/" onClick="jsq('/')"/>
</label>
</p>
<p>
<label>
<input name="text3" type="text" id="text3" />
</label>
</p>
</form>
</body>
</html>
⑺ 求高手帮忙,用javascript脚本语言编写个最简单的计算器,如图所示
Calculator.java:
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.applet.*;
public class Calculator extends Applet implements ActionListener{
Panel buttonPanel;
TextField tf; //用于显示输入的数字的文本框
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bDot,bPlus,bSub,bDiv,bMulti,bEqual; //按键
String onDisplay=""; //显示在文本框中的字符串
boolean isDotPressed=false; //按键'.'是否被按下
float operand; //通过按键输入的数
float operand1,operand2;//operand1和operand2为计算用的操作数
char operator; //计录所用的操作符
float result; //计算结果
int times=1; //小数点后有几位的10次方幂
public void init(){
setLayout(new BorderLayout(5,5));
tf=new TextField(30);
add(tf,BorderLayout.NORTH);
buttonPanel=new Panel();
buttonPanel.setLayout(new GridLayout(4,4,5,5));
add(buttonPanel,BorderLayout.CENTER);
//下面依次把按钮添加上去
b1=new Button("1");
buttonPanel.add(b1);
b1.addActionListener(this);
b1.setActionCommand("1");
b2=new Button("2");
buttonPanel.add(b2);
b2.addActionListener(this);
b2.setActionCommand("2");
b3=new Button("3");
buttonPanel.add(b3);
b3.addActionListener(this);
b3.setActionCommand("3");
bPlus=new Button("+");
buttonPanel.add(bPlus);
bPlus.addActionListener(this);
bPlus.setActionCommand("+");
b4=new Button("4");
buttonPanel.add(b4);
b4.addActionListener(this);
b4.setActionCommand("4");
b5=new Button("5");
buttonPanel.add(b5);
b5.addActionListener(this);
b5.setActionCommand("5");
b6=new Button("6");
buttonPanel.add(b6);
b6.addActionListener(this);
b6.setActionCommand("6");
bSub=new Button("-");
buttonPanel.add(bSub);
bSub.addActionListener(this);
bSub.setActionCommand("-");
b7=new Button("7");
buttonPanel.add(b7);
b7.addActionListener(this);
b7.setActionCommand("7");
b8=new Button("8");
buttonPanel.add(b8);
b8.addActionListener(this);
b8.setActionCommand("8");
b9=new Button("9");
buttonPanel.add(b9);
b9.addActionListener(this);
b9.setActionCommand("9");
bMulti=new Button("*");
buttonPanel.add(bMulti);
bMulti.addActionListener(this);
bMulti.setActionCommand("*");
b0=new Button("0");
buttonPanel.add(b0);
b0.addActionListener(this);
b0.setActionCommand("0");
bDot=new Button(".");
buttonPanel.add(bDot);
bDot.addActionListener(this);
bDot.setActionCommand(".");
bEqual=new Button("=");
buttonPanel.add(bEqual);
bEqual.addActionListener(this);
bEqual.setActionCommand("=");
bDiv=new Button("/");
buttonPanel.add(bDiv);
bDiv.addActionListener(this);
bDiv.setActionCommand("/");
}
public void actionPerformed(ActionEvent e){
String str=e.getActionCommand();
char b=str.charAt(0);
switch(b){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': onDisplay+=b;
operand=operand*10+Integer.parseInt(str);
if(isDotPressed) times*=10;
tf.setText(onDisplay);
break;
case '.': onDisplay+=b;
isDotPressed=true;
tf.setText(onDisplay);
break;
case '+':
case '-':
case '*':
case '/': operator=b;
operand1=operand/times;
System.out.println(operand1);
onDisplay="";
times=1;
isDotPressed=false;
operand=0;
break;
case '=': operand2=operand/times;
System.out.println(operand2);
switch(operator){
case '+': result=operand1+operand2;break;
case '-': result=operand1-operand2;break;
case '*': result=operand1*operand2;break;
case '/': result=operand1/operand2;break;
}
tf.setText(float.toString(result));
onDisplay="";
times=1;
isDotPressed=false;
operand=0;
break;
}
}
}
Calculator.html:
<html>
<applet code="Calculator.class" width=250 height=250>
</applet>
</html>
⑻ 如何用js做一个简易计算器
js做一个简易计算器具体如下:
<html>
<head>
<title>js运算</title>
<boby>
<table>
<tr>
<td>第一个数</td>
<td><input type="text" id="onesum"></td>
</tr>
<tr>
<td>运算符号</td>
<td><input type="text" id="fh"></td>
</tr>
<tr>
<td>第二个数</td>
<td><input type="text" id="twosum"></td>
</tr>
<tr>
<td>计算结果</td>
<td><input type="text" id="sum"></td>
</tr>
<tr>
<td colspan="2"><input type="button" value=" 计算 " onclick="js()"></td>
</tr>
<table>
<script>
function js(){
var num1=document.getElementById("onesum").value;
var num2=document.getElementById("twosum").value;
var fh=document.getElementById("fh").value;
var sum=0;
nu
m1=Number(num1);
num2=Number(num2);
if(fh=='+')
{
sum=num1+num2;
}
else if(fh=='-')
{
sum=num1-num2;
}else if(fh=='*')
{
sum=num1*num2;
}else if(fh=='/')
{
sum=num1/num2;
}
//alert(sum);
document.getElementById("sum").value=sum;
}
</script>
</boby>
</html>
⑼ 易语言制做计算器
呵呵,这个其实没这么麻烦,
易语言
里面就有这样的组件可以利用:1.先在扩展组件里面找到脚本组件并添加2.添加两个编辑框(必须的)3.添加一个按钮(没按钮怎么行?)4.些入代码,代码如下:
.
子程序
_按钮1_被单击
编辑框2.内容
=
脚本组件1.计算表达式
(编辑框1.内容)
如果可以使用,请采纳,谢谢。
⑽ 用JS脚本实现网页计算器!!求代码!求高手!!!!
C#的要不。。。
C#软件中也能做js
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class 计算机 : Form
{
double Num1 = 0;//这三行是考虑计算时候要用的
double Num2 = 0;//这三行是考虑计算时候要用的
string op = "";//这三行是考虑计算时候要用的
public 计算机()
{
InitializeComponent();
}
private void btnNum1_Click(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);//这个是做开平方的。。。
temp = Math.Sqrt(temp);
txtResult.Text = temp.ToString();
}
}
private void button6_Click(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);//这个是那个“阶乘键的”用的是“!”标记。
double factor = 1;
for (int i = 1; i <= temp; i++)
factor = factor * i;
txtResult.Text = factor.ToString();
}
}
private void btnNum1_Click_1(object sender, EventArgs e)
{
Button btn = sender as Button;//这个是第一步:要在计算器中输入数字的。。。
txtResult.Text += btn.Text;
}
private void btnNum3_Click(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);//这个是那个“正弦函数”。。
temp = Math.Sin(temp);
txtResult.Text = temp.ToString();
}
}
private void btnPoint_Click(object sender, EventArgs e)
{
if (txtResult.Text == "")
{
txtResult.Text = "0.";//这个是“小数点”问题。。。要考虑到:1、一串数字中不能出现两个小数点。。2.第一个输入小数点时问题
}
else
{
if (txtResult.Text.IndexOf(".") == -1)
{
txtResult.Text += ".";
}
}
}
private void btnNum0_Click(object sender, EventArgs e)
{
Button btn = sender as Button;//这是数字“0”的问题。。首先不能第一个为0.。。
if (txtResult.Text == "0")
{
txtResult.Text = btn.Text;
}
else
{
txtResult.Text += btn.Text;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
Button btn = sender as Button;//这是解决当第一个按“+”号时程序出错的状况。。。
if (txtResult.Text != "")
Num1 = double.Parse(txtResult.Text);
op = btn.Text;
txtResult.Text = "";
}
private void btnCalculate_Click(object sender, EventArgs e)
{
double result = 0;
Num2 = double.Parse(txtResult.Text);/////这是处理“=”的问题。。。不过还有些不足。。
switch (op)
{
case "+": result = Num1 + Num2; break;
case "-": result = Num1 - Num2; break;
case "*": result = Num1 * Num2; break;
case "/": result = Num1 / Num2; break;
default: result = 0; break;
}
txtResult.Text = result.ToString();
}
private void btnClear_Click(object sender, EventArgs e)
{
txtResult.Text = "";///////////////这是处理”清除键“的功能。。即:清除所有数字。。
Num1 = 0;
Num2 = 0;
op = "";
}
private void btnBackspace_Click(object sender, EventArgs e)
{
int len = txtResult.Text.Length;
if (len != 0)
txtResult.Text = txtResult.Text.Substring(0, len - 1);////这是处理“退格键”的问题。。即:除去最后一个数字。。。
}
private void button20_Click(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);////这是处理“相反数”的问题。。即:先按个‘9“键。再按此键变为”-9“
temp = temp * (-1);
txtResult.Text = temp.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);//这是”余弦“问题。。。
temp = Math.Cos(temp);
txtResult.Text = temp.ToString();
}
}
private void button4_Click_1(object sender, EventArgs e)
{
if (txtResult.Text != "")
{
double temp = double.Parse(txtResult.Text);//////这是处理”正切“问题。。
temp = Math.Tan(temp);
txtResult.Text = temp.ToString();
}
}
}
}