<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BenEskew.com &#187; Visual Basic</title>
	<atom:link href="http://www.beneskew.com/category/programming/visual-basic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beneskew.com</link>
	<description>Just another web developer&#039;s personal weblog.</description>
	<lastBuildDate>Sat, 28 Aug 2010 22:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>To Be Releasing All My Old VB Projects Soon</title>
		<link>http://www.beneskew.com/2009/11/to-be-releasing-all-my-old-vb-projects-soon/</link>
		<comments>http://www.beneskew.com/2009/11/to-be-releasing-all-my-old-vb-projects-soon/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 22:36:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=174</guid>
		<description><![CDATA[I've recently decided to let the world gasp in horror and amazement at all of my old source projects which I made using Visual Basic way back in the day when I was learning how to program on PC's. This all includes my old AOL &#038; AIM related projects (yep, including a famous "cracker" which [...]]]></description>
			<content:encoded><![CDATA[<p>I've recently decided to let the world gasp in horror and amazement at all of my old source projects which I made using Visual Basic way back in the day when I was learning how to program on PC's.</p>
<p>This all includes my old AOL &#038; AIM related projects (yep, including a famous "cracker" which I made for fun back then) because I believe they all hold educational value even today. I'm currently preparing a lot of the projects for you to easily download and whatnot so give me a bit of time. I will be releasing the main source code for hitMan later on today/tonight though. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/11/to-be-releasing-all-my-old-vb-projects-soon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #11</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-11/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-11/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 06:00:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=93</guid>
		<description><![CDATA[In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Window Actions and File Functions. Completely Destroy File and Its Information Compatibility: Win. 98-XP Add the following code into a module within your project... Public Sub DestroyFile(sFileName As String) Dim Block1 As [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Window Actions and File Functions.</p>
<h3>Completely Destroy File and Its Information</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Sub DestroyFile(sFileName As String)<br />
Dim Block1 As String, Block2 As String, Blocks As Long<br />
Dim hFileHandle As Integer, iLoop As Long, offset As Long<br />
'Create two buffers with a specified 'wipe-out' characters<br />
Const BLOCKSIZE = 4096<br />
Block1 = String(BLOCKSIZE, "X")<br />
Block2 = String(BLOCKSIZE, " ")<br />
'Overwrite the file contents with the wipe-out characters<br />
hFileHandle = FreeFile<br />
Open sFileName For Binary As hFileHandle<br />
Blocks = (LOF(hFileHandle) \ BLOCKSIZE) + 1<br />
For iLoop = 1 To Blocks<br />
     offset = Seek(hFileHandle)<br />
     Put hFileHandle, , Block1<br />
     Put hFileHandle, offset, Block2<br />
Next iLoop<br />
Close hFileHandle<br />
'Now you can delete the file, which contains no sensitive data<br />
Kill sFileName<br />
End Sub</code></p>
<p>Add the following code to wherever you want the code to execute...</p>
<p><code>Call DestroyFile("C:\filetodestroy.jpg") 'modify file path of course</code></p>
<h3>Cut, Copy, Paste and Undo</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long<br />
Public Const WM_UNDO = &#038;H304</code></p>
<p><u>Cut:</u><br />
Add the following code where you want the code to execute...</p>
<p><code>Clipboard.SetText Text1.SelText<br />
Text1.SelText = ""</code></p>
<p><u>Copy:</u><br />
Add the following code where you want the code to execute...</p>
<p><code>Clipboard.SetText Text1.SelText</code></p>
<p><u>Paste:</u><br />
Add the following code where you want the code to execute...</p>
<p><code>Text1.SelText = Clipboard.GetText(1)</code></p>
<p><u>Undo:</u><br />
Add the following code where you want the code to execute...</p>
<p><code>Call SendMessage(Text1.hwnd, WM_UNDO, 0&#038;,  0&#038;)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-11/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #10</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-10/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-10/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 02:36:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=88</guid>
		<description><![CDATA[In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Window Actions and File Functions. Minimize All Active Windows Compatibility: Win. 98-XP Add the following code into a module within your project... Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Window Actions and File Functions.</p>
<h3>Minimize All Active Windows</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)<br />
Public Const VK_LWIN = &#038;H5B<br />
Public Const KEYEVENTF_KEYUP = &#038;H2</code></p>
<p>Add the following code into a command button or wherever you want the code to execute...</p>
<p><code>Call keybd_event(VK_LWIN, 0, 0, 0)<br />
Call keybd_event(&#038;H4D, 0, 0, 0)<br />
Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)</code></p>
<h3>Load a Text Box with Items from a Text File</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Sub LoadText(Lst As TextBox, file As String)<br />
'Call LoadText (Text1,"C:\Windows\System\Saved.txt")<br />
On Error GoTo error<br />
Dim mystr As String<br />
Open file For Input As #1<br />
Do While Not EOF(1)<br />
      Line Input #1, a$<br />
      texto$ = texto$ + a$ + Chr$(13) + Chr$(10)<br />
    Loop<br />
    Lst = texto$<br />
Close #1<br />
Exit Sub<br />
error:<br />
X = MsgBox("File Not Found", vbOKOnly, "Error")<br />
End Sub</code></p>
<p>Add a TextBox named Text1 and make sure there is a text file named test.txt with "test" inside it inside the directory where you are working on your project and add the following code wherever you want the code to execute...</p>
<p><code>Call LoadText(Text1, "test.txt")</code></p>
<h3>Save Data to a Text File</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Sub SaveText(Lst As TextBox, file As String)<br />
'Call SaveText (Text1,"C:\Windows\System\Saved.txt")<br />
On Error GoTo error<br />
Dim mystr As String<br />
Open file For Output As #1<br />
Print #1, Lst<br />
Close 1<br />
Exit Sub<br />
error:<br />
X = MsgBox("There has been an error!", vbOKOnly, "Error")<br />
End Sub</code></p>
<p>Add a TextBox named Text1 and add the following code wherever you want the code to execute...</p>
<p><code>Call SaveText(Text1, "C:\Program Files\Program Name\test.txt")</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-11/">Visual Basic Code Snippets #11</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #9</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-9/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-9/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 00:46:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=83</guid>
		<description><![CDATA[In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions. Toggle NumLock Key On/Off Compatibility: Win. 98-XP Add the following code into a module within your project... Option Explicit Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.</p>
<h3>Toggle NumLock Key On/Off</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Option Explicit</p>
<p>Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long<br />
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)<br />
Public Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long<br />
Public Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long</p>
<p>Public Const VER_PLATFORM_WIN32_NT = 2<br />
Public Const VER_PLATFORM_WIN32_WINDOWS = 1<br />
Public Const VK_NUMLOCK = &#038;H90<br />
Public Const KEYEVENTF_EXTENDEDKEY = &#038;H1<br />
Public Const KEYEVENTF_KEYUP = &#038;H2</p>
<p>Public Type OSVERSIONINFO<br />
  dwOSVersionInfoSize As Long<br />
  dwMajorVersion As Long<br />
  dwMinorVersion As Long<br />
  dwBuildNumber As Long<br />
  dwPlatformId As Long<br />
  szCSDVersion As String * 128<br />
End Type</p>
<p>Public Sub ToggleNumLock(TurnOn As Boolean)<br />
'To turn numlock on, set turnon to true<br />
'To turn numlock off, set turnon to false<br />
Dim bytKeys(255) As Byte<br />
Dim bnumLockOn As Boolean<br />
'Get status of the 256 virtual keys<br />
GetKeyboardState bytKeys(0)<br />
bnumLockOn = bytKeys(VK_NUMLOCK)<br />
Dim typOS As OSVERSIONINFO<br />
If bnumLockOn <> TurnOn Then<br />
   If typOS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then<br />
      bytKeys(VK_NUMLOCK) = 1<br />
      SetKeyboardState bytKeys(0)<br />
   Else<br />
      'Simulate Key Press<br />
      keybd_event VK_NUMLOCK, &#038;H45, KEYEVENTF_EXTENDEDKEY Or 0, 0<br />
      'Simulate Key Release<br />
      keybd_event VK_NUMLOCK, &#038;H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0<br />
   End If<br />
End If<br />
End Sub</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>'To turn numlock on...<br />
Call ToggleNumLock(True)</p>
<p>'To turn numlock off...<br />
Call ToggleNumLock(False)</code></p>
<h3>BEEP!</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>Dim X%<br />
X% = Beep(1500, 300)</code></p>
<h3>Disable/Enable Task Manager</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As String, ByVal fuWinIni As Long) As Long</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>'this will disable ctrl+alt+del<br />
Call SystemParametersInfo(97, True, 0&#038;, 0)</p>
<p>'this will enable ctrl+alt+del<br />
Call SystemParametersInfo(97, False, 0&#038;, 0)</code></p>
<h3>Get the Windows User Name</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>Dim X As String<br />
X = String(50, Chr(0))<br />
Call GetComputerName(X$, 50)<br />
MsgBox "Your computer is named: " &#038; X, 32, "Name"</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-10/">Visual Basic Code Snippets #10</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-9/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #8</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-8/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-8/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 00:19:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=78</guid>
		<description><![CDATA[In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions. Ensure Application Can't Load Multiple Times Compatibility: Win. 98-XP This isn't a system function but is definitely essential to any application. Add the following code to the Form_Load() [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.</p>
<h3>Ensure Application Can't Load Multiple Times</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>This isn't a system function but is definitely essential to any application.</p>
<p>Add the following code to the Form_Load() event...</p>
<p><code>If App.PrevInstance Then<br />
    MsgBox ("The application is already open."), vbExclamation, "The requested " &#038; "application is already open"<br />
    Unload Me<br />
End If</code></p>
<h3>Display Internet Properties Dialog</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Function ShowInetProperties() As Boolean<br />
Dim lRet As Long<br />
lRet = Shell("rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,0", vbNormalFocus)<br />
ShowInetProperties = lRet > 0<br />
End Function</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>Call ShowInetProperties()</code></p>
<h3>Toggle CapsLock Key On/Off</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long<br />
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)<br />
Public Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long<br />
Public Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long</p>
<p>Public Const VER_PLATFORM_WIN32_NT = 2<br />
Public Const VER_PLATFORM_WIN32_WINDOWS = 1<br />
Public Const VK_CAPITAL = &#038;H14<br />
Public Const KEYEVENTF_EXTENDEDKEY = &#038;H1<br />
Public Const KEYEVENTF_KEYUP = &#038;H2</p>
<p>Public Type OSVERSIONINFO<br />
   dwOSVersionInfoSize As Long<br />
   dwMajorVersion As Long<br />
   dwMinorVersion As Long<br />
   dwBuildNumber As Long<br />
   dwPlatformId As Long<br />
   szCSDVersion As String * 128<br />
End Type</p>
<p>Public Sub ToggleCapsLock(TurnOn As Boolean)<br />
'To turn capslock on, set turnon to true<br />
'To turn capslock off, set turnon to false<br />
Dim bytKeys(255) As Byte<br />
Dim bCapsLockOn As Boolean<br />
'Get status of the 256 virtual keys<br />
GetKeyboardState bytKeys(0)<br />
bCapsLockOn = bytKeys(VK_CAPITAL)<br />
Dim typOS As OSVERSIONINFO<br />
If bCapsLockOn <> TurnOn Then<br />
   If typOS.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then<br />
      bytKeys(VK_CAPITAL) = 1<br />
      SetKeyboardState bytKeys(0)<br />
   Else<br />
      'Simulate Key Press<br />
      keybd_event VK_CAPITAL, &#038;H45, KEYEVENTF_EXTENDEDKEY Or 0, 0<br />
      'Simulate Key Release<br />
      keybd_event VK_CAPITAL, &#038;H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0<br />
   End If<br />
End If<br />
End Sub</code></p>
<p>Add the following code where you want the code to execute...</p>
<p><code>'To turn capslock on...<br />
Call ToggleCapsLock(True)</p>
<p>'To turn capslock off...<br />
Call ToggleCapsLock(False)</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-9/">Visual Basic Code Snippets #9</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-8/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #7</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-7/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-7/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 23:56:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=74</guid>
		<description><![CDATA[In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions. Get Free Disk Space on Hard Drives Compatibility: Win. 98-XP Add the following code into a module within your project... Public Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.</p>
<h3>Get Free Disk Space on Hard Drives</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long</p>
<p>Public Type DiskInformation<br />
    lpSectorsPerCluster As Long    lpBytesPerSector As Long<br />
    lpNumberOfFreeClusters As Long<br />
    lpTotalNumberOfClusters As Long<br />
End Type</code></p>
<p>Add the following code wherever you want the code to execute...</p>
<p><code>Dim info As DiskInformation<br />
Dim lAnswer As Long<br />
Dim lpRootPathName As String<br />
Dim lpSectorsPerCluster As Long<br />
Dim lpBytesPerSector As Long<br />
Dim lpNumberOfFreeClusters As Long<br />
Dim lpTotalNumberOfClusters As Long<br />
Dim lBytesPerCluster As Long<br />
Dim lNumFreeBytes As Double<br />
Dim sString As String</p>
<p>lpRootPathName = "c:\" 'simply replace this with your hard drive path<br />
lAnswer = GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters)<br />
lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector<br />
lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters<br />
sString = "Number of Free Bytes : " &#038; lNumFreeBytes &#038; vbCr &#038; vbLf<br />
sString = sString &#038; "Number of Free Kilobytes: " &#038; (lNumFreeBytes / 1024) &#038; "K" &#038; vbCr &#038; vbLf<br />
sString = sString &#038; "Number of Free Megabytes: " &#038; Format(((lNumFreeBytes / 1024) / 1024), "0.00") &#038; "MB"<br />
MsgBox sString</code></p>
<h3>Get Windows Directory using API Call</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long<br />
Public Const MAX_PATH = 260</code></p>
<p>Add the following code wherever you want the code to execute...</p>
<p><code>Dim strBuffer As String<br />
Dim lngReturn As Long<br />
Dim strWindowsDirectory As String<br />
strBuffer = Space$(MAX_PATH)<br />
lngReturn = GetWindowsDirectory(strBuffer, MAX_PATH)<br />
strWindowsDirectory = Left$(strBuffer, Len(strBuffer) - 1)</code></p>
<h3>Clear/Add-to Windows Recent Document List</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Sub SHAddToRecentDocs Lib "shell32.dll" (ByVal uFlags As Long, ByVal pv As String)</code></p>
<p>Add the following code wherever you want the Clear Recent Document List code to execute...</p>
<p><code>'clear the entire list<br />
Call SHAddToRecentDocs(2,vbNullString)</code></p>
<p>Add the following code wherever you want to add the file to the list code to execute...</p>
<p><code>'add a new file to list<br />
Dim strNewFile as String<br />
strNewFile="c:\myfile.ext"<br />
Call SHAddToRecentDocs(2,strNewFile)</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-8/">Visual Basic Code Snippets #8</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-7/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #6</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-6/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-6/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 20:31:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=70</guid>
		<description><![CDATA[In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions. Hide/Show Your Application from Task Manager Compatibility: Win. 98-ME Add the following code into a module within your project... Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.</p>
<h3>Hide/Show Your Application from Task Manager</h3>
<p><b>Compatibility:</b> Win. 98-ME</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long<br />
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long<br />
Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long<br />
Public Const RSP_SIMPLE_SERVICE = 1<br />
Public Const RSP_UNREGISTER_SERVICE = 0</p>
<p>Public Sub removeCtrlAltDel()<br />
'only works on win98/ME<br />
   Dim pid As Long<br />
   Dim lngRet As Long<br />
   pid = GetCurrentProcessId()<br />
   lngRet = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)<br />
End Sub</p>
<p>Public Sub showCtrlAltDel()<br />
'only works on win98/ME<br />
   Dim pid As Long<br />
   Dim lngRet As Long<br />
   pid = GetCurrentProcessId()<br />
   lngRet = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)<br />
End Sub</code></p>
<p>Add the following code wherever you want the Hide code to execute...</p>
<p><code>Call removeCtrlAltDel()</code></p>
<p>Add the following code wherever you want the Show code to execute...</p>
<p><code>Call showCtrlAltDel()</code></p>
<h3>Get and Show Windows Runtime</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetTickCount&#038; Lib "kernel32" ()</p>
<p>Public Function windowsRuntime(lbl As Label)<br />
   Dim lngReturn As Long<br />
   lngReturn = GetTickCount()<br />
   lbl.Caption = "Windows has been running for " &#038; (lngReturn / 1000) &#038; " seconds."<br />
End Function</code></p>
<p>Add a label named Label1 to a form and add the following code...</p>
<p><code>Call windowsRuntime(Label1) 'Label1 being the display label.</code></p>
<h3>Add All Available System Fonts to List</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Function AddFontsList(Lis As ListBox)<br />
    For X = 0 To Screen.FontCount - 1<br />
        Lis.AddItem Screen.Fonts(X)<br />
    Next X<br />
End Function</code></p>
<p>Add a ListBox named List1 and add the following code wherever you want the code to execute...</p>
<p><code>Call AddFontsList(List1)</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-7/">Visual Basic Code Snippets #7</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #5</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-5/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-5/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 20:24:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=66</guid>
		<description><![CDATA[In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions. Shutdown/Poweroff Windows Compatibility: Win. 98-XP Add the following code into a module within your project... Public Declare Function ExitWindowsEx Lib "User32" Alias "ExitWindowsEx"(ByVal uFlags As Long, ByVal dwReserved As Long) [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to System Functions.</p>
<h3>Shutdown/Poweroff Windows</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function ExitWindowsEx Lib "User32" Alias "ExitWindowsEx"(ByVal uFlags As Long, ByVal dwReserved As Long) As Long</code></p>
<p>Add the following code into a command button or wherever you want the code to execute...</p>
<p><code>Call ExitWindowsEx(EWX_POWEROFF,0)</code></p>
<h3>Restart Windows</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function ExitWindowsEx Lib "User32" Alias "ExitWindowsEx"(ByVal uFlags As Long, ByVal dwReserved As Long) As Long</code></p>
<p>Add the following code into a command button or wherever you want the code to execute...</p>
<p><code>Call ExitWindowsEx(EWX_REBOOT,0)</code></p>
<h3>Shell Out to Default Web Browser</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long<br />
Public Const conSwNormal = 1</p>
<p>Public Function shellSite(site As String)<br />
ShellExecute hwnd, "open", site, vbNullString, vbNullString, conSwNormal<br />
End Function</code></p>
<p>Add the following code wherever you want the code to execute...</p>
<p><code>Call shellSite("http://www.beneskew.com")</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-6/">Visual Basic Code Snippets #6</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #4</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-4/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-4/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 19:48:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=61</guid>
		<description><![CDATA[In this next update I’ll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms. Save and Load the Position of the Form Compatibility: Win. 98-XP Add the following code into a module within your project... Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I’ll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms.</p>
<h3>Save and Load the Position of the Form</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long<br />
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long</p>
<p>Public Function GetFromINI(Section As String, Key As String, Directory As String) As String<br />
  Dim strBuffer As String<br />
  strBuffer = String(750, Chr(0))<br />
  Key$ = LCase$(Key$)<br />
  GetFromINI$ = Left(strBuffer, GetPrivateProfileString(Section$, ByVal Key$, "", strBuffer, Len(strBuffer), Directory$))<br />
End Function<br />
Public Sub WriteToINI(Section As String, Key As String, KeyValue As String, Directory As String)<br />
    Call WritePrivateProfileString(Section$, UCase$(Key$), KeyValue$, Directory$)<br />
End Sub</code></p>
<p>Add the following code in the Form_Unload event...</p>
<p><code>Call WriteToINI("Main", "Xpos", Form1.Left, App.Path &#038; "\data.ini")<br />
Call WriteToINI("Main", "Ypos", Form1.Top, App.Path &#038; "\data.ini")</code></p>
<p>Add the following code in the Form_Load event...</p>
<p><code>Xpos = GetFromINI("Main", "Xpos", App.Path &#038; "\data.ini")<br />
Ypos = GetFromINI("Main", "Ypos", App.Path &#038; "\data.ini")<br />
Form1.Top = Ypos<br />
Form1.Left = Xpos</code></p>
<h3>Disable the X Button on a Form</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long<br />
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long<br />
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long<br />
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long<br />
Public Const MF_BYPOSITION = &#038;H400&#038;<br />
Public Const MF_DISABLED = &#038;H2&#038;</p>
<p>Public Sub DisableX(Frm As Form)<br />
Dim hMenu As Long<br />
Dim nCount As Long<br />
  hMenu = GetSystemMenu(Frm.hwnd, 0)<br />
  nCount = GetMenuItemCount(hMenu)<br />
  Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)<br />
  DrawMenuBar Frm.hwnd<br />
End Sub</code></p>
<p>Add the following code wherever you want the code to execute...</p>
<p><code>Call DisableX(Me)</code></p>
<h3>Make Form Stay On-Top</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long</p>
<p>Public Const HWND_NOTOPMOST = -2<br />
Public Const HWND_TOPMOST = -1</p>
<p>Public Sub StayOnTop(frm As Form)<br />
'For best results put in the formpaint<br />
Call SetWindowPos(frm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)<br />
End Sub</p>
<p>Public Sub NotOnTop(frm As Form)<br />
'For best results put in the formpaint<br />
Call SetWindowPos(frm.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)<br />
End Sub</code></p>
<p>Add the following code wherever you want the StayOnTop code to execute...</p>
<p><code>Call StayOnTop(Form1) 'Form1 being the form.</code></p>
<p>Add the following code wherever you want the NotOnTop code to execute...</p>
<p><code>Call NotOnTop(Form1) 'Form1 being the form.</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-5/">Visual Basic Code Snippets #5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Basic Code Snippets #3</title>
		<link>http://www.beneskew.com/2009/09/visual-basic-code-snippets-3/</link>
		<comments>http://www.beneskew.com/2009/09/visual-basic-code-snippets-3/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 19:27:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.beneskew.com/?p=55</guid>
		<description><![CDATA[In this next update I’ll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms. Center a Form on the Screen Compatibility: Win. 98-XP Add the following code into a module within your project... Public Sub Form_Center(Frm As Form) 'Usually used in form_load Frm.Left [...]]]></description>
			<content:encoded><![CDATA[<p>In this next update I’ll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms.</p>
<h3>Center a Form on the Screen</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Sub Form_Center(Frm As Form)<br />
    'Usually used in form_load<br />
    Frm.Left = Screen.Width / 2 - Frm.Width / 2<br />
    Frm.Top = Screen.Height / 2 - Frm.Height / 2<br />
End Sub</code></p>
<p>Add a form named Form1 and add the following code wherever you want the code to execute...</p>
<p><code>Call Form_Center(Form1)</code></p>
<h3>Center Form at a Given Point on the Screen</h3>
<p><b>Compatibility:</b> Win. 98-XP</p>
<p>Add the following code into a module within your project...</p>
<p><code>Public Sub Form_CenterAt(Frm As Form, X As Integer, Y As Integer)<br />
   'X: X coordinate to center form at<br />
   'Y: Y coordinate to center form at<br />
   'Example...<br />
   'Form_CenterAt me, screen.width/2, screen.height/2<br />
   Frm.Left = X - Frm.Width / 2<br />
   Frm.Top = Y - Frm.Height / 2<br />
End Sub</code></p>
<p>Add a form named Form1 and add the following code wherever you want the code to execute...</p>
<p><code>Call Form_CenterAt(Form1, screen.width/2, screen.height/2)</code></p>
<p><a href="http://www.beneskew.com/2009/09/visual-basic-code-snippets-4/">Visual Basic Code Snippets #4</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beneskew.com/2009/09/visual-basic-code-snippets-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
