Results 1 to 30 of 30

Thread: Calculator help:

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Calculator help:

    Dang, i thought i had this first try, in like 10 lines of code. heres my project.

    http://s5.yousendit.com/d.aspx?id=2Q...H2VTHQB5RWJEQ2

    The problem is on this line of code, z = x & y & Val(Calc.Caption)

    It seems vb wont evaluate it. Any ideas?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    You can't use & for anything except strings.

    VB Code:
    1. z = x + y + Val(Calc.Caption)

  3. #3

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    dg, that doesnt make sense with my code at all though.

    say x = 5, y = /, Val(Calc.Caption) = 3

    youd be writing this.

    5 + / 3

    that wont work : (

    what else could i use

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    66

    Talking Re: Calculator help:

    im still learning and so can't help you at the moment.....

    i just wanted to knw some parts in your code;.....and design

    first of all i wud like to ask is whether u have created a control array for ur digits?

    and does the (Index) refer to the index of the control array?

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    index refers to the caption of whatever i click on, yes its an array

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Maybe you could use this:

    VB Code:
    1. Option Explicit
    2.  
    3. ' Add a reference to Microsoft Script Control 1.0
    4.  
    5. Private Sub Form_Load()
    6.  
    7. Dim x As New ScriptControl
    8. x.Language = "vbScript"
    9. MsgBox Format(x.Eval("(49*48*47*46*45*44)/(1*2*3*4*5*6)"), "standard")
    10.  
    11. End Sub

  7. #7

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    uhhh...are you sure you posted in the right topic? *** is that? lol

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Would this help you more?

    VB Code:
    1. Option Explicit
    2.  
    3. ' Add a reference to Microsoft Script Control 1.0
    4.  
    5. Private Sub Form_Load()
    6.  
    7. Dim x As New ScriptControl
    8. Dim z%, a%, q$
    9. z = 55
    10. a = 24
    11. q = "*"
    12. x.Language = "vbScript"
    13. MsgBox Format(x.Eval(z & q & a), "standard")
    14.  
    15. End Sub

    It prints out 1,320.00, which is 55 x 24

  9. #9

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    heck yes it would. ill check it out

  10. #10

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    user defined type not defined, also wahts the "standard")

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Calculator help:

    Quote Originally Posted by dglienna
    You can't use & for anything except strings. ...
    Not entirely true: ampersand is a "shortcut" for LONG data type so
    z& = x& + y&
    is perfectly valid syntax ...

    Quote Originally Posted by dglienna
    ...
    VB Code:
    1. z = x + y + Val(Calc.Caption)
    VAL() isn't the best way of getting numeric value(s) from string ...

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    That's just for the format command. You can leave it off if you want.
    Its the same as Format(x,"#.##") You can use Standard, and a few others.

    Where's the error? Try This.
    Attached Files Attached Files

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Quote Originally Posted by RhinoBull
    Not entirely true: ampersand is a "shortcut" for LONG data type so
    z& = x& + y&
    is perfectly valid syntax ...


    VAL() isn't the best way of getting numeric value(s) from string ...
    Sorry. I was referring to mathematical evaulations. Also used in Hexidecimal Notation.

  14. #14

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    Option Explicit
    Dim x As Integer, y As String, z As Integer, zz As Integer

    Private Sub Cmd_Click(Index As Integer)
    x = Calc.Caption
    y = Cmd(Index).Caption
    End Sub

    Private Sub Command1_Click(Index As Integer)
    Calc.Caption = Command1(Index).Caption
    If Len(x) > 0 Then
    z = x & y & Val(Calc.Caption)
    Calc.Caption = z
    End If
    End Sub


    please insert as you would

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    I posted the project that you could try. Didn't it work? #12
    Add the reference to your project and you can use EVAL to compute the value.

  16. #16

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    i didnt see it , ill look now

  17. #17

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    Heres my whole code.
    VB Code:
    1. Option Explicit
    2. Dim x As Integer, y As String, z As Integer, zz As Integer
    3.  
    4. Private Sub Cmd_Click(Index As Integer)
    5.     x = Calc.Caption
    6.     y = Cmd(Index).Caption
    7. End Sub
    8.  
    9. Private Sub Command1_Click(Index As Integer)
    10.  Calc.Caption = Command1(Index).Caption
    11.     If Len(x) > 0 Then
    12.    ' z = x & y & Val(Calc.Caption)
    13.         Calc.Caption = (b.Eval(x & y & Calc.Caption))
    14.     End If
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18. Dim b As New ScriptControl
    19. b.Language = "vbScript"
    20. End Sub

    It highlights dim b as new scriptcontrol an says user type not defined or something...it works on your form though, ***? wahts wrong?

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Did you add the reference?

    ' Add a reference to Microsoft Script Control 1.0

    Click Project -> References, and check the box next to it.

    You can also put the DIM statement in the General Declarations section at the top of your form. Calc.caption needs val(), too

  19. #19

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    no i didnt add it *slaps himself*

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    val(Calc.Caption) needs to be changed, too.

  21. #21

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    *invalid use of new keyword*
    Dim b As New ScriptControl

  22. #22
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Post your code.

  23. #23

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    VB Code:
    1. Option Explicit
    2. Dim x As Integer, y As String, z As Integer, zz As Integer
    3. Dim b As New ScriptControl
    4.  
    5. Private Sub Cmd_Click(Index As Integer)
    6.     x = Calc.Caption
    7.     y = Cmd(Index).Caption
    8. End Sub
    9.  
    10. Private Sub Command1_Click(Index As Integer)
    11.  Calc.Caption = Command1(Index).Caption
    12.     If Len(x) > 0 Then
    13.    ' z = x & y & Val(Calc.Caption)
    14.         Calc.Caption = (b.Eval(x & y & Calc.Caption))
    15.     End If
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19. b.Language = "vbScript"
    20. End Sub

  24. #24
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    Click Project -> References, and scroll down to Microsoft Script Controls 6.0 and tick the box. That should do it. I replaces your textboxes (because you didn't post the project with your forms )
    Here is the code that keeps multiplying the value of the button.

    VB Code:
    1. Option Explicit
    2. Dim x As Integer, y As String, z As Integer, zz As Integer
    3. Dim b As New ScriptControl
    4.  
    5.  
    6. Private Sub Command1_Click()
    7. x = 22: y = "*"
    8. Command1.Caption = b.Eval(x & y & Val(Command1.Caption))
    9. End Sub
    10.  
    11. Private Sub Form_Load()
    12. Command1.Caption = 8
    13. b.Language = "vbScript"
    14. End Sub

    Zip your project, and upload it as an attachment. I'll fix it for you.
    You have a Private Message

  25. #25

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    done
    Attached Files Attached Files

  26. #26
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    I don't know what kind of project you started up, but you also saved the form as module1.bas, which could have helped to mess things up. I tried a lot of different things, before finally deleting everything except the renamed module (to a form) and added it to a new project. It works now, but you can only have single digit numbers. I'll let you work that one out.

    This was a major pita. Never seen it before.
    Attached Files Attached Files

  27. #27

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    lmao really? Well i had an old calculator thing, and i guess i saved it over the old module..I didnt think it worked that way

    by golly thats funny

  28. #28

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    wait, it works, which is good

    but i dont see a microsoft scripting control anywhere on your form, or in the properties anywhere!!

    wt..?
    I thought i had to add that, and i dont get any errors without it here...

  29. #29
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Calculator help:

    its not in components, which you had checked, and had a control in your form.
    you need the reference, which isn't a control per se, you just include the references that you want to use in your program. There are two choices from the Project menu Refernces and Components (cntrl-T).
    That's the difference.

  30. #30

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calculator help:

    oh k, cool, thanks dg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width