Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock Help 1

Status
Not open for further replies.

UKmedia

Programmer
Nov 2, 2002
90
0
0
Hey All,

I have an application that is receiving a reponse from another program. The program sends it's response as:

1=9
0=999

Now the reponse is not always the same and I want to use a select case to read the reponse.

Code:
Dim strReceive
Winsock1.GetData strReceive
txtReceive.Text = strReceive

Select Case

Case strReceive

Case ""
lblResponse.Caption = "Good"

Case ""
lblResponse.Caption = "Bad"

Case ""
lblResponse.Caption = "Complete"

Case Else 
        lblResponse.Caption = "Unknown Response" 

End Select

Now I know what all the reponse codes are but in the Case "" if I put Case "3=999=0" it will not work as the data coming in is on 2 lines.

How can i split the data going in and show this inb each case.

Cheers

UKmedia productions
 
You may not need to split the two lines which I guess are delimited by a vbCr; Just check for the included vbCr (or VbCrLf)

Select Case strReceive

Case "1=9" & vbCr & "0=999"
lblResponse.Caption = "Good"

'etc

Case Else
lblResponse.Caption = "Unknown Response"

End Select
 
Morning,

I have tried that and it does not work also tief it with vbCrLf and that does not work either

UKmedia productions
 
You'd better examine the contents of each character in strReceive to see what it actually contains; with something like..

For i = 1 to Len (strReceive)
Debug.print Asc(Mid$(StrReceive,i,1)) & vbCrLf
Next

This should reveal the actual delimiter(s) between the two lines and any spaces (ascii 32s) that may be present.
 
So the line seperator is vbLf

(and the particular repsonse you've got here is: "3=9" & vbLf & "99=0")
 
nope that has not worked either.

from you last code this is the exact response I get:

51

61

57

10

57

57

61

48

Not sure if the spacing is meaning anything


UKmedia productions
 
Debug.Print Chr$(51); Chr$(61); Chr$(57); Chr$(10); Chr$(57); Chr$(57); Chr$(61); Chr$(48)

tells me that your data is equal to;

3=9
99=0

and that it is delimited with an ascii 10 i.e. a vbLf

so try stuff along the lines of;

Select Case strReceive

Case "1=9" & vbLf & "0=999"
lblResponse.Caption = "Good"

'etc

Case Else
lblResponse.Caption = "Unknown Response"

End Select
 
I am sorry if I am being a pain in the butt but I understand where you aree coming from here but this is not working.

I have posted my code for you to see if I have missed anything.

Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim strReceive As String
Winsock1.GetData strReceive

Select Case strReceive

Case "1=9" & vbLf & vbLf & "0=99"""
lblResponse.Caption = "Cancelled By User"

Case Else
lblResponse.Caption = "Unknown Response"

End Select

End Sub

UKmedia productions
 
This is my last; it is working

Private Sub Command1_Click()

Dim strReceive As String
strReceive = Chr$(51) & Chr$(61) & Chr$(57) & Chr$(10) & Chr$(57) & Chr$(57) & Chr$(61) & Chr$(48)

Select Case strReceive

Case "3=9" & vbLf & "99=0"
lblResponse.Caption = "Good"

'etc

Case Else
lblResponse.Caption = "Unknown Response"

End Select

End Sub
 
sorry back to this little problem again.

Now I have this part done looking at the response codes they are coming in a little long and I only want to read a certain area from the reponse.

Just to let you know it is a cerdit card response I am getting and it reads like so:

if the transaction failed then it sends 3=9 but if the trans was good then it sends

7=1111111111
29=A00000000313131
6=Mastercard 'Card Type
10=UKMedia 'Customer Name On Card

etc...

All I was to read is 3= status of trans.

How can I split this and only read the 3=

?????


UKmedia productions
 
Several methods are available to you here are some of them;

Option Explicit

Private Sub Command1_Click()

Dim strResponse As String
Dim ReqResponse As String

strResponse = "123=456"

'one
ReqResponse = Split(strResponse, "=")(0)
Print ReqResponse
'two
ReqResponse = Left$(strResponse, InStr(strResponse, "=") - 1)
Print ReqResponse
'three
ReqResponse = CStr(Val(strResponse))
Print ReqResponse

End Sub

vbhelp is your friend.
 
thank you for your response.

I am understanding this honest

All the data that comes in the only thing I am intrested in is the 3=

so

3=1 'card appoved
3=3 'card declined
3=2 'appoved offline
3=4 'Talk to bank

so the only line I am intrested in the whole reponse is 3=status

of course I need to get the whole reponse and then filter out only the 3=

any ideas?



UKmedia productions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top