READING STUDENTS

The list of students will be the "multiplayer appication" of our system.

It will be possible to see it inside a 3D space. The users (beeing avatares) can talk about its content, refresh it etc.

But first of all we will create this application beeing a "single-player application". The "magic" of Cobalt is to transform "single-player applications" into "multiplayer appications" adding a new layer over them.

The "Cobalt part" of the application is very easy. Glued to the Button we have an script that sends a message to the server starting an ASPX program. Remember that we have, inside an ScrollingText object (StuList, here) another object: StuListText, here. Pay attention to the detail of the versions of controls.

| page parsedPage thebody clean |
StuListText4 setCharacters: 'Searching the database.Wait... '.

page:=HTTPSocket httpGet:'http://www.dmu.com/croquet/readstudents.aspx'.
parsedPage := HtmlParser parse: page. 
thebody := parsedPage body.
clean := thebody   contents at:1 .  
clean := clean  asString .
clean := clean copyReplaceAll: '[' with:''. 
clean := clean copyReplaceAll: ']' with:''. 
clean := clean  copyReplaceAll: '#' with: '\'.
clean := clean  copyReplaceAll: ':' with: ''.
StuListText4 setCharacters: clean withCRs.
StuList setLength: 100. 
StuList setLength: 300.

This data received will go to StuListText, respecting the "carriage returns".

The two final lines are a "trick" to do the appearance of the ScrollBar.

Look the code of the ASPX application (readstudents.aspx) in JavaScript .NET, uploaded to our Windows server:

<script language="JavaScript" runat="server">
function Page_Load(sender:Object, e:EventArgs):void{
 var msg;
 msg = readDB();
 Response.Write(msg); 
}
function readDB(){ 
var select = "SELECT * FROM students";  
 //The connection
 var oConn:System.Data.OleDb.OleDbConnection = new System.Data.OleDb.OleDbConnection(); 
 oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/data/croquet101.mdb"); 
 try{   
  oConn.Open(); 
  //The DataSet creation
  var ds:System.Data.DataSet  = new System.Data.DataSet(); 
  var datadapt:System.Data.OleDb.OleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter(select, oConn); 
  datadapt.Fill(ds, "stu"); 
  var dsT:System.Data.DataSet  = new System.Data.DataSet();
  dsT = ds; 
  var list = new String("");
  var pad : char = " ";
  for(var i=0; i<dsT.Tables["stu"].Rows.Count; i++){
 list = list + dsT.Tables["stu"].Rows[i]["country"].ToString().Replace("_"," ").PadRight(20, pad) + ":"
            +  dsT.Tables["stu"].Rows[i]["name"].ToString().Replace("_"," ")  + "#";
  //All this needs to be in one line, please!
 }
 //To erase the last separator - we don't need it:
 list=list.slice(0,list.lastIndexOf("#"));
 return list;
}
 catch(e:Exception) {
  //Write the error, if we have one
  return "Error: "+  e.ToString();
 }
 finally{
  //having error or not we close the connection, a good pratice
  oConn.Close();
 }
}
</script>

To teach ASPX is out of the scope of this course but, for your information:

If you like, you can do the exercice of this lesson and use our server for the access to the ASPX script. Our server is free available for tests.

In the video we will see the "single-player application" working. Look the two final lines having the students we have added in the previous lesson.

In the next lesson we will see how to transform this application, to be a "multiplayer appication" inside a Cobalt 3D space.


PREVIOUS LESSON NEXT LESSON
TABLE OF CONTENTS HOMEPAGE