Mar 26th, 2005, 12:04 AM
#1
Thread Starter
Admodistrator
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?
Mar 26th, 2005, 12:06 AM
#2
Re: Calculator help:
You can't use & for anything except strings.
VB Code:
z = x + y + Val(Calc.Caption)
Mar 26th, 2005, 12:10 AM
#3
Thread Starter
Admodistrator
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
Mar 26th, 2005, 12:15 AM
#4
Registered User
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?
Mar 26th, 2005, 12:17 AM
#5
Thread Starter
Admodistrator
Re: Calculator help:
index refers to the caption of whatever i click on, yes its an array
Mar 26th, 2005, 12:19 AM
#6
Re: Calculator help:
Maybe you could use this:
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim x As New ScriptControl
x.Language = "vbScript"
MsgBox Format(x.Eval("(49*48*47*46*45*44)/(1*2*3*4*5*6)"), "standard")
End Sub
Mar 26th, 2005, 12:22 AM
#7
Thread Starter
Admodistrator
Re: Calculator help:
uhhh...are you sure you posted in the right topic? *** is that? lol
Mar 26th, 2005, 12:32 AM
#8
Re: Calculator help:
Would this help you more?
VB Code:
Option Explicit
' Add a reference to Microsoft Script Control 1.0
Private Sub Form_Load()
Dim x As New ScriptControl
Dim z%, a%, q$
z = 55
a = 24
q = "*"
x.Language = "vbScript"
MsgBox Format(x.Eval(z & q & a), "standard")
End Sub
It prints out 1,320.00, which is 55 x 24
Mar 26th, 2005, 12:35 AM
#9
Thread Starter
Admodistrator
Re: Calculator help:
heck yes it would. ill check it out
Mar 26th, 2005, 12:38 AM
#10
Thread Starter
Admodistrator
Re: Calculator help:
user defined type not defined, also wahts the "standard")
Mar 26th, 2005, 12:55 AM
#11
Re: Calculator help:
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 ...
Originally Posted by
dglienna
...
VB Code:
z = x + y + Val(Calc.Caption)
VAL() isn't the best way of getting numeric value(s) from string ...
Mar 26th, 2005, 12:58 AM
#12
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
Mar 26th, 2005, 12:59 AM
#13
Re: Calculator help:
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.
Mar 26th, 2005, 01:00 AM
#14
Thread Starter
Admodistrator
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
Mar 26th, 2005, 01:08 AM
#15
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.
Mar 26th, 2005, 01:10 AM
#16
Thread Starter
Admodistrator
Re: Calculator help:
i didnt see it , ill look now
Mar 26th, 2005, 01:19 AM
#17
Thread Starter
Admodistrator
Re: Calculator help:
Heres my whole code.
VB Code:
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 = (b.Eval(x & y & Calc.Caption))
End If
End Sub
Private Sub Form_Load()
Dim b As New ScriptControl
b.Language = "vbScript"
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?
Mar 26th, 2005, 01:24 AM
#18
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
Mar 26th, 2005, 01:26 AM
#19
Thread Starter
Admodistrator
Re: Calculator help:
no i didnt add it *slaps himself*
Mar 26th, 2005, 01:27 AM
#20
Re: Calculator help:
val(Calc.Caption) needs to be changed, too.
Mar 26th, 2005, 01:29 AM
#21
Thread Starter
Admodistrator
Re: Calculator help:
*invalid use of new keyword*
Dim b As New ScriptControl
Mar 26th, 2005, 02:09 AM
#22
Mar 26th, 2005, 02:31 AM
#23
Thread Starter
Admodistrator
Re: Calculator help:
VB Code:
Option Explicit
Dim x As Integer, y As String, z As Integer, zz As Integer
Dim b As New ScriptControl
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 = (b.Eval(x & y & Calc.Caption))
End If
End Sub
Private Sub Form_Load()
b.Language = "vbScript"
End Sub
Mar 26th, 2005, 02:41 AM
#24
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:
Option Explicit
Dim x As Integer, y As String, z As Integer, zz As Integer
Dim b As New ScriptControl
Private Sub Command1_Click()
x = 22: y = "*"
Command1.Caption = b.Eval(x & y & Val(Command1.Caption))
End Sub
Private Sub Form_Load()
Command1.Caption = 8
b.Language = "vbScript"
End Sub
Zip your project, and upload it as an attachment. I'll fix it for you.
You have a Private Message
Mar 26th, 2005, 02:59 AM
#25
Thread Starter
Admodistrator
Re: Calculator help:
Attached Files
Mar 26th, 2005, 03:26 AM
#26
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
Mar 26th, 2005, 01:40 PM
#27
Thread Starter
Admodistrator
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
Mar 26th, 2005, 01:46 PM
#28
Thread Starter
Admodistrator
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...
Mar 26th, 2005, 03:24 PM
#29
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.
Mar 26th, 2005, 05:52 PM
#30
Thread Starter
Admodistrator
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
Forum Rules
Click Here to Expand Forum to Full Width