Visual Basic Projects

Miles to Kilometers Conversion Tool in Access

In this project, I created a simple but functional conversion tool using Visual Basic for Applications (VBA) in Microsoft Access. The tool allows users to convert distances from miles to kilometers with just a click of a button, demonstrating basic form creation, user input handling, and simple event-driven programming.

Key Features and Implementation

Form Design and Layout:

I designed a new form named MitoKM with an intuitive and user-friendly interface. The form includes two labels:

lblMiles: Prompting the user to enter the distance in miles.

lblAnswer: Displaying the converted distance in kilometers.

Two command buttons were added:

cmdConvert: Triggers the conversion from miles to kilometers.

cmdQuit: Closes the program.

Conversion Logic:

The cmdConvert button was programmed using VBA to convert the input miles to kilometers. The conversion formula applied is 1 KM = 0.62 Miles, ensuring accurate results. Upon clicking the button, the tool takes the user input, performs the conversion, and displays the result in the lblAnswer field.

Program Termination:

The cmdQuit button was programmed to close the application, providing a seamless exit for the user.

Testing and Validation:

The tool was thoroughly tested to ensure the conversion calculation was accurate and that all user interface elements functioned as expected.

Lessons Learned

This project helped me practice and enhance my skills in several key areas:

Form Creation and Design in Access: Gained hands-on experience in creating forms with controls like labels and command buttons, focusing on both functionality and aesthetic design.

Event-Driven Programming with VBA: Learned to write event handlers for button clicks to perform actions such as conversions and application termination, demonstrating the basics of event-driven programming.

User Input Handling and Validation: Developed the ability to handle user input effectively, ensuring accurate conversions and a smooth user experience.

Overall, this project reinforced my understanding of using VBA in Microsoft Access to create simple yet effective tools, building a foundation for more complex database-driven applications.

Character Selection and Looping Program in Access

For this project, I developed a program using Visual Basic for Applications (VBA) in Microsoft Access that demonstrates the use of looping structures and the Select Case statement. The program allows users to select a character and specify the number of lines they want to display, generating a patterned output based on their input.

Key Features and Implementation

Form Design and Controls:

The form, titled Select Case and Looping, includes a text box (txtLines) where the user enters the number of lines they want to display.

A label (lblLines) prompts the user with the question, "How many lines do you want?"

Five buttons representing different characters (#, @, $, %, &) allow the user to choose a character for the pattern.

A "Go" button (cmdGo) triggers the generation of the pattern.

A list box (lstDisplay) displays the generated output.

Program Logic and Variables:

Three key variables are defined:

lines (Integer): Represents the number of lines to display, initialized to 0.

character (String): A module-level variable storing the selected character, making it accessible from multiple subroutines.

message (String): Used to construct the output string.

When a user clicks any of the character buttons (cmdHash, cmdAt, cmdDollar, cmdPercent, cmdAmp), the corresponding character is saved to the character variable.

Upon clicking the "Go" button, the program reads the number of lines from txtLines and uses a Select Case structure based on the chosen character to determine the pattern. Each case contains a For/Next loop that generates the required number of lines, appending them incrementally to the lstDisplay list box.

Dynamic Pattern Generation:

The loop constructs a pattern where each line consists of an increasing number of the chosen character. For example, if the # character is selected with 5 lines, the output will appear as

#

##

###

####

#####

The program supports multiple characters and displays the result dynamically, enhancing user engagement.

Lessons Learned

This project provided hands-on experience with several key concepts in VBA:

Using Select Case Statements: Gained a deeper understanding of using Select Case structures to handle multiple conditions, making the code more readable and organized.

Implementing Loops in VBA: Learned to use For/Next loops for dynamic pattern generation, improving my ability to handle repetitive tasks efficiently in code.

Working with Module-Level Variables: By defining the character variable at the module level, I practiced managing variable scope and ensuring data is accessible across different subroutines.

User Interface Design in Access: Enhanced my skills in designing user-friendly forms with various controls, providing a seamless and interactive experience for the user.

Overall, this project was an excellent exercise in applying VBA to create interactive programs that combine control structures, loops, and event-driven programming.

Dice Rolling Simulation in Access

In this project, I created a Visual Basic for Applications (VBA) program in Microsoft Access to simulate the rolling of two dice and tally the results. The program demonstrates the use of random number generation, arrays, and loops to perform multiple trials and collect statistical data.

Key Features and Implementation

Program Overview:

The program simulates rolling two dice 10,000 times. For each roll, it calculates the sum of the values shown on the two dice, which ranges from 2 to 12.

An array is used to tally the frequency of each possible sum (from 2 to 12) as the dice are rolled repeatedly.

User Interface:

A simple form contains a "Roll" button, which initiates the dice-rolling simulation.

A list box is used to display the results after all trials have been completed.

Key Components:

Random Number Generation:

The Rnd function is used to generate random numbers representing the dice rolls. Since each die can show an integer value between 1 and 6, the program adjusts the random output accordingly.

Array for Tallying Results:

An array (resultsArray) is initialized to store the count of each possible sum from 2 to 12. As the dice are rolled, the array is updated to reflect the frequency of each result.

Looping for Multiple Trials:

A loop runs 10,000 times to simulate the dice rolls, calculate their sum, and update the tally in the array.

Displaying Results:

Once all trials are completed, the results are output to a list box, showing the number of times each possible sum occurred.

Lessons Learned:

This project helped me strengthen my understanding of several programming concepts:

Random Number Generation and Simulation: I learned to use the Rnd function to generate random numbers, which is essential for simulations and modeling random events.

Using Arrays for Data Storage: The project emphasized the importance of arrays for efficiently storing and managing data, such as tallying the results of thousands of dice rolls.

Applying Loops for Repeated Actions: I enhanced my skills in using loops to perform repetitive tasks, such as rolling dice multiple times and updating the tally array.

User Interface and Result Display: Gained experience in designing a simple interface for a simulation program and presenting the results clearly using a list box.

Overall, this project was a great exercise in creating a simulation program that combines random number generation, arrays, loops, and user interface elements, all of which are fundamental skills in programming with VBA.