473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Visual basic 2005 and excel

Hallo,

I have a problem, I do not know how to convert some data from my visual basic 2005 program into a excel file. Can you please tell me what to do?
Feb 20 '07 #1
5 2512
willakawill
1,646 1GB
Hi. The first thing to do is post the code you have already and point out where it is that you need help
Feb 21 '07 #2
Hi. The first thing to do is post the code you have already and point out where it is that you need help

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim g As Double = -9.81  'Gravity
  3.  
  4.     Function Find_Verical_Velocity(ByVal Vy As Double, ByVal mass As Double, ByVal drag_y As Double) As Double
  5.  
  6.         If Vy > 0 Then
  7.             Vy = Vy + ((g - drag_y / mass) * 0.01) 'The equation that gives the velocity is V=Vo-gt
  8.         Else
  9.             Vy = Vy + ((g + drag_y / mass) * 0.01)
  10.         End If
  11.  
  12.  
  13.         Return (Vy) 'Returns the vertical velocity
  14.  
  15.     End Function
  16.     Function Find_Horizontal_Velocity(ByVal Vx As Double, ByVal mass As Double, ByVal drag_x As Double) As Double
  17.  
  18.         Vx = Vx + (-(drag_x / mass) * 0.01)
  19.  
  20.         Return (Vx)
  21.  
  22.     End Function
  23.  
  24.     Function Find_Distance(ByVal Vx As Double) As Double
  25.  
  26.         Static Distance As Double = 0
  27.  
  28.         Distance = Distance + (Vx * 0.01)
  29.  
  30.         Return (Distance)
  31.  
  32.     End Function
  33.  
  34.     Function Find_Height(ByVal Vy As Double) As Double
  35.         Static Height As Double = 0
  36.  
  37.         Height = Height + (Vy * 0.01)
  38.  
  39.         Return (Height)
  40.  
  41.     End Function
  42.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  43.  
  44.         Dim mass As Double = CInt(TextBox1.Text)
  45.         Dim angle As Double = CInt(TextBox2.Text)
  46.         Dim initial_velocity As Double = CInt(TextBox3.Text) 'Given initial velocity
  47.         Dim density As Double = CInt(TextBox4.Text)
  48.         Dim Height As Double = 0.0
  49.         Dim time As Double = 0.0
  50.         Dim Distance As Double = 0.0
  51.         Dim Vx As Double = 0.0 'Horizontal velocity component
  52.         Dim Vy As Double = 0.0 'Vertical velocity  component
  53.         Dim rad As Double
  54.         Dim new_velocity As Double
  55.         Dim Cd As Double = 0.47 'This is the drag coefficient and we assume that is constant
  56.         Dim A As Double = Math.PI * 0.05 ^ 2 'This is the cross-sectional area of the ball
  57.         Dim drag As Double
  58.         Dim drag_x As Double 'The horizontal drag component
  59.         Dim drag_y As Double 'The vertical drag component
  60.  
  61.         Dim ITEMS As ListViewItem
  62.  
  63.         If angle > 180 Then
  64.             MsgBox("PLEASE ENTER A SMALLER ANGLE")
  65.  
  66.         ElseIf angle < 0 Then
  67.             MsgBox("PLEASE ENTER A POSITIVE ANGLE")
  68.  
  69.         ElseIf mass < 0 Then
  70.             MsgBox("PLEASE ENTER A POSITIVE MASS")
  71.         Else
  72.  
  73.  
  74.  
  75.             rad = (angle / 180) * Math.PI  'Calculate the angle in rads
  76.             Vx = initial_velocity * Math.Cos(rad)
  77.             Vy = initial_velocity * Math.Sin(rad)
  78.  
  79.  
  80.             Do
  81.  
  82.                 time = time + 0.01
  83.  
  84.  
  85.                 Vy = Find_Verical_Velocity(Vy, mass, drag_y)
  86.                 Vx = Find_Horizontal_Velocity(Vx, mass, drag_x)
  87.  
  88.                 rad = Math.Atan(Vy / Vx) 'Because the angle changes during the flihgt it calculates the angle in different points
  89.                 new_velocity = Math.Sqrt((Vy ^ 2) + (Vx ^ 2))
  90.  
  91.  
  92.                 drag = 0.5 * Cd * density * new_velocity ^ 2 * A
  93.  
  94.                 drag_x = drag * Math.Cos(rad)
  95.                 drag_y = drag * Math.Sin(rad)
  96.  
  97.  
  98.                 angle = (rad * 180) / Math.PI
  99.  
  100.                 Distance = Find_Distance(Vx)
  101.  
  102.                 Height = Find_Height(Vy)
  103.  
  104.                 ITEMS = New ListViewItem(Math.Round(time, 4))
  105.                 ITEMS.SubItems.Add(Math.Round(Distance, 4))
  106.                 ITEMS.SubItems.Add(Math.Round(Height, 4))
  107.                 ITEMS.SubItems.Add(Math.Round(angle, 4))
  108.                 ITEMS.SubItems.Add(Math.Round(new_velocity, 4))
  109.                 ITEMS.SubItems.Add(Math.Round(Vy, 4))
  110.                 ITEMS.SubItems.Add(Math.Round(Vx, 4))
  111.                 ListView1.Items.Add(ITEMS)
  112.  
  113.             Loop Until (Height < 0)
  114.  
  115.         End If
  116.     End Sub
  117. End Class
Hallo, in the above program we put as inputs the angle, the initial velocity, the mass and the density of a rocket, and then it calculates the distance, the time the height, the velocity and the initial velocity of the rocket until it comes down to the ground. I would like to import the results of the distance and the height into the excel in order to draw a graph.

Please help me.

Thank you
Feb 24 '07 #3
willakawill
1,646 1GB
Ok. The simplest way that I know how to do this is to create an excel file with graph and named ranges for the data cells. Add excel as a reference in your project and use ole automation to open the graph and change the data in the named ranges.

There is a vba tutorial here that should help you get started
Feb 25 '07 #4
Ok. The simplest way that I know how to do this is to create an excel file with graph and named ranges for the data cells. Add excel as a reference in your project and use ole automation to open the graph and change the data in the named ranges.

There is a vba tutorial here that should help you get started

Thank You very much
Feb 25 '07 #5
willakawill
1,646 1GB
Thank You very much
You are very welcome. Good luck
Feb 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Omar | last post by:
Hi Developers, I am trying to access an Excel data file through a VB.Net application. I have the following code: =================================== VB.Net Code =================== Dim...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
0
by: geiaaa | last post by:
hello and happy new year... I just started a project were I need to call dll functions from within excel. More specifically I have created a custom dll in Visual Basic (visual studio 2005) with the...
2
by: Javier1958 | last post by:
Hi all I have a problem running Visual Basic 2005 (.NET) programs in other computers different of that where I have Visual Studio installed. I know I have to install the .NET framework in the...
0
by: Speilman_54 | last post by:
Hi, I'm converting an excel Macro into visual basic 2005 express, as I don't have a copy of VB 6 and trying to make and executable from it, I know this version doesn't have the save file as .exe,...
3
by: Amit | last post by:
Hello group, I"m new to COM Interop and Add-Ins. Today I was reading an article that says: "Use Visual Studio Tools for the Microsoft Office System to create a new Excel Workbook project in...
1
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.