Link to home
Start Free TrialLog in
Avatar of faisalkh
faisalkh

asked on

ASP.net - VB.net Array

Hello,

I am trying to capture the HTTP Response, parse it and take appropriate actions based on the recieved data.

I hope someone can advise how can I go about doing this correct.

The response I get from the URL is

OK:22059

OR

OK:22059
OOS:2745
OOS:2752
OOS:2745
OOS:2752

If its only OK:22059, then I can easily capture and store it in the DB, the problem is when the response in more than 1 line.

 Dim NetResultString() As String
If Not ResponseString Is Nothing And ResponseString <> "" Then
   If ResponseString.Contains("OK") Then
   	NetResultString = ResponseString.Split(Environment.NewLine)
        TransactionID = NetResultString(0).Substring(NetResultString(0).IndexOf(":") + 1, NetResultString(0).IndexOf(vbLf) - NetResultString(0).IndexOf(":") - 1)
   	If (TransactionID <> "") AndAlso (PrevOrderID <> OrderID) Then
   		UpdateWebOrderStatus(OrderID, "ORDER_SAVED_ON_Net", "WebSystem")
   		AddOrderNotes(OrderID, "Order Detail Saved Successfully. Net TransID: " & TransactionID, "WebSystem")
   	End If
   	If NetResultString(1) <> "" Then
   		LineItemID = NetResultString(1).Substring(NetResultString(0).IndexOf(":") + 1, NetResultString(1).IndexOf(vbLf) - NetResultString(1).IndexOf(":") - 1)
   		UpdateWebOrderStatus(OrderID, "ORDER_Net_MANUAL_STOCK", "WebSystem")
   		AddOrderNotes(OrderID, "Partial Order Detail Saved On Net Due To An Out Of Stock Item. ProductID: " & GetProdIDByNetID(LineItemID), "WebSystem")
   		CommonFunctions.SendEmail(My.Settings.AdminEmailAddress, My.Settings.OfficeAdminEmailAddress, "Net URL Data Post Error - Unable to save an Item record.", GetProdIDByNetID(LineItemID) & " is out of stock")
        End If
        ' NetResultString(2) 
        ' NetResultString(3) 
        ' NetResultString(4) 
   End If       
End If

Open in new window


I hope can someone advise how can I loop it through the array object so that if they more than 1 OOS item, it will do the same thing for all.

Thanks
F
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Try following

For Each response in ResponseString.Split(VBCRLF)
    'Above code here to deal with each line of response string
Next
Avatar of faisalkh
faisalkh

ASKER

Hi,
I have tried that but it will only pick the first string from the below ie: "OK:22067" and come out of the loop.
>> Response = "OK:22067OOS:2752"
I am trying to loop it through so that next time it should go to the next if condition
ThanksUser generated image
Dim Response As String

For Each Response In ResponseString.Split(vbCrLf)
   If Response.Contains("OK") Then   	 
        TransactionID = Response.Substring(Response.IndexOf(":") + 1, Response.IndexOf(vbLf) - Response.IndexOf(":") - 1)
        AddOrderNotes(OrderID, "Order Detail Saved Successfully. Net TransID: " & TransactionID, "WebSystem")
   	
   ElseIf Response.Containts("OOS") Then
   	LineItemID = Response.Substring(Response.IndexOf(":") + 1, Response.IndexOf(vbLf) - Response.IndexOf(":") - 1)  		 
   	AddOrderNotes(OrderID, "Partial Order Detail Saved On Net Due To An Out Of Stock Item. ProductID: " & GetProdIDByNetID(LineItemID), "WebSystem")
   		
   End If       
End If

Open in new window

>>> Response = "OK:22067OOS:2752"

That's because there does not seem to be a line break between the elements.
Please can you see the attachment? You will notice that there is a carriage return between the strings

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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