VB.net: Update Listbox with Time,Text then Autoscroll

When making applications in VB.net I often use a Listbox to give the application user some kind of status updates when a application have to loop through a huge amount of data.
It’s a nice way to be able to tell if it’s still working and doesn’t seem like a non-responding application that have crashed.

Therefor I wrote this little code snippet, it’s basically Sub I got inside my elite-module.vb (//irony) which is filled with handy custom functions, suns and such that I tend to use often in my projects.

Anyway, instead of using ~4 lines of code every time to add some text as a update the Listbox, then autoscrolls down to show the new status item and also do a UI refresh.
If there’s intense CPU load the UI might not respond so well, so we force it to redraw.

Here’s the code snippet:

    ' UpdateStatus (Made for "Status updates". It adds/update the the Current Time + Your text string. Then Scrolls down to new item & Refresh Listbox UI.
    ' Example of usage: UpdateStatus(ListBox1, "I just added a new status update...")

    Public Sub UpdateStatus(ByRef ListBoxName As ListBox, StatusComment As String)

        ListBoxName.Items.Add(TimeOfDay.ToString("H:mm:ss") & ": " & StatusComment)
        ListBoxName.TopIndex = ListBoxName.Items.Count - 1
    End Sub

If you don’t want to use the 24-hour time format, you can replace that bit of code with TimeOfDay.ToString(“h:mm:ss tt“) which will give you a output in this format: “7:22:14 pm”

I hope you find it useful.

VB.net: Auto Scroll a Listbox

Do you want to make a Listbox in VB.net auto scroll to the last value?
I use this to log and show the progress of what my application is currently doing.

Amazingly ugly UI I made.
Auto scroll listbox in VB.net

The first line just add date and the current time to the Listbox.
The second line is the one that actually scroll the Listbox.
The third line is refreshing the UI which might be needed if your application need to do a lot of work…

ListBox.TopIndex = ListBox.Items.Count - 1

A good idea is to use a timer to keep the Listbox scrolling so you don’t have to add the same code over and over each time you add a new item to the Listbox.

Fix: WordPress Sitemap Error: “XML declaration allowed only…”

Have you seen a error similar to the one below while trying to access your WordPress Sitemap?

This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.

Wordpress sitemap.xml error

I’ve looked around and one guy solved the problem by removing some PHP-code that indicates the PHP code ending or whatever you call it “?>” in his themes functions.php file.

Because apparently he had 2 of them which caused the sitemap error for him and someone else too in that thread.

But that was not the problem for me. The problem was because some idiot (me) had made a plugin and left linebreaks and spaces in the plugin PHP-file.

So check your WordPress plugins. Deactivate one at a time and hit F5.

Have fun! 😉

Chrome & Vivaldi: Change the CACHE location & Size

This is mostly a note for myself but I’m sure some people will find it useful too.

If you want to change the cache location of where Chrome, Vivaldi and probably other browsers that use the same rendering engine, this is how you do it the easy way.
But this is only for the Shortcut, if some other application starts your browser for example, these parameters wouldn’t be used.
It’s a minor problem, at least for me… I just replace all the shortcuts to Vivaldi I have.

I use a free RamDisk for Windows because I work a lot with temporary files and it’s faster than any harddrive. So that’s where I also place the web browser cache.

1: Right-click on your Chrome/Vivaldi-shortcut and click on “Properties”.

2: Under the tab “Shortcut” you’ll see the field “Target”. Right at the end of the path to the “.exe” file is where you place the parameters for cache directory location and also how much space it should be able to use.

This is the shortcut I use for example. X: is the RamDisk, and 350000000 = 350 MB.

"C:\Users\YOURUSERNAME\AppData\Local\Vivaldi\Application\vivaldi.exe" --disk-cache-dir="x:\Temp" --disk-cache-size-350000000

I hope you find it useful!

The Best Free RAMDisk for Windows 32 & 64-Bit!

I’ve tried several RAMDisk softwares before I found one that were free and worked under Windows 10 64-Bit.
The RAMDisk I use is called ImDisk Toolkit, and I find it pretty much perfect. It got plenty of features which should cover pretty much every users needs.
It might also save a lot of write cycles on your precious SSDs. 😉

RAMDisk for Windows

You can set it up to mount ISO-files and other image file formats if you want to.
Or setup a folder on one of your hard drives and have the content inside it copied to the RAMDisk every time you boot up your PC.
It can also be setup to save the stuff you currently got stored on the RAMDisk to a directory of your choice before you shut down your PC.

You can download ImDisk Toolkit here!