Sunday, April 17, 2011

How to sort multi-row entries in Excel?

So I have a document with many entries that follow this general format.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

What I want to do is to sort them by organization and treat the first rows as one entry so excel essentially thinks:

Organization Name Title Address Phone Fax

Description line 1

Description line 2

Organization's website.

is one row. I should also add that the bottom 3 rows are merged across the cells that form the row above them. Essentially I need it to work as a database but for government workers who are so technically unsavvy they can't upgrade to Office 2007 because the whole ribbon thing is "too confusing." So I am stuck using Excel 2002. I need to be able to sort them and use the top few rows above the actual chart to include a header and sub-heading.

From stackoverflow
  • Do you need the description/website rows to remain merged? If not unmerge to make it easier. You've tagged it as VBA but if this is a one-time fix then is it OK to manually work on the sheet?

    As a starting point I would suggest adding an identifier to each group of rows, and depending on your data quality you could do this by checking the website cell, or simply by counting rows. For example, you could insert a new column before your data and put the following in cell A2:

    =IF(Left(Lower(B1),4)="http",B2,A1)
    

    Where B1 (the row above) could be Organization, Description 1, Description 2, Organization's website, and if it is a website, we assume that on this new row we're starting with a new block of data so we'll take the organization name. If it isn't a website, we'll use the organization name we were using previously (A1 will need to =B1). Then copy that formula down until the end and the 4 rows will at least now have a common key which you can then use to mash around the data.

    If there are URLs which just start www. then modify the formula or better, just search/replace "www." to be "http://www." so that your data quality has improved.

    Alistair Knock : Possibly, particularly if there's likelihood of duplicate organisation names. Start A1=1, then formula =IF(Left(Lower(B1),4)="http",A1+1,A1)
  • Can't you just try recording a macro daoing whatver sort operation you want using UI, and then alanyze the code, and get an idea of what you need to do?

Psexec and calling batch files.

I'm going to try and break this down as simple as I can.

There are three computers involved. Local machine (LM), compute node (CN), and data node (DN) will be their names from here on out.

I have a psexec command which calls a batch file on the compute node.

psexec \\"compute node" -w WorkingDirectory BatchFileName

This BatchFileName sets some local variables then an executable which is located in the WorkingDirectory. This executable loads, but it has a configuration file which points to a bunch of files located on the data node. This is where my operation breaks down. If I run the batch locally on the compute node everything works fine. I'm merely trying to call it from a local machine using psexec instead. The same account name and password are used for all computers in this case.

The error I get is that it can't open the file located on the data node.

Batch file:

@echo off
setlocal
set VALUATION_DATE=20090313
set LiTEShome=C:\LiTES
ServiceConsole.exe
endlocal
exit /b 0

ServiceConsole.exe.config contains:

<add key="SomeName" value="\\Data Node\\Directory\\FileName"/>

Any help with this would be greatly appreciated.

From stackoverflow
  • Try

    psexec \"compute node" -w WorkingDirectory BatchFileName -u UserName -p Password
    

    with an account that has permissions on both nodes.

C++ or C# to program mobile barcode device?

I will be developing some applications using mobile barcode scanners and need to choose between C++ and C# for coding on the scanners.

I am considering Intermec's CK31 or similar for the combination of wifi, scanning choices, programmability and user interface options. It runs Windows CE .NET 4.2 according to their spec sheet.

Intermec's Developer Library comes with .Net and C++ SDKs. My previous Win CE 2003 experience is in C++ (MFC GUI, sockets and serial comms). I'm comfortable in C# with WPF and can learn other GUI frameworks if I have to. That gives me freedom to choose a language - any recommendations one way or another?

I am NOT looking for answers advocating C++ over C# as languages in general - my productivity in either is similar and I have enough experience to be able to create complex, robust C++ solutions.

What I would appreciate are war stories or factors to put into our platform evaluation, about programming on these devices. eg: battery life of C# apps vs C++ apps, memory consumption or other environmental impacts of the language choice. If there are specific versions of .Net CE to avoid, that would be a good tip.

