Member Avatar
Reusable Code Snippet Make a given number odd or even

There are times when you need to make sure your counter starts at an odd or even number. Even is pretty simple - `counter = counter + modulus(counter)`. If counter is even it stays, if it's odd it gets incremented by 1. Odd is a bit more complicated - `counter = counter + modulus(counter + 1)`, If counter is odd it stays, if it's even it gets incremented by 1. if you're in danger of counter being the max value you can always subtract instead. These basic algorithms should work for any language that has a modulus operator/function. I've included …

Member Avatar
+2 forum 4
Member Avatar

This was a query raised by one of a forum members at another site, where he had a worksheet filled with random numbers, and I have already answered that query [at my post here](https://vbacoder1962.wordpress.com/2019/07/15/extracting-cell-phone-numbers-from-random-strings-of-variable-length/). You may go through that post and read the logic behind the code. ![vbacoder_Code_20190715.jpg](/attachments/large/4/160efbe4e4d0a8400d04653a6e420c7b.jpg)

+1 forum 0
Member Avatar
Reusable Code Snippet vb.Net Progress Bar With Text

A long standing complaint with the standard progress bar control is that there is no easy way to display text. In spite of numerous requests, Microsoft has not included this capability. The following code includes a class, `CustomProgress` which inherits the standard `ProgressBar` and adds such a feature. It is fairly easy to use. If you want to show a percentage progress you set `Text` to a null string and the percentage will be calculated from the `Minimum` and `Maximum` value properties. If you want a custom string then assign it to `Text`. Either the percentge or custom text will …

Member Avatar
+4 forum 3
Member Avatar

**I would Like to Use this code after you have clicked into your textbox And I am Edwin Have a good Time**

Member Avatar
+0 forum 3
Member Avatar
Reusable Code Snippet Google Map Control vb.net

I was so amazed at how easy it was to embed google maps into a vb app I decided to post a quick example to help anyone get started. This is a simple example. Google's api has all kinds of things to help customize your map. You can find out anything you need to know from here: [url]http://code.google.com/apis/maps/documentation/javascript/reference.html[/url] You will need to: Create a new windows forms app. Add a class named GoogleControl and paste the GoogleControl code into it. Add a new html doc to the project and name it GoogleMap.htm and set its Build action to CopyIfNewer Copy …

Member Avatar
+4 forum 46
Member Avatar

Several people have asked how to export data to Excel. This code snippet shows how to export the data from a listview in details mode to a new Excel spreadsheet. Take note of the comments in the header to avoid having orphaned Excel.exe tasks eat up your system memory.

Member Avatar
+7 forum 15
Member Avatar
Reusable Code Snippet Permutations in Vb.net

The present code snippet just does an especific task. This is, given an ordered sequence of natural numbers, starting at zero, generate all the different permutations there can be. When we talk about permutations, the order of the sequence does matter. So, the sequence 0, 1, 2 differs from 2, 0, 1. For example, think about a 4-7-2 lock combination sequence. Changing the sequence to 2-7-4 would not open the lock, of course. Properly speaking in mathematics, we are talking about permutations, because the order does matter. On the other hand, if the order did not matter, we would be …

Member Avatar
+0 forum 9
Member Avatar
Reusable Code Snippet Probability and Coin Tossing

Here's an interesting little scenario. You get challenged to a game of coin toss. Both players pick a sequence of coin toss results (heads or tails). The coin is repeatedly tossed until the sequence for one of the players occurs. The loser pays the winner a dollar. You'd assume that you each have an equal chance of winning. However, using two little "tricks" you can tip the odds in your favour. The first trick is to always choose second. If you can manage this then your strategy is as follows: Your first choice should be the opposite of your opponent's …

Member Avatar
+0 forum 36
Member Avatar
Reusable Code Snippet BlowFish Class

# BlowFish? # BlowFish was the brain child of Bruce Schneier back in 93. Since BlowFish was released to the public domain, Bruce Schneier has released new encryption algorythems, TwoFish and ThreeFish. BlowFish is an increddibly popular and very strong algorythem. Because it conforms to Kerckhoffs's Principal [Explained Here](http://en.wikipedia.org/wiki/Kerckhoffs's_principle), even though the algorithem is public domain, it still isn't crackable without the key. # It Isn't Mine, I Just Converted It. # I'm far from a maths genius, far, far from it. My only involvement in this class is converting from VB6 and wrapping. I have tried to comment the …

Member Avatar
+0 forum 1
Member Avatar

There are many examples of compressing files in VB.Net. So many of these examples are using third party libraries which is just not neccesarry. People were saying that files and archives exceeding 4Gb couldn't be used... I hate restrictions and decided to "Stick it to Microsoft" To get a better understanding of Zip files and their contents I set about writing my own Zip file generator from the ground up (Still using Phil Katz's Zip algorythem). Eventually I successfully built my own Zip and ZIP64 archives byte by byte. I then looked at my work and thought, now I have …

