当前位置:首页 > 软件开放 > 正文内容

微信小程序简易计算器代码(小程序实现计算器)

软件开放1年前 (2023-04-06)1160

今天给各位分享微信小程序简易计算器代码的知识,其中也会对小程序实现计算器进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用js代码做一个简易计算器

function test(){

     var txt1 = document.getElementById("txt1"),

         txt2 = document.getElementById("txt2"),

         txt3 = document.getElementById("txt3"),

         opt  = document.getElementById("sel");

     txt3.value =  eval(txt1.value + opt.value + txt2.value);//eval函数可计算某个字符串,并执行其中的的js代码

}

input type="text" id="txt1" /

select id="sel"

     option value="+"+/option

     option value="-"-/option

     option value="*"*/option

     option value="/"//option

/select

input type="text" id="txt2" /

=

input type="text" id="txt3" /

input type="button" id="btn" value="计算" onclick="test()"/

用C语言编一个简单的计算器小程序

你说的是 vc 还是 tc 啊???

其他的运算:

#include stdio.h

int add(int x,int y) {return x+y;}

int sub(int x,int y) {return x-y;}

int mul(int x,int y) {return x*y;}

int div(int x,int y) {return x/y;}

int (*func[])()={add,sub,mul,div};

int num,curch;

char chtbl[]="+-*/()=";

char corch[]="+-*/()=0123456789";

int getach() {

int i;

while(1) {

curch=getchar();

if(curch==EOF) return -1;

for(i=0;corch[i]curch!=corch[i];i++);

if(istrlen(corch)) break;

}

return curch;

}

int getid() {

int i;

if(curch='0'curch='9') {

for(num=0;curch='0'curch='9';getach()) num=10*num+curch-'0';

return -1;

}

else {

for(i=0;chtbl[i];i++) if(chtbl[i]==curch) break;

if(i=5) getach();

return i;

}

}

int cal() {

int x1,x2,x3,op1,op2,i;

i=getid();

if(i==4) x1=cal(); else x1=num;

op1=getid();

if(op1=5) return x1;

i=getid();

if(i==4) x2=cal(); else x2=num;

op2=getid();

while(op2=4) {

i=getid();

if(i==4) x3=cal(); else x3=num;

if((op1/2==0)(op2/2==1)) x2=(*func[op2])(x2,x3);

else {

x1=(*func[op1])(x1,x2);

x2=x3;

op1=op2;

}

op2=getid();

}

return (*func[op1])(x1,x2);

}

void main(void) {

int value;

printf("Please input an expression:\n");

getach();

while(curch!='=') {

value=cal();

printf("The result is:%d\n",value);

printf("Please input an expression:\n");

getach();

}

}

只能 + - * /

简易计算器代码

我的计算器 Option Explicit Dim FocusText As VB.TextBox Dim pd As Boolean Dim x As Double Dim y As Double Dim ch As Integer Private Sub Command1_Click(Index As Integer) On Error Resume Next FocusText.SetFocus If Index SendKeys Index ElseIf Index = 10 Then ch = Index - 10 x = Val(Text1.Text) Text1.Text = "" ElseIf Index = 14 Then y = Val(Text1.Text) Select Case ch Case 0 Text1.Text = x + y Case 1 Text1.Text = x - y Case 2 Text1.Text = x * y Case 3 Text1.Text = x / y End Select ElseIf Index = 15 Then FocusText.SetFocus SendKeys "{BS}" ElseIf Index = 16 Then FocusText.SetFocus SendKeys "." End If End Sub '防止输入多个小数点以及出数字外的其他字符 Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii 57) And KeyAscii 46 And KeyAscii 8 Then KeyAscii = 0 End If If pd = True And KeyAscii = 46 Then KeyAscii = 0 End If If pd = False And KeyAscii = 46 Then pd = True KeyAscii = 46 End If End Sub '防止 Ctrl + v 粘贴 Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyV And Shift = vbCtrlMask Then Text1.Enabled = False Clipboard.Clear Text1.Enabled = True End If End Sub '防止右键粘贴 Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbRightButton Then Text1.Enabled = False Clipboard.Clear Text1.Enabled = True End If End Sub Private Sub Text1_LostFocus() Set FocusText = Text1 End Sub 界面如下 0为Command1(0)1为Command1(1)依次类推 ←为Command1(15) 小数点为Command1(16) 贴子相关图片: 界面可以到

vb:简易计算器(加减乘除)代码

代码如下:

Dim t, t1 As Integer

Dim x, y As Double

Public Sub com()

x = Val(l1.Caption)

Select Case t1

Case Is = 1: y = y + x

Case Is = 2: y = y - x

Case Is = 3: y = y * x

Case Is = 4: y = y / x

End Select

t1 = 0

t = 0

l1.Caption = "0"

End Sub

Private Sub Form_Load()

x = 0

y = 0

t = 0

t1 = 1

End Sub

Private Sub c0_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "0"

Else

l1.Caption = l1.Caption + "0"

End If

End Sub

Private Sub C1_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "1"

Else

l1.Caption = l1.Caption + "1"

End If

End Sub

Private Sub c10_Click(Index As Integer)

If t = 0 Then

l1.Caption = l1.Caption + "."

t = 1

End If

End Sub

Private Sub C2_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "2"

Else

l1.Caption = l1.Caption + "2"

End If

End Sub

Private Sub C3_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "3"

Else

l1.Caption = l1.Caption + "3"

End If

End Sub

Private Sub C4_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "4"

Else

l1.Caption = l1.Caption + "4"

End If

End Sub

Private Sub C5_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "5"

Else

l1.Caption = l1.Caption + "5"

End If

End Sub

Private Sub C6_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "6"

Else

