Question JAVASCRIPT to VB.NET

chikka_gurl143

New member
Joined
Sep 3, 2013
Messages
2
Programming Experience
Beginner
Hello VB.NET experts!

I am barely new to VB.net myself. I am currently working on an IP camera SDK which is in JAVASCRIPT and I have to find a way to "translate" it so I could use it in the VB.net application that I am trying to develop.

I need help on the following. I need help on implementing this in VB.net

VB.NET:
function getHTTPReq(){
	//Create Http Request Object
	var req;
	if( window.XMLHttpRequest) req = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{
		var msxmls = [ "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
		for(i=0; i<=msxmls.length-1; i++)
		{
			try
			{
				req = new ActiveXObject(msxmls[i]);
				break;
			} catch(e) {	}
		}
	}
	return req;
}






function GetPlaybackId() {
    
    getPbGidHttpReq=getHTTPReq();
    if (typeof(getPbGidHttpReq)=="undefined") return;
    
    getPbGidHttpReq.onreadystatechange=GetPlaybackId_OK;


//strCMD is the camera xmlcgi command 


    getPbGidHttpReq.open("GET",strCMD, true);
    getPbGidHttpReq.send(null);
}


function GetPlaybackId_OK() {
    if (getPbGidHttpReq.readyState == 4) 
	{
		if(getPbGidHttpReq.responseText.indexOf('RET="0"')!=-1) 
		{
			var xmlResponse = fnStringtoXML(getPbGidHttpReq.responseText);
			PbGroupId = xmlResponse.getElementsByTagName("GroupID")[0].text;
	    }	
	}
}



Here's what I use and actually works - but not always.

VB.NET:
    Public Function GetHTMLSource(ByVal sURL As String) As String        Dim xmlHttp As Object
        xmlHttp = CreateObject("MSXML2.XmlHttp")
        xmlHttp.Open("GET", sURL, False)
        xmlHttp.Send()
        GetHTMLSource = xmlHttp.responseText
        xmlHttp = Nothing
    End Function

And use :

Call getHTMLSource(strCmd)

***
My problem is that sometimes I issue a cgi command (which would reflect on the strCmd variable) and not get the result that I need.
I need to be able to detect the change in state of my request and perform necessary actions. With the code that I am using now, sometimes it works the way it should be and sometimes it doesn't.

Anyways, if what I am saying is confusing, I just badly need to implement creating and detecting readystatechange of an xmlhttp request in VB.net.

Thank you that you would try to help me.
 
You can use XDocument.Load to load the xml document. VB and .Net has excellent support for working with Xml.
 
Not convert exactly - but I want to know how it is implemented on VB.net. I know how to interact with the browser - it is just that I can't seem to track changes in its state (i.e. the browser has already responded and the code is ok; or if the browser is taking a time to respond) which is very important because sometimes, I issue command and I am not getting the desired result.

Conejo, I appreciate your response. I will look into the links that you have provided. Thank you.

- Joycenel
 
Back
Top