Member Avatar
+1 forum 3
Member Avatar

Hey guys, does anyone know how to do this? Here is my current code that will not work. I have tried everything that I know how to make this work to no avail. This is under form1_load. Any help would be awesome. Thanks in advance.

+0 forum 0
Member Avatar
Reusable Code Snippet Collapsible Panel

Here is a small extention of the Panel class that allows you to 'collapse' it. So far, the user can place a control on the parent form and perform a collapse/expantion by: 'Where cpNew is a Collapsible Panel If Not cpNew.PanelCollapsed Then cpNew.Collapse() 'or If cpNew.PanelCollapsed Then cpNew.Expand() I will be changing/improving the control as much as possible. If anyone has any suggestions/tips they would greatly be appreciated!

Member Avatar
+0 forum 1
Member Avatar

I know that this probably has been done by someone, but I want to learn how to do this using VB 2010 express. I cannot seem to get the numbers to stay in the text boxes that they are dropped in. The numbers always go to the last box (#81). What am I doing wrong. You might have to change some lines to get the numbers to display in the lables assigned for them - that's ok.

Member Avatar
+0 forum 5
Member Avatar

This is the code to align the content of a Panel in the Center, Hope this Helps :)

Member Avatar
+0 forum 2
Member Avatar

VB.Net never meant for games! it's more recommended for software developement, but hey why not have some fun. If anyone out there is looking to create an Angry Birds Game-like or a Simulator for throwing an object, you've come to the right place, this code will give you great start/push to build your own app. #**Trajectory**# ![dd5f632319f6a4422579ce0a7c3db41e](/attachments/large/4/dd5f632319f6a4422579ce0a7c3db41e.jpg "dd5f632319f6a4422579ce0a7c3db41e") A Trajectory for a projectile have a bunch of formulas, the more equations you use, the more realistic motion you'll get. As a start i used only 3 formulas which they're the essentiel ones,the X and Y coordinates and the angle, containing …

Member Avatar
+1 forum 2
Member Avatar

I have just seen a resurrected thread about issues with loading images to a PictureBox and the inability to delete the file while the program is running. There was no clear explaination of the problem, only suggested hacks and apparent frustration. So I thought I would offer this explanation from [Microsoft](http://support.microsoft.com/kb/814675): > **SYMPTOMS** > When either a Bitmap object or an Image object is constructed from a file, the file remains locked for the lifetime of the object. As a result, you cannot change an image and save it back to the same file where it originated. > > Additionally, …

Member Avatar
+0 forum 2
Member Avatar
Reusable Code Snippet Color ComboBox In vb

Now I am going through a project with colors. And then I think that if I try to display color values with their names in a simple combobox, it could be amazing. I tried and did it and it is looking like ![Capture3.png](/attachments/small/4/4473f7608016edcb5981090cccc80593.png "align-left") And ![Capture4.png](/attachments/small/4/87a5e5686d66033648a3e0ab787d6778.png "align-left") And finally the project looks like ![Capture2.PNG](/attachments/large/4/28adcd5b3021552683dc4fd791d2f813.PNG "align-center") In that codes, firstly I tried to bind combobox with colors. Private Sub BindWebColors() 'binding combobox with color vaues 'assign combobox drawmode cmbWebColor.DrawMode = DrawMode.OwnerDrawFixed cmbWebColor.ItemHeight = 20 Dim colType As Type = GetType(System.Drawing.Color) For Each prop As PropertyInfo In colType.GetProperties() If prop.PropertyType Is GetType(System.Drawing.Color) …

Member Avatar
+0 forum 1
Member Avatar

I am posting this in response to those who ask about replacing the webbrowser (WB) control’s default browser. You cannot ask the WB control to use a different browser, it is hardwired to use the current version of Microsoft’s Internet Explorer that is installed on the target computer. It may appear that the WB control is using an older version than is installed; this is not the case. Microsoft in their infinite wisdom made the decision to make IE 7 the default-rendering mode for all applications that use the WB control. This can be observed by visiting this website: http://detectmybrowser.com …

Member Avatar
+1 forum 6
Member Avatar

=======Download The Full Solution Below======== This will be my last VB.Net soure as I've made the move to C#. For a recent job application I was given the technical test to create a horse race simulator which would calculate the odds of a runner winning a race of up to 16 runners, then ensure the runners were within a 2% winning margin of there expected win percentage after 1,000,000 races. I got the results between 0.10% and 0.02% but never got offered the position as my solution was "Beyond Requirements". ![HRS.png](/attachments/large/4/bd6b8dd0650ce5f12fd9ab24b7755c94.png "align-center") This solution is host to ll sorts of …

+1 forum 0
Member Avatar
Reusable Code Snippet Add VBA code to Excel file

This snippet demonstrates how you can add VBA code to an Excel file at run time. **Prerequisites** In this snippet I am using Microsoft Excel 2013 with the Microsoft Excel 15.0 object library. Before you can use this code, you will have to change a setting within Microsoft Excel to authorise the use of the VBA Project Object Model from external programs. This is a security feature to protect end users from malicious programs and is disabled by default. If you do not enable this feature then the code below will result in an exception stating "Programmatic access to Visual …

+0 forum 0
Member Avatar
Reusable Code Snippet Mates8 grapher

By means of Mates8, graph coding becomes a bit easier. The web page has four textboxes so the figure gets bounded to the left, right, top and bottom; and a draw button. Additionally, a panel control will contain the image generated by the code after the button is pressed.

Member Avatar
+0 forum 5
Member Avatar

This conception I get from a post on CodeProject by [Heriberto Lugo](http://www.codeproject.com/Tips/837177/Recursion-for-Beginners-Sorting-Ten-Numbers-Withou). But that was for only 10 numbers. Then I had an idea to use it in vb. There are many shorting process like Bubble Short, Linear Short etc. But exceptionally it does not use loops as others do. It does it by recursion. If we take an array of 10 elements and store a value from 10 to 1 in each Array Element. It should be like ![a09127110acb607fa3464fb2a9df79ab](/attachments/large/4/a09127110acb607fa3464fb2a9df79ab.PNG "a09127110acb607fa3464fb2a9df79ab") Let us try to go through the rotation. Consider for the first element, the stored value is 10. It …

Member Avatar
+0 forum 5
Member Avatar
Reusable Code Snippet Comparing Password SHA1 Hash

Using .Net's SHA1 Crypto Service to compare hashes between a user's password and their stored hashed password. Simplez =0)

+0 forum 0
Member Avatar

I was just mucking around with a progress feature for some software, and thought I'd just put this wee demo up of a clocky type progress thing =0) Just Copy and paste the form code and watch it run. (p.s it's in degrees, note minutes and seconds) ![55f1addda67a729e91ae90c980c39deb](/attachments/small/4/55f1addda67a729e91ae90c980c39deb.png)

