哪个朋友可以用VB做出只有1个文本框1个按钮的计算器,文本框内输入+,-,*,/,和()的运算,点按钮结果显示在文本框上,会的朋友教下--感激不尽,上次问过了,大家有的说到其他语言上了,大家有没更好的方法,再次谢了

解决方案 »

  1.   

    VbScript 你不喜欢, 下面这个你再不能接受的话, 我想你只有去找 彼尔 啦.........Option Explicit
    Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As LongPrivate Sub Command1_Click()
       ExecuteLine "RtnVal = " & Text1.Text
       ExecuteLine "clipboard.settext RtnVal"
       Text1.Text = Clipboard.GetText
    End SubPublic Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
       ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, fCheckOnly) = 0
    End Function
      

  2.   

    学习.........想问一下CBM666大师:只能通过剪贴板取得计算结果吗?
      

  3.   

    EbExecuteLine只能在设计时有效,生成exe文件就不行了。。
    还是用ScriptControl的Eval吧
      

  4.   

    这么简单的问题这么大个论坛没人告诉你
    我先告诉你思路吧:
    做一组控件数组Command1,复制后粘贴的时候选是,都叫Command,它们的Index属性不一样,分别是0、1、2、3、4、5
    把它们调整成正方型的,标题是+,-,*,/,(,和)
    然后用一个变量保存Text里面的数据
    用Select case判断他按了什么
      

  5.   

    这个问题能解决,但是你要说明,就只有 +,-,*,/,和()的运算;没有其他的,可以写个函数来判断一下阿。通过函数来判断先乘除后加减有括号先处理括号,只要把规则定好了,实现起来是没问题的。
    1、可以把整个式子作为一个字符串
    2、重第一个字符开始判断,是运算符,在判断前后两侧的运算符级别高低,是数字则继续判断下一个字符。
    更简单的办法是约定数字和运算符、运算符与运算符之间用空格分开,则直接把该整个式子用split(整个式子," ")处理成数组,然后再循环计算,直到数组中就剩下一个元素。则是最终结果。
      

  6.   

    这个都差不多的,只要将里面的操作符和操作数以字符串方式分离后就都一样了。推荐一个示例程序,可以直接用,还有源代码,LZ一定试下。
    http://download.csdn.net/detail/txzsp/3781512
      

  7.   


    //表达式求值
    #include <stdio.h>
    #include <malloc.h>
    #include <string.h>
    /*
    *功能:根据运算符计算
    *参数:a, b参与运算的数, ch运算符
    *返回值:计算结果,操作符错误则返回0
    */
    int cal(int a, char ch, int b)
    {
    switch(ch)
    {
    case '+':
    return a+b;
    break;
    case '-':
    return a-b;
    break;
    case '*':
    return a*b;
    break;
    case '/':
    return a/b;
    break;
    }
    return 0;
    }
    /*
    *功能:计算表达式的值(用数组模拟栈)
    *参数:表达式字符串
    *返回值:计算结果
    */
    int evaluateExpression(char *str)
    {
    int i = 0, result, numSub = 0, operSub = 0;
    int tmp, len = strlen(str);
    int *operand = (int*)malloc(sizeof(int)*len);
    char *operat = (char*)malloc(sizeof(char)*len);
    while(str[i] != '\0')
    {
    switch(str[i])
    {
    case '+':
    while(operSub > 0 && operat[operSub-1] != '(')
    {
    printf("%d %c %d = ", operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    operand[numSub-2] = cal(operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    printf("%d\n", operand[numSub-2]);
    --numSub;
    --operSub;
    }
    operat[operSub++] = '+';
    break;
    case '-':
    while(operSub > 0 && operat[operSub-1] != '(')
    {
    printf("%d %c %d = ", operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    operand[numSub-2] = cal(operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    printf("%d\n", operand[numSub-2]);
    --numSub;
    --operSub;
    }
    operat[operSub++] = '-';
    break;
    case '*':
    if(str[i+1] >= '0' && str[i+1] <= '9')
    {
    tmp = 0;
    while(str[i+1] >= '0' && str[i+1] <= '9')
    {
    tmp = tmp * 10 + str[i+1] - '0';
    ++i;
    }
    --i;
    printf("%d * %d = ", operand[numSub-1], tmp);
    operand[numSub-1] = cal(operand[numSub-1], '*', tmp);
    printf("%d\n", operand[numSub-1]);
    ++i;
    }
    else
    operat[operSub++] = '*';
    break;
    case '/':
    if(str[i+1] >= '0' && str[i+1] <= '9')
    {
    tmp = 0;
    while(str[i+1] >= '0' && str[i+1] <= '9')
    {
    tmp = tmp * 10 + str[i+1] - '0';
    ++i;
    }
    --i;
    printf("%d / %d = ", operand[numSub-1], tmp);
    operand[numSub-1] = cal(operand[numSub-1], '/', tmp);
    printf("%d\n", operand[numSub-1]);
    ++i;
    }
    else
    operat[operSub++] = '/';
    break;
    case '(':
    operat[operSub++] = '(';
    break;
    case ')':
    while(operat[operSub-1] != '(')
    {
    printf("%d %c %d = ", operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    operand[numSub-2] = cal(operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    printf("%d\n", operand[numSub-2]);
    --numSub;
    --operSub;
    }
    --operSub;
    break;
    default:
    tmp = 0;
    while(str[i] >= '0' && str[i] <= '9')
    {
    tmp = tmp * 10 + str[i] - '0';
    ++i;
    }
    --i;
    operand[numSub++] = tmp;
    break;
    }
    ++i;
    }
    while(numSub > 1 && operSub >= 1)
    {
    printf("%d %c %d = ", operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    operand[numSub-2] = cal(operand[numSub-2], operat[operSub-1], operand[numSub-1]);
    printf("%d\n", operand[numSub-2]);
    --numSub;
    --operSub;
    }
    result = operand[numSub-1];
    free(operand);
    free(operat);
    return result;
    }
    int main()
    {
    char *str = "225/15-20+(4-3)*2";
    int result;
    printf("计算过程:\n");
    result = evaluateExpression(str);
    printf("计算结果:result = %d\n", result);
    return 0;
    }计算过程:
    225 / 15 = 15
    15 - 20 = -5
    4 - 3 = 1
    1 * 2 = 2
    -5 + 2 = -3
    计算结果:result = -3
    用C写的,提供思路而已