CSocket - DataArrival Not Occurring (GET Request) - http

I'm attempting to do a GET request in VB6 using CSocket. The data is sent successfully however no response is received (tested on multiple sites). My code is below.
Option Explicit
Dim WithEvents WinSock As CSocket
Private Sub Form_Load()
Set WinSock = New CSocket
End Sub
Private Sub btnConnect_Click()
WinSock.Protocol = sckTCPProtocol
WinSock.Connect "winhome.de", 80
MsgBox "Connecting..."
End Sub
Private Sub WinSock_OnConnect()
MsgBox "Connected."
Dim Data$
Data = "GET http://www.winhome.de/index.html HTTP/1.0" & vbCrLf & "Accept: */*" & _
vbCrLf & "Accept: text/html" & vbCrLf & vbCrLf
WinSock.SendData Data
MsgBox Data
End Sub
Private Sub WinSock_OnDataArrival(ByVal bytesTotal As Long)
Dim Data$
WinSock.GetData Data, vbString
MsgBox Data
End Sub
The OnConnect event never seems to trigger, but works fine with a normal WinSock control, Any help?

For these scenarios you don't want any "blocking" debugging, including MsgBox or IDE breaks -- the events get lost.
E.g. accumulate your debug logs into a string or a file and look at the results after a run.

Related

Access 2010 using DoCmd.SendObject to send email

Using Access 2010, I have created a form that is functioning as a directory. I want to be able to click on a name field and send an email to that person. I have it working for one name on the directory but the second and third names fields give me the following error: Compile error: Method or data member not found. The highlighted portion of the code is: Private Sub AA2Name_Click(), while Me.AA2Email is highlighted in blue.
The full code is:
Private Sub AA1Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA1Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA2Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA2Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA3Name_Click()
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=Me.AA3Email
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Thank you to anyone that can help!
I've recreated as best I can what from you've described above and it all ran ok for me. You can have a look at what I've got here for clues; use the frmEmails - original VBA form.
The only thing I can think of is that you may have mistyped Me.AA2Email somewhere? Perhaps check the Name property of the control this is meant to refer to... does it appear in intellisense?
On a side note: I've created another version of the same form in that file called frmEmails - updated VBA. Here I've arranged your VBA so you're not duplicating so much code. Essentially it runs all the common code in to 1 subroutine, passing in the varying email field as an argument. This doesn't solve your problem, but I thought it was worth adding.
Public Sub ComposeEmail(ToField As String)
On Error GoTo Err_Handler
DoCmd.SendObject acSendNoObject, To:=ToField
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
Private Sub AA1Email_Click()
ComposeEmail Me.AA1Email
End Sub
Private Sub AA2Email_Click()
ComposeEmail Me.AA2Email
End Sub
Private Sub AA3Email_Click()
ComposeEmail Me.AA3Email
End Sub

Button Event isn't displaying value until 2nd click (vb6)

I created a tcp connection in vb6 to grab the weight off of a scale and display that weight after pressing a button. The problem is that the weight is not displayed until the SECOND (2nd) click of the button, not the first. I have set a break point in various spots and upon the first click of the button, it takes me to that break point, so I know the event is firing as it should, but nothing is displayed until the 2nd click. I have done a bunch of research but can't seem to find anyone with the exact problem (or solution).
Public tcpC As New Winsock
'Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CFixPicture_Close()
tcpC.Close
End Sub
Private Sub CFixPicture_Initialize()
tcpC.LocalPort = 0
tcpC.Connect "192.168.0.1", 8000
End Sub
Private Sub CommandButton1_click()
On Error GoTo errHandler
Dim strData As String
tcpC.SendData "S" & vbCrLf
tcpC.GetData strData
Text1.Caption = "Weight: " & strData
Exit Sub
errHandler:
MsgBox "error:" & Err.Description
End Sub
I am making an assumption that your code is in the form and you are just declaring a new object of type Winsock. My code declares a Winsock variable using the keyword WithEvents to get access to the events raised by the Winsock object. The particular event you're interested in is DataArrival. It is fired by the Winsock control when data is received. I moved setting the text to this event. Also, you cannot use WithEvents and "As New" (you really don't want to use As New anyway), so I create the object before I set the properties in the CFixPicture_Initialize() method. Finally, I added setting the object to nothing after closing it.
Option Explicit
Private WithEvents tcpC As Winsock
Private Sub CFixPicture_Close()
tcpC.Close
Set tcpP = Nothing
End Sub
Private Sub CFixPicture_Initialize()
Set tcpC = New Winsock
tcpC.LocalPort = 0
tcpC.Connect "192.168.0.1", 8000
End Sub
Private Sub CommandButton1_click()
On Error GoTo errHandler
Dim strData As String
tcpC.SendData "S" & vbCrLf
'there is no data here yet - moved to the DataArrival event
'tcpC.GetData strData
'Text1.Caption = "Weight: " & strData
Exit Sub
errHandler:
MsgBox "error:" & Err.Description
End Sub
Private Sub tcpC_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpC.GetData strData
Text1.Caption = "Weight: " & strData
End Sub