Member Avatar
+0 forum 2
Member Avatar

After trying to manipulate PNG files and failing miserably discovering that the standard GDI doesn't provide support for any PNG parameters decided to provide some basic image manipulation functions built into .Net that I came across on my investigations. 1. Adjust Image Quality 2. Flip Image Horizontally 3. Flip Image Vertically 4. Rotate Image (90 Degree Step) This Source Uses 4 buttons, A HScrollBar and A PictureBox.

Member Avatar
+1 forum 1
Member Avatar

Did you know that you can data bind a bitmap to a PictureBox's image property, and the source image doesn't have to be in a binary format stored in a data table? Using a standard object setup for data binding (iNotify etc.) you can easily update your program's image propertie's from one place.

+0 forum 0
Member Avatar

NOTE: The games GUI is not fully implemented, so changing it's image and difficulty is done manually in the Button.Click Event NOTE: Whether you download the VS2013 source file or copy and paste the code, you need to download, and extract the two image files to the project's "Bin\Debug" directory. If you copy and paste the source ensure your form has the following controls: Button (Button1) PictureBox (Name:pbGameBoard, Width:792, Height:792) # THE GAME # This is a fun example using graphics. It is a representation of the classic tile slide game, where you slide the tiles around to make the …

Member Avatar
+1 forum 1
Member Avatar

>Take Heed There are lots of things to be aware of with the Windows Registry. In most cases the best thing to be aware of is that ideally you should avoid playing with it at all costs. Alas, we are what we are and we do what we do. My advice to you is to make a back up of your registry. Remember though, values are read and written continuousley without our knowledge, and reverting to a backup made 10 minutes ago may not reflect your current systems settings so be careful. >Backup Your Registry Start RegEdit, Search for RegEdit …

+0 forum 0
Member Avatar

I'm currently working on a collection of sub-projects, one of which was a backup manager. I needed to be able to allow the user to specify a backup time and a repeat interval. After thinking about the solution, decided it would be best for the user to provide an Initial DateTime of the first occurance and how frequent they would like to repeat the event. This class can be used to help determaine Alarms, Reminders or anything that requires an event to be triggered at a certain time. >Fun and Good for Beginners It was good fun writing this wee …

Member Avatar
+1 forum 2
Member Avatar
Reusable Code Snippet VB.NET - Simple Game

Here's a simple game code, open a new vb project and copy paste this code and hit run. the game contains 3 levels, all you have to do is to shoot the smiley faces to earn money using mouse clicks, also there's a boss enemy on level 3. I didn't have much time to add more levels to the game (actually i only tried to play it once :p), here's my point of this code "Just for fun" try to import some enemy characters(in a picturebox) and add more levels and add some sound effects to the shooting or when …

Member Avatar
+3 forum 8

The End.