With...End With: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
(Added javascript snippet and a better way to do it in javascript)
No edit summary
Line 15: Line 15:
Dim theURL, theTitle
Dim theURL, theTitle
With document
With document
  theURL = .URL
  theURL = .URL
  .title = "New Title"
  .title = "New Title"
  theTitle = .title
  theTitle = .title
   document.write(.URL & "<br>")
   document.write(.URL & "<br>")
   document.write(.title & "<br>")
   document.write(.title & "<br>")
Line 32: Line 32:
var theURL, theTitle;
var theURL, theTitle;
with (document) {
with (document) {
  theURL = URL;
  theURL = URL;
  title = "New Title";
  title = "New Title";
  theTitle = title;
  theTitle = title;
   document.write(URL + "<br>");
   document.write(URL + "<br>");
   document.write(title + "<br>");
   document.write(title + "<br>");
Line 42: Line 42:


(function($){
(function($){
      theURL = $.URL;
    theURL = $.URL;
      $.title = "New Title";
    $.title = "New Title";
      theTitle = $.title;
    theTitle = $.title;
      document.write($.URL + "<br>");
    document.write($.URL + "<br>");
      document.write($.title + "<br>");
    document.write($.title + "<br>");
  }(document)
  }(document)
);
);
</pre>
</pre>

Revision as of 06:43, 12 May 2013

With object

[statements]

End With

Description

With allows you to do a series of operations on an object without having to name the object each time.

Example (Basic)

Rem With sample
'With statement allows accessing properties on a specified object

Dim theURL, theTitle
With document
  theURL = .URL
  .title = "New Title"
  theTitle = .title
  document.write(.URL & "<br>")
  document.write(.title & "<br>")
End With

Example (JavaScript)

// With sample
/* With statement allows accessing properties on a specified object */

var theURL, theTitle;
with (document) {
  theURL = URL;
  title = "New Title";
  theTitle = title;
  document.write(URL + "<br>");
  document.write(title + "<br>");
}

/* a better way to perform With */

(function($){
    theURL = $.URL;
    $.title = "New Title";
    theTitle = $.title;
    document.write($.URL + "<br>");
    document.write($.title + "<br>");
  }(document)
);

Output

File:///C:Browse.htm
New Title