To read settings in a VB.NET WinForm application, you can use the My.Settings object. My.Settings is a strongly typed class that provides access to the settings defined in the project’s Settings.settings file.
Here’s an example of how you can use My.Settings to read a setting:
Dim settingValue As String = My.Settings.SettingName
Private Sub ParseXML()
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(“NavaFP01000012022-12-170.00.00.0S C 10 %0.0C.Gst 2.5 %0.0S.Gst 2.5 %0.0NcSale“)
Dim xmlNode As XmlNode = xmlDoc.SelectSingleNode(“Records/Record”)
If xmlNode IsNot Nothing Then
Dim posName As String = xmlNode(“POSName”).InnerText
Dim billNo As String = xmlNode(“BillNo”).InnerText
Dim date As String = xmlNode(“Date”).InnerText
Dim time As String = xmlNode(“Time”).InnerText
Dim subTotal As String = xmlNode(“SubTotal”).InnerText
Dim discountAmount As String = xmlNode(“DiscountAmount”).InnerText
Dim grandTotalAmount As String = xmlNode(“GrandTotalAmount”).InnerText
‘ Access the Taxes node
Dim taxesNode As XmlNode = xmlNode(“Taxes”)
For Each taxNode As XmlNode In taxesNode.ChildNodes
Dim taxDesciption As String = taxNode(“TaxDesciption”).InnerText
Dim taxAmount As String = taxNode(“TaxAmount”).InnerText
Next
Dim settelmentMode As String = xmlNode(“SettelementMode”).InnerText
Dim transactionStatus As String = xmlNode(“TransactionStatus”).InnerText
End If
End Sub
Public Class Record
Public Property POSName As String
Public Property BillNo As String
Public Property Date As String
Public Property Time As String
Public Property SubTotal As Decimal
Public Property DiscountAmount As Decimal
Public Property GrandTotalAmount As Decimal
Public Property Taxes As List(Of Tax)
Public Property SettelementMode As String
Public Property TransactionStatus As String
End Class
Public Class Tax
Public Property TaxDesciption As String
Public Property TaxAmount As Decimal
End Class
Imports System.Xml
Private Function ParseXML(xmlString As String) As Record
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(xmlString)
Dim xmlNode As XmlNode = xmlDoc.SelectSingleNode(“Records/Record”)
If xmlNode IsNot Nothing Then
Dim record As New Record()
record.POSName = xmlNode(“POSName”).InnerText
record.BillNo = xmlNode(“BillNo”).InnerText
record.Date = xmlNode(“Date”).InnerText
record.Time = xmlNode(“Time”).InnerText
record.SubTotal = Decimal.Parse(xmlNode(“SubTotal”).InnerText)
record.DiscountAmount = Decimal.Parse(xmlNode(“DiscountAmount”).InnerText)
record.GrandTotalAmount = Decimal.Parse(xmlNode(“GrandTotalAmount”).InnerText)
‘ Access the Taxes node
Dim taxesNode As XmlNode = xmlNode(“Taxes”)
record.Taxes = New List(Of Tax)()
For Each taxNode As XmlNode In taxesNode.ChildNodes
Dim tax As New Tax()
tax.TaxDesciption = taxNode(“TaxDesciption”).InnerText
tax.TaxAmount = Decimal.Parse(taxNode(“TaxAmount”).InnerText)
record.Taxes.Add(tax)
Next
You can use the System.Net.Http namespace in .NET to send a REST API GET request and retrieve the XML response. To parse the XML response into a class object, you can use the code I provided in my previous answer.
Imports System.Net.Http
Private Async Function GetXMLAsync() As Task(Of String)
Dim client As New HttpClient()
Dim response As HttpResponseMessage = Await client.GetAsync(“https://your-api-endpoint.com”)
If response.IsSuccessStatusCode Then
Dim xmlString As String = Await response.Content.ReadAsStringAsync()
Return xmlString
End If
Return Nothing
End Function
Private Async Sub LoadXMLAsync()
Dim xmlString As String = Await GetXMLAsync()
If Not String.IsNullOrEmpty(xmlString) Then
Dim record As Record = ParseXML(xmlString)
‘ Do something with the Record object
End If
End Sub
Listing All Records
Private Function ParseXML(xmlString As String) As List(Of Record)
Dim records As New List(Of Record)()
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(xmlString)
Dim recordNodes As XmlNodeList = xmlDoc.SelectNodes(“/Records/Record”)
For Each recordNode As XmlNode In recordNodes
Dim record As New Record()
Dim taxNodes As XmlNodeList = recordNode.SelectNodes(“Taxes/Tax”)
For Each taxNode As XmlNode In taxNodes
Dim tax As New Tax()
tax.TaxDesciption = taxNode.SelectSingleNode(“TaxDesciption”).InnerText
tax.TaxAmount = Decimal.Parse(taxNode.SelectSingleNode(“TaxAmount”).InnerText)
public class MyHTTPServer extends NanoHTTPD {
public MyHTTPServer() {
super(8080);
}
@Override
public Response serve(IHTTPSession session) {
String msg = “
Hello from Android TV HTTP Server!
“;
return newFixedLengthResponse(Response.Status.OK, “text/html”, msg);
}
public static void main(String[] args) {
MyHTTPServer server = new MyHTTPServer();
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This code starts a HTTP server on port 8080 and returns a simple HTML message when a client makes a request to the server.
Here’s a simple example to demonstrate this:
On the mobile device, send an HTTP POST request to the Android TV’s IP address (e.g. http://192.168.0.100:8080/) with the text to be displayed as the body of the request.
On the Android TV, the web server can receive the request and extract the text from the body.
The extracted text can then be displayed on the TV screen using an Android view such as TextView.
import fi.iki.elonen.NanoHTTPD;
public class MyHTTPServer extends NanoHTTPD {
public MyHTTPServer() {
super(8080);
}
@Override
public Response serve(IHTTPSession session) {
Method method = session.getMethod();
if (Method.POST.equals(method)) {
try {
session.getInputStream();
Map files = new HashMap();
session.parseBody(files);
String text = files.get(“postData”);
// display the text on the TV screen
displayText(text);
String msg = “Text received: ” + text;
return newFixedLengthResponse(Response.Status.OK, “text/plain”, msg);
} catch (IOException | ResponseException e) {
e.printStackTrace();
}
}
return newFixedLengthResponse(Response.Status.BAD_REQUEST, “text/plain”, “Bad Request”);
}
private void displayText(String text) {
// code to display the text on the TV screen
}
public static void main(String[] args) {
MyHTTPServer server = new MyHTTPServer();
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
DECLARE @UserID INT = 1;
DECLARE @PrevQuestionID INT = NULL;
WITH PossibleQuestions AS
(
SELECT QuestionID, Question, Answer1, Answer2, Level
FROM Questions
WHERE PrevQuestionID = @PrevQuestionID
AND QuestionID NOT IN (SELECT QuestionID FROM UserAnswers WHERE UserID = @UserID)
),
Levels AS
(
SELECT MIN(Level) AS MinLevel
FROM PossibleQuestions
)
SELECT TOP 1 QuestionID, Question, Answer1, Answer2, Level
FROM PossibleQuestions
CROSS JOIN Levels
WHERE Level = MinLevel
ORDER BY NEWID();
Console.WriteLine(“Press enter to exit”);
Console.ReadLine();
}
}
}
This example creates a simple math service that can perform addition and subtraction operations, and makes it available over the network using the TCP protocol. The MathService class is decorated with the MarshalByRefObject attribute, which makes it possible to call its methods from a remote client.
The RPCServer project contains the code for the server, which registers the MathService class with the .NET remoting framework and makes it available over the network. The RPCCLient project contains the code for the client, which uses the .NET remoting framework to call methods on the remote MathService instance.