Use function Solver of Excel in VB.NET 2003


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Use function Solver of Excel in VB.NET 2003

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    5

    Post Use function Solver of Excel in VB.NET 2003

    Hello everybody,

    I want to use the function Solver, which exists as a tool in Excel, in VB.NET 2003. What i want to do is to build a project in which i can give a desired output in order the program can tell to me what the initial data must be. I had this implemented in Excel using the solver, but i must build a Windows Application doing apart from other things and this jop.

    During the search i had done all the weak i didn' t find anything usefull in Studio .Net 2003. If anyone knows sth about that, i would be glad hearing his/hers ideas and suggestions.

    Thanks for your time spending on reading my post.

  2. #2
    Join Date
    Jan 2006
    Posts
    1

    Talking Re Solver Problems in vb.net with excel

    Hy there... it took me quite along time, because in the Net you don't find quite something according to this thread.

    But:
    ....Now

    At first: it is possible to access the Solver from .net via excel.
    Maybe one has to create a Temp-excel file to use it just in .net

    My Example shows how you can Use the solver with a Macro defined in your Excel file.

    at first you need to set the reference to excel in .net:
    Click on References, add reference.
    Click the .com button and browse to the Microsoft office Folder in which the Excel.exe is located.

    Add it. (This also works with some other parts of the office package)

    Now you should see EXCEL in your references
    code:

    Imports Microsoft.Office.Interop 'so you have the opportunity to access excel without writing this stuff NOTE: this imports has nothing to do with references... you CAN use excel without this!

    Public Class Form1
    Dim oExcelApp As Excel.Application
    Dim oExcelWorkbook As Excel.Workbook
    Dim oExcelWorksheet As Excel.Worksheet
    ...
    ...

    private sub subExcelSolver
    dim tmpStringPath as string = c:\Data\..\tmp.xls
    oExcelApp = New Excel.Application
    oExcelApp .Visible = True 'if you want to see it FALSE if not
    oExcelWorkbook = xlApp.Workbooks.Open(tmpStringPath)
    oExcelWorksheet = xlMappe.Worksheets(1)
    oExcelApp .Run("Solver.xla!Auto_Open") ' !!!!!!!!!!
    dim tmpIntValue as integer = 44 'This is the Value that should be the result
    oExcelApp .Run("subVbaExecuteSolver", tmpIntValue , some other parameters maybe changed cells, etc.)

    end sub


    ...
    ...
    end class


    within your Excel file

    add a new Module
    and place a sub like this

    Public Sub subVbaExecuteSolver(ByVal SomeValue As integer, byval other parameters)
    SolverReset
    SolverOk SetCell:="B2", MaxMinVal:=1, ByChange:="A1","C2"
    ...
    SolverSolve UserFinish:=True
    SolverReset
    End Sub


    And now have some fun!
    Hopefully...
    Greets Felix,
    Göttingen, Germany

Similar Threads

  1. call function for button
    By angela_quests in forum VB Classic
    Replies: 2
    Last Post: 04-13-2007, 04:57 AM
  2. Replies: 1
    Last Post: 11-15-2006, 05:13 AM
  3. VB.NET 2003 Std Edition to Include Upgrade Wizard
    By Patrick Troughton in forum .NET
    Replies: 2
    Last Post: 02-23-2003, 06:22 PM
  4. calling ping thru vb
    By Michael Shutt in forum VB Classic
    Replies: 6
    Last Post: 04-05-2001, 02:25 AM
  5. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 10:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center