Illustrated tutorial on Visual Basic.NET. Visual Basic language - examples of writing code Vb6 example programs

The function returns a one-dimensional array containing a specified number of substrings. This function is the inverse of the Join function.

Syntax

Split( Expression[, Delimiter[, Limit[, Compare]])

Options

Expression- an expression of String type containing substrings with delimiters.
Delimiter- an expression of Variant (String) type that defines the character that is used as a delimiter. If the argument is omitted, the space character (" ") is used.
Limit- a Long expression indicating the number of elements to return. the default is -1 (return all elements).
Compare- a numeric parameter indicating the comparison method.

Parameter Compare can take the following values:

Return values

Returns a one-dimensional array of type Variant (String).
If the Expression parameter has zero length, the function returns an empty array. If the Delimiter parameter has zero length, the function will return an array with one Expression element.

Usage example

Private Sub Form_Load() Dim arrMyArray() As String Dim strMyString As String strMyString = "Hello! How are you?"

arrMyArray = Split(strMyString) "returns "Hello!" Debug.Print arrMyArray(0) End Sub See also:
Array,
Hi all!
Today I would like to talk about cryptography. I made an example of using special cryptography - steganography. This method hides the very fact of data encryption. There are many types of steganography. I'd like to talk about the LBS method, which hides data in the low-order bits of the audio data. It looks like users are exchanging audio files, but in reality they are exchanging sensitive data. Anyone who does not know about this method will not even suspect the exchange of secret data. In some cases this can be very useful.
How it works?

In our case, we are only interested in the bit depth of the audio data. It can be 32, 24, 16, ... bits per sample. The main idea of ​​steganography (in our case) is to rewrite the low-order bits of audio data. The more bits we use, the stronger the distortion will be.
Visually:


As can be seen from the figure, the method stores all encrypted data in certain bits of audio data (in this case, 4 bits for each sample). Also note that to save data you need to use an audio file larger in size than the encrypted file. For example, if we use 3 bits for encoding, the audio file will need to be at least 16/3 times larger than what is being encoded. I say 16 because I'm using 16 bits per sample in my example.
In the attached example I also keep the original filename. The data format is clear:


When packaging occurs, every byte is taken from the encrypted file. Then the necessary bits are extracted from the next byte, and the corresponding bits in the audio data are also cleared. These bits are then set using a bitwise OR operation. Masks and shifts are used to extract the required bits. Masks leave the necessary bits, and shifts place them at the beginning of the byte.
Unpacking happens exactly the opposite. Bits are extracted from the audio file and the original file is assembled. Spectrum of an audio file depending on bit depth:

I hope this short review will be useful.
Thank you for your attention.

Using the Split function in VBA Excel, its syntax and parameters. Values ​​returned by the Split function. Examples of using.

The Split function is designed in VBA Excel to split a string into substrings using special delimiter marks. The separator can be either a single character or a string of several characters. The Split function is the inverse of the function, which creates one string from an array of substrings.

Function Syntax

Split (Expression,,,)

The required parameter of the Split function is Expression - if the other parameters are not explicitly specified, their default values ​​are used.

Function parameters

*If binary comparison (0 or CompareMethod.Binary) is used, the function is case sensitive. If a text comparison (1 or CompareMethod.Text) is used, the function is not case sensitive.

Return values

The Split function returns a one-dimensional array, indexed from zero, that contains the specified parameter Limit number of substrings. Most often, the Split function is used with the parameter value Limit by default, equal to -1, when all substrings found in the source string are returned.

Example 1

Sub Test1() Dim a() As String a = Split("vremya ne zhdet") MsgBox a(0) & vbNewLine & a(1) & vbNewLine & a(2) End Sub Result in MsgBox: time ne zhdet

The first example uses Delimiter And Limit default.

Example 2

Sub Test2() Dim a() As String a = Split("vremya-ne-zhdet","-", 2) MsgBox a(0) & vbNewLine & a(1) End Sub Result in MsgBox: time ne-zhdet

In the second example Delimiter= "-", a Limit = 2.

The Split function assigns results using a predeclared text , which can be used in the assignment line with or without empty parentheses. In the examples above, the array is specified without parentheses.

You can copy the codes from the given examples into the VBA module of your Excel workbook and see how they work. Experiment with substituting your own data to get a hands-on feel for the Split feature.

Hello everyone, in this article I want to show you useful codes for small programs. Which you can use to write your own more serious programs, or you were looking for exactly these functions that are described here.

All codes were used in the Microsoft Visual Basic v6.0 programming environment.

Exit with confirmation

The first kind of program, or function, is an exit with a message confirming the exit. In general, open the Visual Basic programming environment, create a standard project, then place one button on the form, click on the button and the code editing window will open, and you need to insert the following code there:

Beep Dim message As String Dim buttonsandicons As Integer Dim title As String Dim response As String message = "Do you want to go out?"" buttonasicons = vbYesNo + vbQuestion response = MsgBox(message, buttonasicons, title) If response = vbYes Then End End If !}

title = "Exit

Password to start the program<>Dim Password, Pword PassWord = "12345" Pword = InputBox("Enter password") If Pword

PassWord Then MsgBox "Password is not correct" End End If

Where, 12345 is the password to start the program. But this code can be used wherever you want.

Message output

If you just want to display a message for something, then paste this:" buttonasicons = vbOKOnly + vbexciamation MsgBox message, buttonsandicons, title !}

Beep Dim message As String Dim buttonsandicons As Integer Dim title As String message = "Message" title = "Message

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Form1.CurrentX = X Form1.CurrentY = Y End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Line (Form1.CurrentX, Form1.CurrentY)-(X, Y), QBColor(0) End If End Sub

You can change the color using the QBColor(0) parameter, i.e. Instead of 0, put another number.

Restarting the computer

To reboot your computer: place the button and paste the following code:

Dim strComputer As String strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "(impersonationLevel=impersonate, (Shutdown))!\\" _ & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each ObjOperatingSystem In colOperatingSystems ObjOperatingSystem.Reboot " To reboot Next

Launching a program in a single copy

The following example will help you make the program run only once, i.e. if it is restarted, it will display a corresponding message. Insert the following into the form code:

Private Sub Form_Load() If App.PrevInstance = True Then MsgBox "The project has already started!"

End End If

Turning off the computer

To turn off your computer you can use the following code:

Dim strComputer As String strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "(impersonationLevel=impersonate,(Shutdown))!\\" _ & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each ObjOperatingSystem In colOperatingSystems ObjOperatingSystem.ShutDown "To shut down Next

Ending any process

To terminate the process you can use the following code:

Shell "Cmd /x/c taskkill /f /im ICQlite.exe", vbvhite

Private Declare Function GetTickCount Lib "kernel32" () As Long "And in the button code: Dim a_hour, a_minute, a_second a = Format(GetTickCount() / 1000, "0") "total seconds a_days = Int(a / 86400) a = a - a_days * 86400 a_hour = Int(a / 3600) a = a - a_hour * 3600 a_minute = Int(a / 60) a_second = a - a_minute * 60 MsgBox "Your computer is running " & Str(a_days) & " days " & Str(a_hour) _ & " hours " & Str(a_minute) & " minutes" & Str(a_second) & " seconds"

We looked at simple functions that can be used almost anywhere. Now let's look at more serious examples, and they can greatly help you write your large projects.

Examples of working with folders

Delete directory

Private Declare Function RemoveDirectory& Lib _ "kernel32" Alias ​​"RemoveDirectoryA" (ByVal lpPathName As String) "Removing directory (empty!) PathName$ = "D:\t" code& = RemoveDirectory(PathName) If code& = 0 Then "Error removing directory Else "Directory deleted End If

Create directory

Sub MakeDir(dirname As String) Dim i As Long, path As String Do i = InStr(i + 1, dirname & "\", "\") path = Left$(dirname, i - 1) If Right$(path , 1)<>":" And Dir$(path, vbDirectory) = "" Then MkDir path End If Loop Until i >= Len(dirname) End Sub Private Sub Command1_Click() Call MakeDir("C:\Soft\1\2\3\ ") End Sub

List all folders with sub folders

We add 2 text fields and a button to the form, the name of the first text field is StartText, the name of the second text field is OutText. Multiline property = true, button name = CmdStart

Static running As Boolean Dim AllDirs As New Collection Dim next_dir As Integer Dim dir_name As String Dim sub_dir As String Dim i As Integer Dim txt As String If running Then running = False CmdStart.Enabled = False CmdStart.Caption = "Stopping" Else running = True MousePointer = vbHourglass CmdStart.Caption = "Stop" OutText.Text = "" DoEvents next_dir = 1 AllDirs.Add StartText.Text Do While next_dir<= AllDirs.Count dir_name = AllDirs(next_dir) next_dir = next_dir + 1 sub_dir = Dir$(dir_name & "\*", vbDirectory) Do While sub_dir <>"" If UCase$(sub_dir)<>"PAGEFILE.SYS" And sub_dir<>"." And sub_dir<>".." Then sub_dir = dir_name & "\" & sub_dir On Error Resume Next If GetAttr(sub_dir) And vbDirectory Then AllDirs.Add sub_dir End If sub_dir = Dir$(, vbDirectory) Loop DoEvents If Not running Then Exit Do Loop txt = "" For i = 1 To AllDirs.Count txt = txt & AllDirs(i) & vbCrLf Next i OutText.Text = txt MousePointer = vbDefault unning = False End If

Now we launch the program, write in the StartText text field: C:\windows, and click on the button.

Directory size

Const MAX_PATH = 260 Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type Private Declare Function FindFirstFile Lib _ "kernel32" Alias ​​"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindNextFile Lib _ "kernel32" Alias ​​"FindNextFileA" (ByVal hFindFile As Long, ileData As WIN32_FIND_DATA) As Long Private Declare Function FindClose Lib _ "kernel32" (ByVal hFindFile As Long) As Long Public Function SizeOf(ByVal DirPath As String) As Double Dim hFind As Long Dim fdata As WIN32_FIND_DATA Dim dblSize As Double Dim sName As String Dim x As Long On Error Resume Next x = GetAttr(DirPath) If Err Then SizeOf = 0: Exit Function If (x And vbDirectory) = vbDirectory Then dblSize = 0 Err.Clear sName = Dir$(EndSlash(DirPath) & "*.* ", vbSystem Or vbHidden Or vbDirectory) If Err.Number = 0 Then hFind = FindFirstFile(EndSlash(DirPath) & "*.*", fdata) If hFind = 0 Then Exit Function Do If (fdata.dwFileAttributes And vbDirectory) = vbDirectory Then sName = Left$(fdata.cFileName, InStr(fdata.cFileName, vbNullChar) - 1) If sName<>"." And sName<>".." Then dblSize = dblSize + SizeOf(EndSlash(DirPath) & sName) End If Else dblSize = dblSize + fdata.nFileSizeHigh * 65536 + fdata.nFileSizeLow End If DoEvents Loop While FindNextFile(hFind, fdata)<>0 hFind = FindClose(hFind) End If Else On Error Resume Next dblSize = FileLen(DirPath) End If SizeOf = dblSize End Function Private Function EndSlash(ByVal PathIn As String) As String If Right$(PathIn, 1) = "\" Then EndSlash = PathIn Else EndSlash = PathIn & "\" End If End Function Private Sub Form_Load() "Replace "D:\soft" with the directory whose size you want to know MsgBox SizeOf("D:\soft") / 1000000 End Sub

Examples of working with files

Copy

Let's say we have a file named 1.txt in the C:\1\ folder, and we need to copy it to C:\2\ to do this we write the following code:

Filecopy "C:\1\1.txt","C:\2\1.txt"

Note! If directory 2 already contains a file named 1.txt, it will be replaced with 1.txt from directory 1.

Private Declare Function CopyFile Lib _ "kernel32.dll" Alias ​​"CopyFileA" _ (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Sub Command1_Click() " Copy file C:\1.txt to D :\1.txt. Dim retval As Long " return value "Copy the file retval = CopyFile("C:\1.txt", "D:\1.txt", 1) If retval = 0 Then "If error MsgBox " I can't copy" Else "If everything is fine MsgBox "File copied." End If End Sub

Removal

For example, we want to delete file 1.txt from the root of the C:\ drive

Kill("C:\1.txt")

API method

Private Declare Function DeleteFile Lib _ "kernel32.dll" Alias ​​"DeleteFileA" (ByVal lpFileName As String) As Long Private Sub Command1_Click() "Delete file C:\Samples\anyfile.txt Dim retval As Long "Return value retval = DeleteFile( "C:\1.txt") If retval = 1 Then MsgBox "The file was successfully deleted."

End Sub

Moving

You can, for example, move it like this:

Filecopy "C:\1.txt","C:\2\1.txt" Kill ("C:\1.txt")

But it's better like this (via API):

Private Declare Function MoveFile Lib _ "kernel32.dll" Alias ​​"MoveFileA" _ (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long Private Sub Command1_Click() Dim retval As Long "Return value retval = MoveFile("C:\1 .txt", "C:\2\1.txt") If retval = 1 Then MsgBox "Moved successfully" Else MsgBox "Error" End If End Sub

Renaming

In order to rename the file 1.txt located in C:\ to 2.txt, you can use the following code:

API method

Filecopy "C:\1.txt","C:\2.txt" Kill ("C:\1.txt")

Private Declare Function MoveFile Lib _ "kernel32.dll" Alias ​​"MoveFileA" _ (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long Private Sub Command1_Click() Dim retval As Long " return value retval = MoveFile("C:\1 .txt", "C:\2.txt") If retval = 1 Then MsgBox "Success" Else MsgBox "Error" End If End Sub

Determine file size

The file size can be determined in two ways:

If the file can be opened with the OPEN function, then you can use the LOF function

Dim FileFree As Integer Dim FileSize As Long FileFree = FreeFile Open "C:\WIN\GENERAL.TXT" For Input As FileFree FileSize = LOF(FileFree) Close FileFree

Or use the FileLen function

Dim lFileSize As Long FileSize = FileLen("C:\WIN\GENERAL.TXT")

Hide clock programmatically

Option Explicit Private Declare Function FindWindow Lib _ "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib _ "user32" Alias ​​"FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function ShowWindow Lib _ "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Dim hnd As Long Private Sub Command1_Click() ShowWindow hnd, 0 End Sub Private Sub Command2_Click() ShowWindow hnd, 1 End Sub Private Sub Form_Load() hnd = FindWindow("Shell_TrayWnd", vbNullString) hnd = FindWindowEx(hnd, 0, "TrayNotifyWnd", vbNullString) hnd = FindWindowEx(hnd, 0, "TrayClockWClass", vbNullString) Command1.Caption = "Hide clock" Command2.Caption = "Show clock" End Sub

Add tray icon

Add a module and paste the code into it:

Declare Function Shell_NotifyIconA Lib _ "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer Public Const NIM_ADD = 0 Public Const NIM_MODIFY = 1 Public Const NIM_DELETE = 2 Public Const NIF_MESSAGE = 1 Public Const NIF_ICON = 2 Public Const NIF_TIP = 4 Type NOTIFYICONDATA cbSize As Long hWnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 64 End Type Public Function SetTrayIcon(Mode As Long, hWnd As Long, Icon As Long, tip As String) As Long Dim nidTemp As NOTIFYICONDATA nidTemp.cbSize = Len(nidTemp) nidTemp.hWnd = hWnd nidTemp.uID = 0& nidTemp.uFlags = NIF_ICON Or NIF_TIP nidTemp.uCallbackMessage = 0& nidTemp.hIcon = Icon nidTemp.szTip = tip & Chr$( 0) SetTrayIcon = Shell_NotifyIconA(Mode, nidTemp) End Function

To use, insert into the form code:

Private Sub Form_Load() SetTrayIcon NIM_ADD, Me.hWnd, Me.Icon, "Test" End Sub "To delete a Private Sub Command1_Click() SetTrayIcon NIM_DELETE, Me.hWnd, 0&, "" End Sub

Blocking the start button

Private Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias ​​"FindWindowExA" _ (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function EnableWindow Lib "user32" _ (ByVal hwnd As Long, ByVal fEnable As Long) As Long Public Sub EnableStartButton(Optional Enabled As Boolean = True) Dim lHwnd As Long " find hWnd lHwnd& = FindWindowEx(FindWindow("Shell_TrayWnd", ""), 0&, "Button", vbNullString) Call EnableWindow(lHwnd&, CLng(Enabled)) End Sub Private Sub Command1_Click() EnableStartButton False "START button is disabled End Sub Private Sub Command2_Click() EnableStartButton True "START button is not disabled End Sub

Reading parameters from the INI file

The program connects to FTP, and the ini file contains the parameters - server, login, port, password.

First, create an INI file:

Servname=server usern=Login pwd=password port=port

It must be placed in the program folder. Next, insert into the module:

Private Declare Function WritePrivateProfileString Lib _ "kernel32" Alias ​​"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, _ ByVal lpString As String, ByVal lpFileName As String) As Long Private Declare Function GetPrivateProfileString Lib _ "kernel32" Alias ​​"GetP rivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, _ ByVal lpDefault As String, ByVal lpReturnedString As String, _ ByVal nSize As Long, ByVal lpFileName As String) As Long Public Function ReadIni(Razdel As String, Param) As String ReadIni = GetValue (Razdel, Param, App.Path & "\test.ini", "0") End Function Private Function GetValue(ByVal Section As String, _ ByVal Key As String, ByVal fFileName As String, Optional ByVal DefaultValue As String = vbNullString) As String Dim Data As String Data = String$(1000, Chr$(0)) If GetPrivateProfileString(Section, Key, DefaultValue, Data, 1000, fFileName) > 0 Then GetValue = Left$(Data, InStr(Data$, Chr $(0)) - 1) Else GetValue = DefaultValue End If Exit Function End Function

Then paste into the form code:

Private Declare Function InternetOpen Lib _ "wininet.dll" Alias ​​"InternetOpenA" (ByVal sAgent As String, ByVal nAccessType As Long, ByVal sProxyName As String, _ ByVal sProxyBypass As String, ByVal nFlags As Long) As Long Private Declare Function InternetConnect Lib _ "wininet.dll" Alias ​​"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, _ ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal nService As Long, _ ByVal dwFlags As Long, ByVal dwContext As Long) As Long Private Declare Function FtpPutFile Lib _ "wininet.dll" Alias ​​"FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean Private Declare Function FtpGetFile Lib _ "wininet.dll" Alias ​​"FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, ByVal d wContext As Long ) As Boolean Private Declare Function InternetCloseHandle Lib _ "wininet.dll" (ByVal hInet As Long) As Integer Dim rc& Dim rs&

And in the button code:

rc& = InternetOpen("", 0, vbNullString, vbNullString, 0) rs& = InternetConnect(rc&, ReadIni("General", "servname"), "0", _ ReadIni("General", "usern"), ReadIni( "General", "pwd"), 1, 0, 0) If FtpGetFile(rs&, "Your file.txt", "path where", False, 0, 1, 0) = False Then End Call InternetCloseHandle(rs&) Call InternetCloseHandle(rc&)

List of running processes

Add a Listbox and 1 button, insert the following code:

Option Explicit Private Declare Function CreateToolhelpSnapshot Lib _ "Kernel32" Alias ​​"CreateToolhelp32Snapshot" _ (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function ProcessFirst Lib _ "Kernel32" Alias ​​"Process32First" _ (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib _ "Kernel32" Alias ​​"Process32Next" _ (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long) Private Const TH32CS_SNAPPROCESS As Long = 2& Private Const MAX_PATH As Integer = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type Di m hSnapShot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long Private Sub Command1_Click() List1.Clear hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Sub End If uProcess.dwSize = Len(uProcess) r = ProcessFirst(hSnapShot, uProcess) Do While r List1.AddItem uProcess.szExeFile r = ProcessNext(hSnapShot, uProcess) Loop Call CloseHandle(hSnapShot) End Sub

Putting a program into startup

In order for the program to load with Windows, like some other programs, you can use the registry:

Add 2 buttons and the following code:

Private Sub Command1_Click() "Registry entry Set Reg = CreateObject("WScript.Shell") Reg.RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\Name of your program", _ "Path to your program" End Sub Private Sub Command2_Click() "Delete from the registry Set Reg = CreateObject("WScript.Shell") Reg.RegDelete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\Name of your program" End Sub

And in order for the program to load along with Windows, even in safe mode, then the following code:

First, a more serious method (make a backup copy of the registry just in case).

Private Sub Command1_Click() Set Reg = CreateObject("WScript.Shell") Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Shell", _ "Path to your program" End Sub Private Sub Command2_Click()" This is for recovery Set Reg = CreateObject("WScript.Shell") Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Shell", _ "Explorer.exe," End Sub

Well, a simple way.

Private Sub Command1_Click() Set Reg = CreateObject("WScript.Shell") Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Userinit", _ "C:\\WINDOWS\\system32\\userinit.exe ,Path to your program" End Sub Private Sub Command2_Click()"To restore Set Reg = CreateObject("WScript.Shell") Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\Userinit", _ "C: \\WINDOWS\\system32\\userinit.exe," End Sub

Hiding the taskbar

Add 2 buttons and paste the code:

Private 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 Private Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Const SWP_HIDEWINDOW = &H80 Const SWP_SHOWWINDOW = &H40 "Hide Private Sub Command1_Click() hwnd1 = FindWindow("Shell_traywnd", "") Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_HIDEWINDOW) End Sub "Shows Private Sub Command2_Click() hwnd1 = FindWindow("Shell_traywnd", "") Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_SHOWWINDOW) End Sub

Unzip RAR archive

In order to unzip the RAR archive, you can use the following code:

WinRarApp = "C:\Program Files\WinRAR\WinRAR.exe x -o+" iPath = "C:\" iArhivName = "File name.rar" adr = WinRarApp & " """ & iPath & iArhivName & """ " "" & iPath & """ " RetVal = Shell(adr, vbHide)

How much RAM is in the computer

Add one button and paste the following code:

Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As TMemoryStatus) Private Type TMemoryStatus dwLength As Long dwMemoryLoad As Long dwTotalPhys As Long dwAvailPhys As Long dwTotalPageFile As Long dwAvailPageFile As Long dwTotalVirtual As Long dwAvailVirtual As Long End Type Dim s As TMemoryStatus Private Sub Command1_Click( ) ms.dwLength = Len(ms) Call GlobalMemoryStatus(ms) MsgBox "Total:" & ms.dwTotalPhys & vbCr & "Free:" _ & ms.dwAvailPhys & vbCr & "Used in %:" & ms.dwMemoryLoad End Sub

Hide desktop icons

This is done as follows. Add 2 buttons and paste the following code:

Private Declare Function ShowWindow& Lib "user32" (ByVal hwnd&, ByVal nCmdShow&) Private Declare Function FindWindow Lib _ "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Const SW_HIDE = 0 Const SW_NORMAL = 1 Private Sub Command1_Click() Dim hHandle As Long hHandle = FindWindow("progman", vbNullString) Call ShowWindow(hHandle, SW_HIDE) End Sub Private Sub Command2_Click() Dim hHandle As Long hHandle = FindWindow("progman", vbNullString) Call ShowWindow(hHandle , SW_NORMAL) End Sub

Using the Command1 button, the icons are hidden, Command2 - they appear.

That's all for me, I hope the above examples will be useful to you, bye!

This chapter introduces the basic "arsenal" of VB.NET. Most of the material consists of a brief overview of concepts common to all programming languages ​​(such as variables and looping instructions) and a description of basic data types, mainly various numbers and strings. Readers familiar with VB6 may want to skim this chapter.

Only a few examples in this chapter contain actual code that can be used in serious VB.NET programs. The fact is that no serious VB.NET program can do without template-based objects called classes, a topic that will be discussed in Chapter 4. We will start with the basic constructs of the language, because otherwise we would have to limit ourselves to primitive classes that have no practical value. This chapter does not cover user-defined classes and shows only basic examples of how to use the .NET Framework's built-in classes, which are extremely powerful.

What follows from this? Oddly enough, the programs written in this chapter are very close in style to traditional programming of the early BASIC era and even the Fortran and COBOL era that preceded it (apart from some strange but necessary syntactic constructs). In particular, unlike the programs in later chapters, they always have a clearly defined beginning and end, and control is transferred from beginning to end (although control can be transferred by special commands).

As stated in the introduction, we will try to present programs written in normal .NET style, avoiding artificial compatibility with VB6 whenever possible.

Every VB.NET application must have an entry point. The entry point contains code that is automatically executed at startup, after which control is transferred to the rest of the program code. In relatively simple graphics applications, the entry point may be associated with the initial form, as in VB6. But as we saw in Chapter 1, Windows Forms code is quite complex and finding the entry point can be challenging. This chapter only covers console applications that run in a console window (like a DOS session window). Yes, VB.NET makes it easy to create traditional console applications often used in server-side scripting programming.

The entry point of a console application is the procedure Sub Main module (analogous to the procedure Sub Main in VB6). If you select the console application icon ( Console Application), VB.NET automatically generates a "skeleton" application with an entry point - a procedure Sub Main:

Module Module1 Sub Main() End Sub End Module

Unlike VB6, the first line specifies the name of the module (the command is in bold). This example uses the default name Modul el. According to the rules, the module name must match the file name. Let's say you changed the module name in the first line: Module Test1. When you try to run a console application, you receive an error message:

Startup code "Sub Main" was specified in "Test.Modulel". but "Test.Modulel" was not found

Renaming a module after it has been created is done as follows:

  1. Change the module name in the program window.
  2. Change the module file name in the solution window.
  3. Right click on the line ConsoleApplication solution window and select the command from the context menu Properties.
  4. Make sure it's listed Startup object In the dialog box that appears (Fig. 3.1), the module name is selected.

By analogy with VB6, a VB.NET program (solution) can consist of several modules, but the presence of a procedure Sub Main only allowed in one module. The application terminates upon reaching the command End Sub procedures Sub Main. For example, the legendary "Hello world" program looks like this:

Module Modul el Sub Main() Console.WriteLine("Hello world") End Sub End Module

If you run this program in the IDE, a DOS window with the words “Hello world” will very quickly flash on the screen (and immediately disappear). The window closes when the command is processed End Sub.