Results 1 to 5 of 5

Thread: Use Of Calculator In Vb

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    2

    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

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    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
    -------------------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    2
    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    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
  •  



Click Here to Expand Forum to Full Width