All Snippets
Top 100 Snippets

By Language

GBIC >> Source Code >> Top 100 Snippets >> QBasic
Top 100 QBasic Snippets
These snippet titles reflect my cut at the most common functions a programmer needs to create QBasic applications. Since QBasic programs tend to be small, you might find only a dozen or so of these in any one program. You're very unlikely to find them all in any one program.

Most snippets consists of relatively few lines of code, particularly since they focus on accomplishing a single task.

Creating a Top 100 QBasic list is a bit challenging in that it is used to create both graphical and non-graphical applications. Should the Top 100 list reflective an essentially non-graphics language such as Perl, or should the Top 100 list mirror the snippets for a' graphics-intensive language such as the .NET family of languages?

I find that my opinion continues to shift on about 10%-20% of the list, so don't be surprised to find the list changing - or growing as I consider the list in more detail.

You can view the snippets online at this site or download my freeware gbCodeLib code librarian, which has the source code for all of these. It contains snippets and mini-tutorials for QBasic as well as several other languages such as VB, VB.net, VBA, JavaScript, Perl, Java, and HTML.

For now, the list favors DOS/command line capabilities, although for gaming support I am looking to add more graphical capabilities to the list.

1. Start a new application and wait for it to finish
2. Maintain MRU file (most recent updated files)
3. Read/write INI files

4. Cycle througn an array
5. Randomly shuffle an array
6. Remove an element of an array (by content or by position)
7. Search an array

8. Copy or retrieve text and images from the clipboard

9. Capture any key (Enter, TAB, arrow keys, home/end, F-keys, ...)
10. Forces lower/upper case on text input

12. Compute elapsed time between 2 dates
13. Compute elapsed time between 2 events (ms accuracy)
14. Display time in multiple formats

15. Create valid full pathname from folder and file names
16. Extract file name from a full path
17. Determine if a file exists
18. Get file properties (size/date/attributes)
19. Delete a file to the recycle bin
20. Backup/restore a file

File - Text
21. Read file one line at a time or all at once
22. View content

File - Binary
23. Read/write data at a specific location
24. Read entire file at once
25. View contents in hex or binary-stripped format

26. Determine if a file exists
27. Delete a folder and its subfolders
28. Get list of dirve letters
29. Get type of drive
30. Create a fll path of folders


31. Convert between Long, RGB, VB, and web colors
32. Get image size without reading entire file (JPG/GIF/BMP)
33. Get screen resolution
34. Read/write/display/convert images (JPG/GIF/BMP)
35. Resize and image, keeping aspect ratio

36. Check for Internet connection
37. Create web page (HTML) from code
38. Download text/binary file, with progress indicator
39. Upload text/binary file, with progress indicator
40. Get remote file information (size/date0
41. Open a web page in a browser
42. Send email using default email application
43. Update file via FTP

44. Create random integer within specified range
45. Round number to specified number of decimals

46, Play CD
47. Play sound or video file (.wav, .mp3, ..mid, avi, .mpg)
48. Record sound or video

49. List all files and folders beneath a specified full path

50. Print images (positioned, scaled, or tiled)
51. Print preview
52. Color text printing
53. Send page eject to the printer
54. Print justified text (left/right)


55. Calculate checksum
56. Encrypt/decrypt a file/string (with or without a password)

57. Bubble sort
58. QuickSort

59. Convert strings to upper/lower case
60. Find/replace a string within a string
61. Split string into an array based on delimeters
62. Find text between two strings

63. Get computer name
64. Get user name
65. Get name of special folders (Windows, System, SendTo, Startup,
66. Get Windows version
67. Reboot / restart / logoff system