From stackoverflow
  • I've been developing for about 15 years. Approx 5 years in C++ and 3 years in C# (which currently is my language of choice). In C++ I always used stdlib, and sometimes boost.

    I have cut my development time with a third since I switched from c++ to c#. That was done because of a couple of things (nothing scientific, just my opinons):

    1. .Net is a more complete framework and easier to use than stdlib and boost combined.
    2. C# has a better structure which make easier to read others code and to code.
    3. Unit testing in .Net is light years from unit testing in C++, especially with Resharper and xUnit (xUnit got clean syntax, resharper let's you test specific test methods directly inside dev studio).

    I mostly code servers, GUI programming should be even faster.

    Andy Dent : thanks for bothering to answer but you explicitly ignored my instructions in the question - I don't care about language opinions, just want some facts about mobile development.
  • The answer to your question has to do with the type of your application. If your application is mainly around communicating with the hardware and only a thin layer of business logic and User Interface is needed, then C++ would be a better choice. To interact with the scanners you need to talk to a driver. This is better and faster achieved with C++. The .NET SDK will actually be a wrapper of C++ code using a ton of P/Invoke, which makes the code performing less faster.

    If on the other side your application requires a significant business layer and/or a User Interface, then .NET (and specifically C#) is a better option. In that case the productivity gains far out weight the performance gains of C++.

    Another important factor is the type of the devices the application is going to be deployed to. Are you targeting Windows Mobile devices only? Then .NET is a safe option. For Windows CE devices you need to investigate whether the compact framework is pre-installed or not. Also, some Windows CE devices may not support all .NET namespaces.

    Finally, I recommend reading Mobile Architecture Pocket Guide, which is a recent document about architectural decisions for mobile applications.

    Andy Dent : Based on my own experience using C++/CLI called from C#, I question your assertion about the P/Invoke use in the SDK. Do you actually know this about their SDK or are you assuming?
    kgiannakakis : This is a general remark - I don't know the specific SDK. However, to communicate with a device driver, you need P/Invoke. It is impossible to do it with managed code. P/Invokes are probably hidden in dlls that you are referencing.
    Andy Dent : You're partly wrong. Try searching on device driver c++/cli to see hundreds of examples - C++/CLI gives a good alternative to using P/Invoke. It's not managed code but allows smooth bridging to C++ to call pure C.
    Andy Dent : Thanks for the link to the Mobile Architecture Pocket Guide.
  • I've been designing and developing software for Windows Mobile and Windows CE in C, C++ and C# for quite a few years now. Moreover, I been doing so for Honeywell (formerly Hand Held Products, purchased by Honeywell in 2007) where I've worked on nearly all aspects of the devices, from drivers and services to Line of Business GUIs and utilities.

    First of all, I won't tell you one language is better than the other... I probably spend a 50/50 split of my time with each, and each platform definitely has their own place in the mobile development.

    I will however, give a suggestion that you likely stay away from any device that runs an OS as old as WinCE 4.2, especially if you are even considering .NET development. The reasoning for this is that 4.2 only has, at most, .NET CF 1.0 embedded in ROM (part of the OS ROM image), meaning that you would require a ~5MB CAB file to install at least .NET CF 2.0 Yes, you could develop with CF 1.0 but, truly, it's not worth the pain of using such an old framework. Most WinCE 5.0 devices these days come with CF (Compact Framework) 2.0 installed in the ROM so I would at least look for that.

    On that same vain, you may even want to consider using a device with Windows Mobile 6.0 or 6.1 as they are easy to program with and will always have CF 2.0 pre-installed. In case you're wondering why I have not mentioned CF 3.0 or CF 3.5, it's just because the first Mobile platform to be release with those versions will be Windows Mobile 6.5, which is not out yet. Though you can always install the framework if you want (~8MB CAB).

    Granted, WinCE definitely gives you a more "Windows" look and feel to its GUI over its Windows Mobile cousin, so that is all a matter of your programming preference and what your end users want and need.

    Regarding kgiannakakis's comments on SDKs being only a thing layer, this is just not true. If you have a proper SDK you should have all of the same access to any devices or drivers that you would in C++ but with the ease of C#. For example, Honeywell provides an extensive SDK for all of our devices in C++, VB and C# and the C# portion of the SDK actually has more functionality than the C++ portion. You will never have to do a P/Invoke with our code from C#.

    If you want to take a look at the SDK I'm talking about, it's freely available to download here and has some great examples. IMHO I would actually consider the provided SDK as more important than the hardware in many cases since, most of the time, the hardware for the devices is pretty much the same. They all have ARM CPUs, WiFi, Bluetooth, Laser or Image based scanners, etc. Though, I looked at the Intermec link you posted and it doesn't look like that unit actually has a built in scanner...are you using an external scanner hooked to the device? Take a look at the Honeywell offering if you want here. We've got devices with probably the best imager based bar code scanner in the business, built into all of our units. And we have a rock solid SDK (I should know, I wrote a lot of it). And the SDK provides .NET extremely access to all of the hardware on the device. Ok...I'll stop my sales pitch now.

    As for one language over the other...it really all depends on what exactly you want to do.

    Drivers and services cannot be written in anything but Native (Win32) C or C++. So .NET is out for anything like that. C and C++ can absolutely be your friend on mobile devices in terms of keeping things lightweight, since you don't need the whole .NET framework to run the add. Remember,

    Andy Dent : Thanks. I love seeing someone else's enthusiasm for their work coming out despite incredible self-restraint :-) Evaluating devices has been interesting and it's early days. I agree with picking based on SDK - I was looking for some device characteristics to narrow down the SDKs.
    Andy Dent : Re the Intermec CK31 - the features list "Integrated 1D (standard, long range) / 2D Intermec scanning technology"
  • First I'll strongly echo Adam's recommendation against running anything based on CE .NET 4.2 at this point for essentially the same reason. At this point it's an ancient version of the OS and unless you are getting the terminal for free it's not worth it and if you choose to do C# development the download of the CAB to run .NET 2 is just painful.

    We've developed a lot of applications for both Motorola(Symbol) and Intermec devices. The current set of APIs for both of them work reliably so I'd worry more about the suitability of the device than the specific APIs. They also both provide reasonable sample programs that make it easy to cut and paste a solution.

    I have noticed one other big difference between Motorola and Intermec. On the Intermec devices I've worked with (in C#), it takes about a second for the decoder for each symbology to be loaded. This typically isn't a big deal if you use a limited number of symbologies and setup the scanner at the start of the application, but can cause significant delays if you change the decoders(symbologies) within the application.

How can you move ASP.Net controls to different places on the Web form at runtime?

Is there an accepted way to "move" a control.

My client wants to place a certain chunk of markup (representing some visual element) in one of several different places on the page. The locations are different to the point that I can't effect the change on CSS along (by floating it or something).

I considered just putting the control in multiple spots with Visible set to "false," then displaying the one in the place they wanted for that particular page.

However, the code for this control is not trivial -- there's a couple template sections, for instance. Having to dupe this in multiple places would get unwieldy. Also, I don't want to have to work with this control strictly from the code-behind for the same reason.

So, I'd like to put it in one place on the Web form, the move it around based on where I want it. Could I put Placeholders in different spots, have the control in one spot, then remove and add it to the right spot? I suspect this would work.

Does someone have a better idea? Is there a best practice for this?

From stackoverflow
  • Do Web Parts do what you want to do?

    Or, you can change the parent programmatically of your controls to move them into a separate area.

  • You could always put panels in the pre-defined locations and add the control to the specific panel at runtime.. Here's an example adding a label (the label could be replaced with any control).

    Dim lblDisplay As Label = New Label()
    lblDisplay.ID = "myLabel"
    lblDisplay.Text = "Some Text"
    pnlDisplay.Controls.Add(lblDisplay)
    

    As far as...

    "Also, I don't want to have to work with this control strictly from the code-behind for the same reason."

    I think you're going to have to do most of your work in the code behind.

    PS.. a good example of the whole usercontrol setup can be downloaded here.. http://www.asp.net/downloads/starter-kits/time-tracker/

    Deane : I meant that I didn't want to create it from the code-behind. I don't have a problem manipulating it in some form from the code-behind, but I'd like the bulk of it's mark up in the Web form.
    madcolor : I'm suggesting you create a user-control with the markup that has properties you can get/set and load a panel. No good reason to have your markup sitting in the webform that I can see.
  • You can override the Render method and place the controls wherever you want in the html.

    You only need to add controls to the Controls collection that must interact on the server. The rest of your HTML can just be written to the response stream. If you override Render you can create the html anyway you see fit, placing the controls in any order.

    Below is an example of how to write out your html.

    protected override void Render(HtmlTextWriter writer)
    {
      AddAttributesToRender(writer);
      writer.RenderBeginTag(TagKey);
    
      writer.RenderBeginTag(HtmlTextWriterTag.Div);
      _control.RenderControl(writer);
      writer.RenderEndTag();
    
      writer.RenderEndTag();
    }
    
  • I'd recommend using a placeholder control, moving your markup into a separate user control, then loading this at runtime and adding it to the relevant placeholder.

    Eg.

    // Load a user control
    MyControl userCtrl = (MyControl) LoadControl("~/Controls/MyControl.ascx");
    
    // Or create an instance of your control
    SubclassedControl subclassedCtrl = new SubclassedControl();
    
    // Do stuff with controls here
    userCtrl.LoadData();
    subclassedCtrl.Text = "Hello World";
    
    // Check which placeholder to add controls to
    PlaceHolder placeHolder = (foo=="bar") ? placeHolder1 : placeHolder2;
    
    // Add the controls
    placeHolder.Controls.Add(userCtrl);
    placeHolder.Controls.Add(subclassedCtrl);
    

    This will avoid cluttering up your page with unnecessary markup, and loading it at runtime will also avoid unnecessary confusion later, when another developer looks at the code and can't immediately see why a control is in one place in the markup, but renders on a completely different part of the page.

    Deane : How would I do this if the control is a extension of a standard ASP.Net control, so it exists as a .cs file in App_Code? Would I need to "wrap" it in a User Control (a .ascx file)?
    madcolor : Yes, then you can either load it in a placeholder or a panel.. same diff, only the panel spits a div or span tag where the placeholder doesn't.
    Mun : If you're subclassing a standard ASP.NET control, then rather than loading a control, you could create an instance of your control instead, and then add it to the placeholder. I've updated the code sample above to reflect this.
  • An alternative (and one I've seen done many times before) is through javascript and the DOM. Render your control inside a hidden div tag. So you would render your content here:

    <div id='rendercontent' style='display:none'>
      .. control here ..
    </div>
    

    Then, lets say you wanted to move it all here (the span tag is inside because that's what we're going to replace):

    <div id='newlocation1'><span></span></div>
    

    You would define the following javascript:

    <script language="JavaScript">
    function replaceNode(newElementID, targetElementID)
    {
        var targetElement=document.getElementById(targetElementID);
        var newElement=document.getElementById(newElementID);
        targetElement.replaceChild(newElement, targetElement.firstChild);
    }
    </script>
    

    And when you want to move the content to the new location, call:

    <script language="JavaScript">
    replaceNode('rendercontent','newlocation1');
    </script>
    

What's the difference with buffered synchronous I/O and asynchronous I/O?

When using a synchronous I/O such as fread which is buffered, the read operations are postponed and combined, I think that isn't done synchronously.

So what's the difference between a buffered synchronous I/O and an asynchronous I/O?

From stackoverflow
  • My understanding of async I/O is that you're notified when it's done via an interrupt of some sort so you can do more I/O at that point. With buffered I/O, you do it and forget about it, you never hear about that particular I/O again.

    At least that's how it is with the huge intelligent disk arrays we deal with.

    The idea of async I/O is that you begin the I/O and return to doing other stuff. Then, when the I/O is finished, you're notified and can do more I/O - in other words, you're not waiting around for it to finish.

    Specifically for the synchronous read case: you request some input and then wait around while it's read from the device. Buffering there just involves reading more than you need so it's available on the next read without going out to the device to get it.

    Async reads, you simply start the process to read then you go off and do something else while it's happening. Whether by polling or an interrupt, you later discover that the read is finished and the data is available for you to use.

    For writes, I'm not sure I can see the advantage of one over the other. Buffered sync writes will return almost immediately unless the buffer is full (that's the only time when an async write may have an advantage).

  • From a programming point of view, synchronous IO would be handled in the same function/process eg.

    var data0 = synchronousRead();
    var data1 = synchronousRead();
    

    whereas asynchronous IO would be handled by a callback.

    asynchronousRead(callBack1);
    doOtherStuff();
    ...
    
    function callBack1(data)
    {
        data0 = data;
    }
    
  • Synchronous IO is the "normal" kind where you call a routine, and flow of control continues when the routine has read into your local variable (ignoring writes).

    Asynchronous IO involves setting up a buffer variable (static, global, or otherwise long lived / wide scope) and telling the system that you want data put into it when it eventually becomes available. Your program then continues. When the system has the data, it sends you a signal / event / message of some kind, telling you that you now have data in your buffer variable.

    Async IO is usually used by GUI programs to avoid stalling the user interface while IO completes.

  • Synchronous I/O works on a polling basis: you poll, data is returned (when available---if not available, then: for blocking I/O, your program blocks until data is available; for non-blocking I/O, a status code is returned saying no data is available, and you get to retry).

    Asynchronous I/O works on a callback basis: you pass in a callback function, and it gets called (from a different thread) when data becomes available.

  • Look here. Evrything you want to know is explained.

    link to wikipedia

Am I experiencing a memory leak, or just high memory usage in Firefox?

I'm loading some fairly big data sets in to firefox (500 k or so) and drawing tables with them. Firefox is using up to 400 megs of memory. How can I tell if Firefox is leaking memory, or is just using a lot of memory just because it can?

Is there another browser which will use less memory if it doesn't need it? I get the feeling that firefox grabs a bunch of memory for itself and doesn't release it unless it has to. It may be apparent that my understanding of memory management in general is very superficial.

From stackoverflow
  • There is a setting you can set in firefox that forces it to free as much memory as it can on minimise:

    1. On the website url toolbar type about:config
    2. A page full of words will come up. right click anywhere and choose New -> Boolean
    3. For the name input type "config.trim_on_minimize" Select True
    4. Restart FireFox.
    morgancodes : cool. thanks! what do you mean by "on minimize"? When you minimize the browser window?
    ck : Yes, when you physically minimise it (through Windows+M or clicking the minimise button, or right click on the task bar and minimise).
    John Rasch : +1 - This is great, I've been running into the same issue except it occurs when I use Pandora to listen to music. I've been below 100K constantly instead of the usual 500K+ since I added this setting.
  • If it is leaking memory, then the mem usage (number of K) in your Windows task manager will continue to grow. If this number is fairly consistent, then Firefox is behaving normally. It is my opinion that Firefox requires far too much memory to behave normally.

  • You can turn on Windows Performance Monitor and see if the firefox.exe process is growing memory over time to confirm if there is a memory leak.

  • How can I tell if Firefox is leaking memory, or is just using a lot of memory just because it can?

    Open another page in a different tab. Then close your 'big' tab and see if the memory is freed.

  • I get the feeling that firefox grabs a bunch of memory for itself and doesn't release it unless it has to. It may be apparent that my understanding of memory management in general is very superficial.

    well, at 1 point Firefox requires a lot of memory, say 400Mb. maybe after that, it doesn't require so many memory, BUT

    since your system do not need this memory, it does not reclaim it to Firefox, which keeps it.

    If ever you launch other processes that need a lot of memory, then your OS will claim back memory to other processes that are running with a high priority.

    To summarize my ideas : it's probably not a memory leak.

    Is there another browser which will use less memory if it doesn't need it?

    why don't you try them?

  • Memory Leak - memory which is not released when it should be

    If the memory Firefox is allocating to hold your data is released when you navigate away from your page, there is no memory leak. You can than argue if Firefox if using too much memory or not, but that is something beyond your scope.

    You do have a leak on your hands if that memory is not released. In that case you should check if it is something you can handle in your JS code, or a firefox bug. If it's the latter, go ahead to the mozilla bugzilla, and open a ticket.

jQuery Autocomplete in ASP.net MVC doesn't work when the control created in Ajax way

I am running an issue, could you help me out with your knowledge..?

Basically, this autocomplete extension of jQuery depends onto the ready method of the jQueryLibrary. (I am not 100% sure what it does actually, but I can guess it checks wheather the DOM has been loaded, if loaded it does something as an regular "onload" event handler).

Now, I have an ASP.net MVC application where I am using Ajax to render a partial view (an ascx file) and that file contains the autocomplete textbox.

As the DOM has been already loaded and I am now modified the DOM with the content of the ascx file in an Ajax fashion, my text boxes into the ascx are not doing anything autocompletion. What could be an alternate or workaround of this problem..? Even I am a bit curious why it's not working..?

Any idea would be greatly appreciated.

Have a nice day

From stackoverflow
  • you need to load the autocomplete function again as like you said the new items in the dom have come after the jquery already loaded. You can either put the jquery function in the ascx (simple way) or force the jquery to run on the DOM again which may cause unintended results.

  • Jeremy thanks for your reply. Here is my ascx code. I didn't understand what you said by ""..could you be so kind explaining a bit more..? thanks a lot!

    here is an image that shows my user controls code. http://img10.imageshack.us/img10/6845/75246857.jpg