l1.Caption = l1.Caption + "6"

End If

End Sub

Private Sub C7_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "7"

Else

l1.Caption = l1.Caption + "7"

End If

End Sub

Private Sub C8_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "8"

Else

l1.Caption = l1.Caption + "8"

End If

End Sub

Private Sub C9_Click(Index As Integer)

If l1.Caption = "0" Then

l1.Caption = "9"

Else

l1.Caption = l1.Caption + "9"

End If

End Sub

Private Sub z1_Click(Index As Integer)

com

t1 = 1

End Sub

Private Sub z2_Click(Index As Integer)

com

t1 = 2

End Sub

Private Sub z3_Click(Index As Integer)

com

t1 = 3

End Sub

Private Sub z4_Click(Index As Integer)

com

t1 = 4

End Sub

Private Sub z5_Click(Index As Integer)

tmp = Mid(l1.Caption, Len(l1.Caption), 1)

If tmp = "." Then

t = 0

End If

If Len(l1.Caption) = 1 Then

l1.Caption = "0"

Else

l1.Caption = Left(l1.Caption, Len(l1.Caption) - 1)

End If

End Sub

Private Sub z6_Click(Index As Integer)

l1.Caption = "0"

Form_Load

End Sub

Private Sub z7_Click(Index As Integer)

If (l1.Caption "0") Then

l1.Caption = "-" + l1.Caption

End If

End Sub

Private Sub z8_Click(Index As Integer)

com

l1.Caption = Str(y)

End Sub

扩展资料

语言缺点

Visual Basic 语言具有不支持继承、无原生支持多线程、异常处理不完善等三项明显缺点,使其有所局限性(此些缺点皆已在 vb .net 获得改进)。

不支持继承

VB 5.0 和 VB 6.0 都是基于对象的编程语言,但是不包含继承特性。VB 中提供了特殊的类的功能,但是还是不能满足程序员的需求。

无原生支持多线程

Visual Basic 对于多线程无原生支持,只能通过Windows API的调用实现,且极其的不稳定。因为在API创建的线程中,并没有自动初始化运行时库,导致部分的函数无法使用。一般的,在VB6等早期的VB开发环境下,使用API创建线程的目的是完成容易使程序假死的大量数据或者逻辑的计算。

异常处理不完善

Visual Basic 中内置异常处理,即使未写异常处理代码,一旦用户出错也会弹出一个明确写出出错原因对话框,接着程序终止。

Visual Basic 中可以使用 Err.Raise抛出异常。对系统及用户抛出的异常的处理常用两种模式:一是使用 On Error Resume Next 处理错误;另一种是使用 On Error Goto 将运行引入错误处理代码。但相对 C++ 等语言而言,这样的异常处理破坏了代码的结构。

参考资料:百度百科-VB

微信小程序简易计算器代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于小程序实现计算器、微信小程序简易计算器代码的信息别忘了在本站进行查找喔。

扫描二维码推送至手机访问。

版权声明:本文由飞速云SEO网络优化推广发布,如需转载请注明出处。

本文链接:http://zspsrg.cn/post/15572.html

分享给朋友:

“微信小程序简易计算器代码(小程序实现计算器)” 的相关文章

红包软件开发(红包软件制作)

红包软件开发(红包软件制作)

今天给各位分享红包软件开发的知识,其中也会对红包软件制作进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、怎么把红包做成二维码,如何生成自己的支付宝领红包二维码? 2、如何开发弄个类似于抢红包的软件 3、想开发一个微信自动抢红包软件,有钱途吗? 4...

北京软件开发公司哪家好(北京软件开发公司招聘)

北京软件开发公司哪家好(北京软件开发公司招聘)

本篇文章给大家谈谈北京软件开发公司哪家好,以及北京软件开发公司招聘对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、北京手机APP软件开发公司哪家好 2、软件开发选哪个公司比较好? 3、北京APP开发的公司哪家好 4、北京的软件开发公司有哪些 5、北京软件定...

怎么删除home下的目录(误删home目录)

怎么删除home下的目录(误删home目录)

今天给各位分享怎么删除home下的目录的知识,其中也会对误删home目录进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、执行home命令可以删除目录吗 2、如何删除红帽Linux的/home下的文件 3、/home 目录下的文件如下图所示,请问如要要...

eclipse默认工作空间路径设置(eclipse配置构建路径)

eclipse默认工作空间路径设置(eclipse配置构建路径)

今天给各位分享eclipse默认工作空间路径设置的知识,其中也会对eclipse配置构建路径进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: 1、如何修改eclipse默认的工作空间路径及字体显示 2、怎么修改Eclipse默认打开路径 3、eclipse...

阳台的装修设计图片大全(阳台的装修设计图片大全集)

阳台的装修设计图片大全(阳台的装修设计图片大全集)

本篇文章给大家谈谈阳台的装修设计图片大全,以及阳台的装修设计图片大全集对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、阳台顶部装修效果图 小阳台怎么设计 2、一楼阳台装修效果图 6款阳台设计随你选 3、主卧阳台装修效果图 多款温馨雅致的室内阳台设计 阳台顶部装修...

如何在剪映上传自己制作的模板(怎么把作品上传到剪映,自己做的模板怎么上传到剪映)

如何在剪映上传自己制作的模板(怎么把作品上传到剪映,自己做的模板怎么上传到剪映)

本篇文章给大家谈谈如何在剪映上传自己制作的模板,以及怎么把作品上传到剪映,自己做的模板怎么上传到剪映对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。 本文目录一览: 1、剪映专业版如何将视频嵌入模板 2、剪映怎么做模板让别人用? 3、剪映怎样做模板出售 4、用剪映怎样制作放假通知模...