-
Use Of Calculator In Vb
I WANT TO USE CALCULATOR i.e., "CALC.EXE" program in my vb application.
1) HOW CAN I CALL THE PROGRAMM IN VB ?
2) HOW CAN I PUT MY RESULT TO THE CALCULATOR ?
3) HOW CAN I GET THE RESULT OF THE CALCULATOR SUCH THAT THE RESULT CAN BE PROCESED FURTHER IN MY APPLICATION ?
CAN ANY BODY SUGGEST ME ?
.... REGARDS
-
This shows the principles :-
Code:
'------------------------------------------------
Sub test()
Dim MyData As DataObject
Dim ReturnValue, I
'- from VB Editor help
ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I = 1 To 100 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=", True ' Get grand total.
'- copy value
SendKeys "^C", True
'- paste to sheet
Set MyData = New DataObject
MyData.GetFromClipboard
x = MyData.GetText(1)
Worksheets("Sheet1").Cells(1, 1).Value = x
'- close
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
End Sub
'----------------------------------------------
-
set mydata = new dataobject
is giving compile error
it says "invalid use of New keyword"
what could be the reason pl ?
..
-
Try using FindWindow, FindWindowEx, and SendMessage APIs on
the shelled calculator to automate it without the unreliability of
SendKeys. If the user click somewhere or types something while
your code is interating with the calculator then it will throw
SendKeys out of sync.
:)
-
This code works Ok in XL97. Suggest you look up VB Editor help for your version.
Shell... Sendkeys............ DataObject