Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default two cool points for whoever can solve this one...winsock

I'm trying to make a VBA function in Excel which, given a unix command,
connects to a server I have created, runs the command, and then returns
the output. I have already written the server.


Example: A cell formula =UnixRun("echo hi") should have a value of
"hi".


Problem: My code (pasted below) works fine when I place a breakpoint at
the line "Do", then hit F5 to continue immediately after arriving
there. But if I run the code directly without a breakpoint, no data
ever comes back through the winsock GetData method. I considered that
the breakpoint may be allowing a
delay for the winsock object to start returning data, but even if I
enter a 3 second delay at the exact same point in the code as the break
point, still no data comes through. Therefore, I think the problem is
in the Winsock object. Any ideas to get around this? thx


Code:
If m_objWS.State = sckConnected Or m_objWS.State = sckOpen Then
m_objWS.SendData command & Chr(10)
DoEvents
' *** If I place the breakpoint on the next line, it works
' *** Without the break point, errCount increments to 100,000
' *** Adding in a 3 second wait instead of the
' *** breakpoint also fails.
Do
DoEvents
' first 4 bytes return a code for the #
' # of bytes to expect in this packet
m_objWS.PeekData output, vbString, 4
If (Len(output) = 4) Then
m_objWS.GetData output, vbString, 4
sizePacket = interpret_code(output)
m_objWS.GetData output, vbString, sizePacket
totalOutput = totalOutput & output
Else
' loop in case data hasn't arrived
sizePacket = 1
errCount = errCount + 1
End If
Loop While sizePacket 0 And errCount < 100000

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default two cool points for whoever can solve this one...winsock

Rob

If you're using Application.Wait, you may be suspending everything instead
allowing Winsock to catch up. Try

dim dStart as Date

dStart = Now

Do
DoEvents
Loop Until Now dStart + TimeValue("00:00:05")

This will wait five seconds, but will constantly relinquish control to any
other apps in the queue. I'd be interested to know if this works, so let me
know.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

wrote:
I'm trying to make a VBA function in Excel which, given a unix
command, connects to a server I have created, runs the command, and
then returns the output. I have already written the server.


Example: A cell formula =UnixRun("echo hi") should have a value of
"hi".


Problem: My code (pasted below) works fine when I place a breakpoint
at the line "Do", then hit F5 to continue immediately after arriving
there. But if I run the code directly without a breakpoint, no data
ever comes back through the winsock GetData method. I considered that
the breakpoint may be allowing a
delay for the winsock object to start returning data, but even if I
enter a 3 second delay at the exact same point in the code as the
break point, still no data comes through. Therefore, I think the
problem is in the Winsock object. Any ideas to get around this? thx


Code:
If m_objWS.State = sckConnected Or m_objWS.State = sckOpen Then
m_objWS.SendData command & Chr(10)
DoEvents
' *** If I place the breakpoint on the next line, it works
' *** Without the break point, errCount increments to 100,000
' *** Adding in a 3 second wait instead of the
' *** breakpoint also fails.
Do
DoEvents
' first 4 bytes return a code for the #
' # of bytes to expect in this packet
m_objWS.PeekData output, vbString, 4
If (Len(output) = 4) Then
m_objWS.GetData output, vbString, 4
sizePacket = interpret_code(output)
m_objWS.GetData output, vbString, sizePacket
totalOutput = totalOutput & output
Else
' loop in case data hasn't arrived
sizePacket = 1
errCount = errCount + 1
End If
Loop While sizePacket 0 And errCount < 100000



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Winsock.sendData Anand Nichkaode Excel Discussion (Misc queries) 0 October 7th 08 10:14 AM
winsock lag error [email protected] Excel Programming 0 February 9th 05 06:23 PM
Use winsock in Excel VBA Grey Excel Programming 0 May 25th 04 09:42 AM
Cannot get appropriate Event fired with WinSock control Tetsuya Oguma[_3_] Excel Programming 0 October 22nd 03 08:14 AM


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"