|
-
May 11th, 2004, 03:16 AM
#1
Thread Starter
New Member
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
-
May 11th, 2004, 04:26 AM
#2
Addicted Member
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
'----------------------------------------------
Regards
BrianB
-------------------------------
-
May 11th, 2004, 06:07 AM
#3
Thread Starter
New Member
set mydata = new dataobject
is giving compile error
it says "invalid use of New keyword"
what could be the reason pl ?
..
Last edited by jollydhar; May 11th, 2004 at 11:27 PM.
-
May 11th, 2004, 11:00 AM
#4
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 12th, 2004, 08:16 AM
#5
Addicted Member
This code works Ok in XL97. Suggest you look up VB Editor help for your version.
Shell... Sendkeys............ DataObject
Regards
BrianB
-------------------------------
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
|