vb.net if else logic flow error

I am debugging some code in an ASP.net web application project.
I have an If/Else statement nested in a Try/Catch block. Whenever an error occurs within the If block, rather than immediately jumping into the Catch block, it falls into the Else block.
I have stepped through the code repeatedly to witness this happening. When I throw an exception within the if block, I would expect logic to flow into the catch block, and I would never expect to see the if block get hit, and then the else block get hit, that seems to completely defeat the purpose of the if/else logic.
Here is the code in question:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadDocument()
End Sub
Private Sub LoadDocument()
Dim taDocuments As New SecureTableAdapters.IndividualDocumentsTableAdapter
Dim dtDocuments As New Secure.IndividualDocumentsDataTable
Dim iDocumentID As Integer = CInt(Request.QueryString("iDocumentID"))
Dim sFileName As String
Dim isMac As Boolean = clsApplication.isMac(Request.Browser.Platform)
Dim bDownloaded As Boolean = False
Try
If taDocuments.FillBy_IndividualDocumentID(dtDocuments, iDocumentID) > 0 Then
Dim oRow As Secure.IndividualDocumentsRow = dtDocuments.Rows(0)
sFileName = "Statement-" & oRow.sFileNumber & ".pdf"
If oRow.sDocumentName.ToUpper.Contains("LEDES") Or oRow.sDocumentName.ToUpper.Contains("TEXT") Then
sFileName = sFileName.Replace("pdf", "txt")
End If
Dim b As Byte() = Nothing
If oRow.IsbExtractedNull = False AndAlso oRow.bExtracted Then
Dim sHost As String = "206.220.201.175"
Dim sPath As String = String.Format("/Legacy/{0}/{1}/{2}.pdf", oRow.iFirmID.ToString, "Individuals", oRow.iIndividualDocumentID.ToString)
b = DownloadDocument(sHost, sPath)
If b Is Nothing Then
'When this line is hit, logic jumps to the else block with the comment below
Throw New Exception("FTP Download Failed")
Else
bDownloaded = True
End If
Else
bDownloaded = False
End If
If bDownloaded = False Then
b = getImage(iDocumentID, "oPDF", "iIndividualDocumentID", "tblIndividualDocuments")
If b Is Nothing Then
Throw New Exception
End If
End If
If isMac Then
Response.ContentType = "application/x-macbinary"
Else
Response.ContentType = "application/octet-stream"
End If
Response.Expires = 0
Response.AddHeader("Content-Disposition", "attachment; filename=""" & sFileName & """")
Response.BinaryWrite(b)
Else
'--->When the exception occurs, logic jumps to this else block
Throw New Exception
End If
Catch ex As Exception
Response.Write("Sorry, that statement could not be located. Please try again, or call us at xxx.xxx.xxxx for further information.")
clsApplication.EmailError("An error occurred downloading a statement: " & vbCrLf & ex.Source & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
How is this possible?
It sounds like you're using the debugger with Optimizations still turned on. This can cause the Step Traceing to act in seemingly illogical and even impossible ways. This is caused because after the optimizer moves the code and variables around and consolidates different statements, there is no longer a simple or straight-forward relationship between the lines of source-code and the executable instructions.
Sounds like the code you're debugging against might be out of sync with the code that's executing. Try rebuilding the whole solution.
I think you are probably mistaken:
Try the following in simple vb .net winforms program.
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Dim doIt As Boolean = True
If doIt Then
Throw New Exception("throwing that stuff")
Else
MsgBox("in here - how did that happen?")
End If
Catch ex As Exception
MsgBox(String.Format("That makes sense. Exception is: {0}", ex))
End Try
End Sub
End Class

VB.NET Custom Errors Messages

I like to user custom errors in my site.
The Idea is to trap errors and display friendly meaningful messages to users.
The real error details (line number, Page ...) will sent to me by e-mail.
I am programming in VB.NET.
Until now every code that i found about this say's that i must use the global.asax for it.
I do not like to use global.asax, I just like to make an error page that will sent me a -email with all the error details.
Until now, i go to the web.config file and insert this line:
<customErrors defaultRedirect="test.aspx" mode="On"></customErrors>
test.aspx looks like this:
Sub Page_Error(sender as Object, e as EventArgs)
Dim ctxOBJ As HttpContext
Dim exceptionOBJ As Exception
Dim errorInfoTXT As String
ctxOBJ = HttpContext.Current()
exceptionOBJ = ctxOBJ.Server.GetLastError()
errorInfoTXT = "Offending URL: " & ctxOBJ.Request.Url.ToString() & _
"Source: " & exceptionOBJ.Source.ToString() & _
"Message: " & exceptionOBJ.Message.ToString() & _
"Stack trace: " & exceptionOBJ.StackTrace.ToString() & _
"Target Site: " & exceptionOBJ.TargetSite.ToString()
ctxOBJ.Response.Write (errorInfoTXT)
ctxOBJ.Server.ClearError ()
End Sub
When here is an error in some page its redirect me to test.aspx but not showing any error.
Thanks,
Roy Shoa.
You just need to change this to
Sub Page_Load(sender as Object, e as EventArgs)
It's not the error page that's erroring, so its error event never fires.

How to sort a gridview once a radio button is selected

I'm trying to sort records in the gridview right after a radio button is selected. My approach is with the dataview, but because the dataset variable doesn't survive a round trip to the server, I don't know how to make this happen. please help!
Public Sub GetCustomers()
db.RunProcedure("usp_customers_get_all")
db.doSort(radList.SelectedValue)
gvCustomers.DataSource = db.MyView
End Sub
Protected Sub radList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radList.SelectedIndexChanged
If radList.SelectedValue = 0 Then
db.doSort(0)
gvCustomers.DataSource = db.MyView
End If
If radList.SelectedValue = 1 Then
db.doSort(1)
gvCustomers.DataSource = db.MyView
End If
End Sub
Public Sub doSort(ByVal strIn As Integer)
If strIn = 0 Then
MyView.Sort = "lastname, firstname"
Else
MyView.Sort = "username"
End If
End Sub
Public Sub RunProcedure(ByVal strName As String)
Dim objConnection As New SqlConnection(mstrConnection)
Dim mdbDataAdapter As New SqlDataAdapter(strName, objConnection)
Try
mdbDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
Me.mDataset.Clear()
mdbDataAdapter.Fill(mDataset, "tblCustomers")
MyView.Table = mDataset.Tables("tblCustomers")
Catch ex As Exception
Throw New Exception("stored procedure is " & strName.ToString & " error is " & ex.Message)
End Try
End Sub
You could store the dataset in one of the following places and then when the post back happens just load it again from there. I have done many of these on a corporate intranet.
Session Variable
ViewState
QueryString
Cache
I cant really provide more help as you didn't specify if this is done in Ajax or if you do a full postback etc. If you provide more info I would love to help you.

Resources