Short solution for short problems

VBS: debug vbs scripts using Visual Studio

These days they are becoming very rare, but sometimes you can still find them doing some important work on some server somewhere in your company.

The database changes and the script doesn't react anymore as it should. What now? Try and error? Or can we actually still debug that script using Visual Studio?


Just use the cscript command with //X and your file as attribute:

C:\temp\vbs>cscript //X test2.vbs

Now a visual studio selector window pops up, select the version you want and debug the script!

In my case I had to comment some lines like where mails where sent. And I had to make sure the ODBC connection was defined.


Google: Adsense responsive add

Google has this responsive adds which are crucial to use on a responsive web page. So I changed them on this new Blog layout.

And then in smaller screens:

Same post, same add frame (different add). But you see that the height has increased and the width has decreased.

The message recieved was unexpected or badly formatted.

After settings up a new Azure Server with MSSQL 2014, we couldn't connect to the server.

After some research it appeared to be because .Net 4.5.1 was giving problems. On my machine it was solved by removing the .Net Framework 4.5.1 and installing the .Net Framework 4.5.2. No need to reboot even. On another PC, we had to rebuild the .Net Framework using the regiis tool describer here:

AngularJS: Back Button

Something simple, though not yet default in Angular + $stateprovider.

How to go to the previous state?

Lots of posts, easy solution. The best one yet is to save the previous state in the state itself when a state change was succesfull.

Just add these 3 lines to your app.run:

$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
	$state.previous = fromState;

Now the previous state is already saved and can be accessed anywhere the state is injected:

$scope.goBackToProject = function () {
	console.log('Back to: '+$state.previous);

And just call it onclick:

<button ng-click="goBackToProject()" class="btn btn-danger" type="button"><span class="glyphicon glyphicon-step-backward"></span> Back</button>

That's it!

AngularJS: UI router, subviews and passing parameters to controllers

I was struggling a while with AngularJS to have nested views and pass data between the controllers behind the views. The obvious and easy solution would be to set a variable in the rootscope and get in the other controller. That works fine until you are working with collections in collections.

My example looks like this:


The problem was that a Project had a collection of Zones. For the project, I created a view and a Controller. Now first I thought of using 1 view and 1 controller to show all the project with its zones and subzones. (btw each level can have pictures and properties).


1) It could not be accomplished simple with the current model, because the model was not loading its child objects. I could start building up the model in JavaScript and at the end bind it.

E.g. selectedProject.zones[0].subzones[0].pictures = getPictures()

But then I had to loop over all the child objects and get them from the server. I also had to rewrite a lot of code and could not reuse any view.


2) I could also enable the model on the server to load all its siblings, but that would be too easy. I wanted to solve it the hard way, only to learn more from AngularJS and its UI-Router.

If I loaded everything on the server, I also couldn’t reuse the current views, but still in my case it would have been the best solution.


3) Use the UI-router and nested views.

The challenge here was that I had to pass parameters to the nested controllers. When I loop over the Zones, I have to pass the zone_id to the ZoneController. To solve this, I ended up using the ng-init directive. This will init a variable in the scope of the controller before its loaded. So this is perfect!

<div class="panel panel-info">

    <div class="panel-heading">Zones</div>

    <div class="panel-body"ng-repeat="z in projectToPrint.zones">

        <div ui-view="zoneDetails@projectsfull"ng-init="zoneToPrint = z"></div>




The StateProvider configuration it looks like this (For the moment only projects and zones, but the rest will use the same principle):






















Now for every zone a $scope is created and the zoneToPrint is set to the child zone.

Using this I can get sub collections in my controller

if($scope.zoneToPrint !=null){

    if($scope.zoneToPrint.pic_id !=null){

        picturesService.getPictures($scope, $scope.zoneToPrint.pic_id, APIGeneralSettingsService);



        $scope.pictures =null;


    if($scope.zoneToPrint.prop_id !=null){

        propertiesService.getProperties($scope, $scope.zoneToPrint.prop_id, APIGeneralSettingsService);



        $scope.properties =null;



and bind them:

<div class="panel panel-info">

    <div class="panel-heading">Pictures</div>

    <div class="panel-body"ng-repeat="p in pictures">

        <div><b>ID:</b> {{ p.pic_id }}</div>

        <div><b>Seq:</b> {{ p.pic_seq }}</div>

        <div><b>Url:</b> {{ p.pic_onlineurl }}</div>

        <div><b>Date:</b> {{ p.pic_created|date:'yyyy-MM-dd' }}</div>

        <div href="#"class="thumbnail">

            <img class="img-responsive"ng-src="{{p.pic_onlineurl}}"

                 alt="{{p.pic_id }}">




 also I can bind this variable to the view:

<div class="panel panel-info">

    <div class="panel-body">

        <b>Id:</b> {{zoneToPrint.z_id}}


    <div class="panel-body">

        <b>Titel:</b> {{zoneToPrint.z_title}}


    <div class="panel-body">

        <b>Info:</b> {{zoneToPrint.z_info}}


    <div class="panel-body">

        <b>Date:</b> {{zoneToPrint.z_date|date:'yyyy-MM-dd' }}


    <div ui-view="propertyList@zoneDetails@projectsfull"></div>

    <div ui-view="pictureList@zoneDetails@projectsfull"></div>


Above you can also see that the pictures and properties are in a subview, but not controller defined, so just using the same scope!



The ng-init will happen before the controller is loaded, so the zoneToPrint is set for each zoneController. Based on this, the correct binding will happen. Works perfect.

JSON & EF: Error Self referencing loop detected for type System.data.entity occurs .

I got this error when I started to add the navigation properties to the entities. Because a master detail relation has got 2 kinds of navigation properties. The master gets the collection of childs and the child gets the master where it belongs to. JSON serialization will end up in a circular loop, since it serializes the child, then tries to serialize the parent, but this has a collection of child etc.

You can solve this many ways.

- If you do not need the parent navigation property, you can remove it. 

- You could set an attribute to the property: [JsonIgnore] [IgnoreDataMember]. The problem here is when you use the generated classes, the next time you generate it will be removed.

- Set lazy loading on your context to false: db.Configuration.LazyLoadingEnabled = false;

In my case I chose the first one, since the parent did not need to know about it's children.  

ios: Website not responsive on iphone

I'm making a back-end website that is Angular + Bootstrap. So this should work on practically all browsers. 

On my develop machine, the site works perfect, responsiveness is good, when I resize the browser, the site reacts. But on my iPhone the site always opened zoomed out. So too small to read. I was expecting it to react responsize.

This problem was solved by adding this meta tag:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

Make sure also to clear the browsing history.