Link to home
Start Free TrialLog in
Avatar of Crono15M
Crono15M

asked on

Transfering Data from VB to Excel

I wrote a program to interface an external data source with Excel using a winsock and a database control.

Under the current circumstances I am able to send only 1 column of data to Excel.

If possible please modify my code to allow for 2 or more columns of data.
If not then please give an alternate solution.

(As will you will see when you look at my code, I am in no way an expert so please explain whatever you do, Thanks)

Here it is
----------------------------------------

Dim ncount As Integer

Private Sub cmdconnect_Click()
sckdvt.Connect
End Sub

Private Sub Cmddisconnect_Click()
sckdvt.Close
End Sub

Private Sub Cmdend_Click()
Unload Me
End Sub

Private Sub CmdIP_Click()
sckdvt.Close
sckdvt.RemoteHost = Txtip.Text
LblIP.Visible = False
Txtip.Visible = False
CmdIP.Visible = False
cmdconnect.SetFocus
Beep
MsgBox ("You must now reconnect")
End Sub

Private Sub Cmdport_Click()
sckdvt.Close
sckdvt.RemotePort = Txtport.Text
Lblport.Visible = False
Txtport.Visible = False
Cmdport.Visible = False
cmdconnect.SetFocus
Beep
MsgBox ("You must now reconnect")
End Sub

Private Sub Form_Load()
frmSplash.Show vbModal
Load Frmmain
Load frmAbout
End Sub

Private Sub mnuabout_Click()
frmAbout.Show vbModal
End Sub

Private Sub mnuExit_Click()
Unload Me
End Sub

Private Sub mnuIP_Click()
LblIP.Visible = True
Txtip.Visible = True
CmdIP.Visible = True
Txtip.SetFocus
End Sub

Private Sub mnuPort_Click()
Lblport.Visible = True
Txtport.Visible = True
Cmdport.Visible = True
Txtport.SetFocus
End Sub

Private Sub sckdvt_DataArrival(ByVal bytesTotal As Long)
Static ncount As Integer
Dim strdata As String
Dim dmeasurement As Double
ncount = ncount + 1
If ncount < 60 Then
    sckdvt.GetData strdata, vbString
    Txtdata.Text = strdata
    If Len(strdata) < 15 Then
        Dtacontrol.Recordset.AddNew
        dmeasurement = Val(strdata)
        Txtexcel.Text = dmeasurement
    Else
        sckdvt.GetData strdata, vbString
        Txtdata.Text = strdata
    End If
End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of ture
ture

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crono15M
Crono15M

ASKER

How do I reference to an Object Library?
I don't know if it makes a difference but, I am using Excel2000.
I figured out the referencing. Now just give me a chance to try it and I'll get back to you. Thanks
Just curious..

Why would this fail?

If xl Is Nothing Then
    Set xl = New Excel.Application
   

also noticed "New" ... does this allow user to have Excel open in another window?
ture,
   As of now, I have only a few questions.
Given that I know that
     wb.Save
    wb.Close
    xl.Quit
    Set xl = Nothing
 
are all executing, The application does not close excel completely and thus I can not get at the data unless I force quit.

1. How do I completely close out of excel?

2. Can and how do I get at the spreadsheet while the program is running?

3.Every time I quit, it says the file already exists, "Do you want to replace it". I want the program to auotmatically replace the old file.

Thanks Again,
       Crono15M
ture,
   As of now, I have only a few questions.
Given that I know that
     wb.Save
    wb.Close
    xl.Quit
    Set xl = Nothing
 
are all executing, The application does not close excel completely and thus I can not get at the data unless I force quit excel.

1. How do I completely close out of excel?

2. Can and how do I get at the spreadsheet while the program is running?

3.Every time I quit, it says the file already exists, "Do you want to replace it". I want the program to auotmatically replace the old file.

Thanks Again,
       Crono15M