Visual Basic.   Visual Basic

..........................................................................................................................

[ ] [ ] [ ] [ ] [ ] [ Microsoft Agent 2.0 ] [ ] [ ] [ ]
..........................................................................................................................


87 Visual Basic'a


C

  1. ALIAS-
  2. FAST CODE
  3. VB
  4. STANDALONE
  5. OBJECT BROWSER
  6. BENCHMARK
  7. APP.PATH UNC-
  8. , IIF SWITCH
  9. CHOOSE
  10. GOSUBS
  11. ARRAY -
  12. AUTOMATION MANAGER HIDDEN
  13. ջ
  14. SAVESETT
  15. VB
  16. "FILE EXIST"
  17. ,
  18. - -
  19. DOUBLE CLICK
  20. CTRL ITEM LIST
  21. WINDOWS 95/NT
  22. ,
  23. TREEVIEW
  24. VB SENDTO
  25. " " VB
  26. USERID WINDOWS 95/NT
  27. ( )
  28. !
  29. API
  30. VAL
  31. ID
  32. COMBOBOXE
  33. WIN32
  34. ?
  35. ,
  36. ARRAY
  37. OPTION BUTTONS
  38. CHECK-BOX INTEGER
  39. DBGride
  40. POP-UP TITLE BAR
  41. API
  42. GETSETTING
  43. VB
  44. "&" LABEL
  45. ENABLE FALSE
  46. POPUP MENU TEXT BOXES
  47. TYPENAME
  48. TEXT BOX
  49. VAL
  50. INTERNET
  51. HELP-
  52. MDI DESIGN-TIME
  53. , !
  54. BACKQUOTES
  55. , WINDOWS 95

1

, , Enter . -, : Change Click. -, Enter , (.. ). , Change, / () , , , . , Lost Focus , , , , , . Click, , . Declarations

' VB3 integer
Dim bNoise as Boolean
' True , ,

Form_Load:

bNoise = False

KeyDown :

Private Sub cbTest_KeyDown(KeyCode As _
Integer, Shift As Integer)
'
' Click
If KeyCode = vbKeyDown Or KeyCode _
= vbKeyUp Then bNoise = True
End Sub

Click :

Private Sub cbTest_Click()
If bNoise Then
' Ignore Noise events
' (up or down arrow)
bNoise = False
Else
'
SendKeys "{TAB}", True
End If
End Sub

, , LostFocus .


2.

VB5
Level: Beginning

VB 5.0 , . , , . , Comment/Uncomment Edit, :-(. Edit, VB, Edit.



ޠ


3.

VB5
Level: Beginning

- VB4, (Optional parameters). VB5 : ( Variants), Property. , .

Property Get Value _
(Optional index As Long = 1)
End Property

( ) IsMissing:

Property Get Value _
(Optional index As Long)
If IsMissing(index) Then index = 1
...
End Property


4. ALIAS-

VB5
Level: Beginning

e , (??). 100% , , Assume No Aliasing Advanced Optimizations, Compile Project Properties (, , ). native code , alias- , , RAM . .



5.

VB5
Level: Beginning

, . , vbStartUpScreen (=2) StartUpPosition ( 5). , vbStartUpOwner (=1). Property . , Show.

Form2.Show vbModal, Me


6. FAST CODE

VB5
Level: Beginning

native code , "Optimize for Fast Code". , , . , , , ( ), . , RAM, , , . , P-code. , UI- , native-code . , , , VB Application Performance Explorer (APE), VB CD.


7.

VBA5
Level: Beginning

Office 97, Word 97 business-application engine, , engine. Excel PowerPoint , . , Word 2 VBA : (, Word) ( Word ), Word. , Excel PowerPoint, , VBA . . , , , .


8. VB

VB5
Level: Beginning

IDE VB5:
, General ( ), Add Tab. , , drag-and-drop.
, Customize. Commands, , . Project-References,Project-Properties, Tools-Add Procedure.
Toolbars Customize. , , . Customize, , , / ..


9.

VB5
Level: Beginning

, . , , , Project Explorer , , , . , . , General Tools-Options.


10. STANDALONE

VB4 16/32, VB5 (Enterprise Edition)
Level: Intermediate

Ko out-of-process OLE , VB (companion type library) EXE-, .TLB . , Enterprise Edition VB4 VB5, Remote Server File, VB standalone . VB5, Component Properties Project.


11. OBJECT BROWSERa

VB5
Level: Intermediate
Object Browser (, ), Show Hidden Members. , Object Browser hidden- ( ) , .
, VBA hidden _HiddenModule, VBA : ObjPtr, StrPtr, VarPtr. ObjPtr private area , StrPtr , VarPtr (string descriptor), string.


12.

VB4 16/32
Level: Advanced

VB5 VarPtr (. OBJECT BROWSERa ), VB4. Runtime library VB4 , :

#If Win16 Then
Declare Function VarPtr Lib "VB40016.DLL" (variable As Any) As Long
#Else
Declare Function VarPtr Lib "VB40032.DLL" (variable As Any) As Long
#End If

(Type structure) API, - .


13. BENCHMARK ( )

VB4 16/32, VB5
Level: Intermediate

, VB Timer . , , , , Timer, . , Now.

Dim startTime As Date
StartTime = Now
' the code to be benchmarked
' ...
Print "elapsedSeconds = " & Format$ ((Now - startTime) * 86400, "#####")

Format$ .


14. APP.PATH UNC-


VB5
Level: Intermediate

VB4, App.Path VB5 UNC-, "\\server\programs\...", , VB IDE EXE-. , App.Path .

ChDrive App.Path
ChDir App.Path

ChDrive UNC-, , On Error Resume Next. , . , , INI-. , . Q167167 Microsoft Knowledge Base.


15

VB4 16/32, VB5
Level: Advanced
, Variant. , :

' return the number of items
Function ItemCount(anArray As Variant) As Long
ItemCount = UBound(anArray) - LBound(anArray) + 1
' the first element is
' anArray(LBound(anArray))
End Function

, , , UBound Lbound :

Function ItemCount(anArray As Variant)As Long
Dim items As Long, i As Integer
On Error Resume Next
items = UBound(anArray) - LBound(anArray) + 1
For i = 2 to 999
items = items * (UBound(anArray, _
i) - LBound(anArray, i) + 1)
If Err Then Exit For
Next
ItemCount = items
End Function


16. , IIF SWITCH

VB4 16/32, VB5
Level: Intermediate
If...Then...Else Iif:

'
maxValue = IIf(first >= second,first, second)

Switch - , , If...ElseIf:

' , , , 0?
Print Switch(x < 0, "negative", x > 0, _
"positive", True, "Null")

, True, .


17. CHOOSE

VB3, VB4 16/32, VB5
Level: Beginning

Choose , , (compile-time), , (run time). , 1 10, (Choose , ):

Function Factorial(number As Integer) _
As Long
Factorial = Choose(number, 1, 2, 6, _
24, 120, 720, 5040, 40320, _
362880, 3628800)
End Function


18. GOSUBS

VB5
Level: Intermediate

GoSubs , . VB5 native code, , GoSubs , .


19. ARRAY -

VB5
Level: Intermediate

, , "array" , VB5. (reserved keyword) . Replace IDE VB5, "Find whole words only".


20. AUTOMATION MANAGER HIDDEN

VB4 16/32, VB5 Enterprise Edition
Level: Advanced

OLE Remote Automation, Automation Manager OLE remote communication. , visible, , . Automation Manager, /Hidden:
C:\Windows\System\AutMgr32.Exe /Hidden
, . , . Q138067 in the Microsoft Knowledge Base.


21.

VB4 16/32, VB5
Level: Advanced

(popup menus) , , VB4 16/32 VB5. , , . , . Click, , . , . Q167839 in the Microsoft Knowledge Base.



22.

VB4 16/32, VB5
Level: Intermediate
, (Collection) , . , list-box :

Sub Remove_Duplicates(arr() As String)
Dim i As Long
Dim RawData As String
Dim DataValues As New Collection

On Error Resume Next
' 457 - Duplicate key
For i = LBound(arr) To UBound(arr)
RawData = arr(i)
DataValues.Add RawData, RawData
' Run-time error 457 ,
Next
On Error GoTo 0

' List Box
' ( Sorted True)
lstSortedData.Clear
For Each DataValue In DataValues
lstSortedData.AddItem DataValue
Next
End Sub


23. ջ

VB3
Level: Intermediate

, . , ʻ , resize . , , , text box, TextCommand, Change :

Sub TextCommand_Change ()
Dim msg as string
msg = Trim$(Me.TextCommand.Text)
If Len(msg) = 0 Then Exit Sub

Select Case msg
Case "COMMAND_RESIZE"
Call MyFormResize
Case "COMMAND_REPAINT"
Call MyFormPaint
...
End Select
Me.TextCommand = ""
End Sub

, TextCommand:

Sub Command1_Click ()
formB.TextCommand = "COMMAND_RESIZE"
DoEvents
End Sub

MDI :

Dim f As Form
Set f = Me.ActiveForm
f.TextCommand = "COMMAND_RESIZE"

VB4 VB5, Public- .


24. SAVESETTING

VB4 16/32, VB5
Level: Intermediate
SaveSetting GetSetting . :

Public Sub FormPosition_Get(F As Form)
' F
' ini/reg
'
Dim buf As String
Dim l As Integer, t As Integer
Dim h As Integer, w As Integer
Dim pos As Integer

buf = GetSetting(app.EXEName, _
"FormPosition", F.Tag, "")
If buf = "" Then
' defaults
F.Move (Screen.Width - F.Width) \ _
2, (Screen.Height - F.Height) \ 2
Else
' l,t,w,h
pos = InStr(buf, ",")
l = CInt(Left(buf, pos - 1))
buf = Mid(buf, pos + 1)
pos = InStr(buf, ",")
t = CInt(Left(buf, pos - 1))
buf = Mid(buf, pos + 1)
pos = InStr(buf, ",")
w = CInt(Left(buf, pos - 1))
h = CInt(Mid(buf, pos + 1))
F.Move l, t, w, h
End If
End Sub

Public Sub FormPosition_Put(F As Form)
' op,left,height
' width F reg/ini
Dim buf As String
buf = F.left & "," & F.top & "," & _
F.Width & "," & F.Height
SaveSetting app.EXEName,_
"FormPosition", F.Tag, buf
End Sub

Load Unload . Tag,

Sub Form_Load()
FormPosition_Get Me
End Sub
Sub Form_Unload()
FormPosition_Put Me
End Sub


25. VB

VB4 16/32, VB5
Level: Beginning

VB . , message box, :

rc = MsgBox(msg, 4 + 32 + 256, "Confirm Delete")

?

rc = MsgBox(msg, vbYesNo + vbQuestion _
+ vbDefaultButton2, _
"Confirm Delete")

check box:

VbUnchecked =0
VbChecked =1
VbGrayed =2

chr$( ASCII):

vbTab instead of Chr$(9)
vbCr instead of Chr$(13)
vbLf instead of Chr$(10)
vbCrLf instead of Chr$(13)+Chr$(10)




26 "FILE EXIST"

VB3, VB4 16/32, VB5
Level: Intermediate

Dir$ runtime error, . , Dir$ ("d:\win\himems.sys") , d: . , :

Function FileExist(filename As String) _
As Boolean
On Error Resume Next
FileExist = Dir$(filename) <> ""
If Err.Number <> 0 Then FileExist _
= False
On Error GoTo 0
End Function


27. ,

VB4 16/32, VB5
Level: Intermediate

VB , , . , enable/disable :

EnableAll True, Text1, Text2, _
Command1, Command2

, :

Sub EnableAll(Enabled As Boolean, _
ParamArray objs() As Variant)
Dim obj As Variant
For Each obj In objs
obj.Enabled = Enabled
Next obj
End Sub


28

VB3, VB4 16/32, VB5
Level: Intermediate
-, , Scroll ( ) . , :

Dim StartX As Long, StartY As Long
Dim Moving As Boolean

Finally, declare these three events for PicPicture:
, PicPicture:

Private Sub PicPicture_MouseDown_
(Button As Integer, Shift As _
Integer, x As Single, y As Single)
StartX = x
StartY = y
Moving = True
End Sub

Private Sub PicPicture_MouseMove_
(Button As Integer, Shift As _
Integer, x As Single, y As Single)
If Moving Then
PicPicture.Move _
PicPicture.Left + x - StartX, PicPicture.Top + y - StartY
End If
End Sub

Private Sub PicPicture_MouseUp_
(Button As Integer, Shift As _
Integer, x As Single, y As Single)
Moving = False
End Sub

. .



29.

VB3, VB4 16/32, VB5
Level: Intermediate

/ . : 1 10 ASCII , . EncryptPassword DecryptedPassword, /, / Number. . XOR, . Number 10, ASCII. DecryptPassword , XOR, .

Function EncryptPassword(Number As _
Byte, DecryptedPassword As String)
Dim Password As String, Counter As Byte
Dim Temp As Integer

Counter = 1
Do Until Counter = _
Len(DecryptedPassword) + 1
Temp = Asc(Mid(DecryptedPassword, _
Counter, 1))
If Counter Mod 2 = 0 Then
'see if even
Temp = Temp - Number
Else
Temp = Temp + Number
End If
Temp = Temp Xor (10 - Number)
Password = Password & Chr$(Temp)
Counter = Counter + 1
Loop
EncryptPassword = Password
End Function

Function DecryptPassword(Number As _
Byte, EncryptedPassword As String)
Dim Password As String, Counter As Byte
Dim Temp As Integer

Counter = 1
Do Until Counter = _
Len(EncryptedPassword) + 1
Temp = Asc(Mid(EncryptedPassword, _
Counter, 1)) Xor (10 - Number)
If Counter Mod 2 = 0 Then 'see if even
Temp = Temp + Number
Else
Temp = Temp - Number
End If
Password = Password & Chr$(Temp)
Counter = Counter + 1
Loop
DecryptPassword = Password
End Function


30. - -

VB4 16/32, VB5
Level: Intermediate
, , , ( , - ??). , VB4/VB5 StrConv(), :

Private Sub Text1_Change()
If Text1.Tag = "" Then
Text1.Tag = Text1.SelStart
Text1.Text = StrConv(Text1.Text, vbProperCase)
Text1.SelStart = Text1.Tag
Text1.Tag = ""
End If
End Sub



31. DOUBLE CLICK

VB4 32, VB5
Level: Intermediate
VB4 Win95 Toolbar, . ButtonClick, double-click, ButtonDoubleClick . , :

Private mbSingleClicked As Boolean
Private mbDoubleClicked As Boolean

In the Toolbars ButtonClick event, add this code:
ButtonClick :

Private Sub Toolbar1_ButtonClick_
(ByVal Button As Button)
Dim t As Single
t = Timer
If mbSingleClicked = True Then
mbDoubleClicked = True
MsgBox "Double Clicked"
Else
mbSingleClicked = True
' , -
Do While Timer - t < 1 And mbSingleClicked = True
DoEvents
Loop
' DoubleClick,
If mbDoubleClicked = True Then
mbSingleClicked = False
mbDoubleClicked = False
Exit Sub
End If
End If
If mbDoubleClicked = False Then
MsgBox "Single Clicked"
End If

'
'If mbDoubleClicked Then
'--------- code
'ElseIf mbSingleClicked Then
'--------- code
'End If

' , SingleClick
If mbDoubleClicked = False Then
mbSingleClicked = False
mbDoubleClicked = False
End If
End Sub



32.

VB3, VB4 16/32, VB5
Level: Intermediate

, :

Function DirUsedBytes(ByVal dirName As _
String) As Long
Dim FileName As String
Dim FileSize As Currency

' \,
If Right$(dirName, 1) <> "\" Then
dirName = dirName & "\"
Endif
FileSize = 0
FileName = Dir$(dirName & "*.*")

Do While FileName <> ""
FileSize = FileSize + _
FileLen(dirName & FileName)
FileName = Dir$
Loop
DirUsedBytes = FileSize

End Function

:

MsgBox DirUsedBytes("C:\Windows")


33.

VB4 32, VB5
Level: Advanced

, , , . , DISKSPACEINFO ("RootPath") :

Dim dsi As DISKSPACEINFO
dsi.RootPath = "C:\"
GetDiskSpace dsi

():

' *** Declaratiosn Section ******
Declare Function GetDiskFreeSpace Lib _
"kernel32" Alias _
"GetDiskFreeSpaceA" _
(ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, _
lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, _
lpTotalNumberOfClusters As Long) _
As Long

Type DISKSPACEINFO
RootPath As String * 3
FreeBytes As Long
TotalBytes As Long
FreePcnt As Single
UsedPcnt As Single
End Type

' ****** ******
Function GetDiskSpace(CurDisk As _
DISKSPACEINFO)
Dim X As Long
Dim SxC As Long, BxS As Long
Dim NOFC As Long, TNOC As Long

X& = GetDiskFreeSpace_
(CurDisk.RootPath, SxC, BxS, _
NOFC, TNOC)
GetDiskSpace = X&

If X& Then
CurDisk.FreeBytes = BxS * _
SxC * NOFC
CurDisk.TotalBytes = BxS * _
SxC * TNOC
CurDisk.FreePcnt = ((CurDisk._
TotalBytes CurDisk._
FreeBytes) / CurDisk._
TotalBytes) * 100
CurDisk.UsedPcnt = _
(CurDisk.FreeBytes / _
CurDisk.TotalBytes) * 100
Else
CurDisk.FreeBytes = 0
CurDisk.TotalBytes = 0
CurDisk.FreePcnt = 0
CurDisk.UsedPcnt = 0
End If
End Function

, - 2, Single.


34. CTRL LIST BOX

VB4 32, VB5
Level: Advanced

MultiSelect listbox 1 - Simple 2 - Extended, Ctrl listbox, ( ) . , Ctrl. .

Declare Function GetKeyboardState Lib _
"user32" (pbKeyState As Byte) _
As Long
Declare Function SetKeyboardState Lib _
"user32" (lppbKeyState As Byte) _
As Long
Public Const VK_CONTROL = &H11
Public KeyState(256) As Byte

MouseDown listbox ( List1), MultiSelect Simple Extended:

' Ctrl
GetKeyboardState KeyState(0)
KeyState(VK_CONTROL) = _
KeyState(VK_CONTROL) Or &H80
SetKeyboardState KeyState(0)

, Ctrl, , List1_LostFocus:

' Ctrl
GetKeyboardState KeyState(0)
KeyState(VK_CONTROL) = _
KeyState(VK_CONTROL) And &H7F
SetKeyboardState KeyState(0)


35.

VB3, VB4 16/32, VB5
Level: Intermediate

API, 16- 32- . DirWalk , :

ReDim sArray(0) As String
Call DirWalk("OLE*.DLL", "C:\", sArray)

* ? , . , ;, , "OLE*.DLL; *.TLB". - , - .
, , sArray . , .
DirWalk, , FileListBox DirListBox, . , : : FileListBox File1, DirListBox Dir1. . , () VB.

Sub DirWalk(ByVal sPattern As String, _
ByVal CurrDir As String, sFound() _
As String)
Dim i As Integer
Dim sCurrPath As String
Dim sFile As String
Dim ii As Integer
Dim iFiles As Integer
Dim iLen As Integer

If Right$(CurrDir, 1) <> "\" Then
Dir1.Path = CurrDir & "\"
Else
Dir1.Path = CurrDir
End If
For i = 0 To Dir1.ListCount
If Dir1.List(i) <> "" Then
DoEvents
Call DirWalk(sPattern, _
Dir1.List(i), sFound())
Else
If Right$(Dir1.Path, 1) = "\" _
Then
sCurrPath = Left(Dir1.Path, _
Len(Dir1.Path) - 1)
Else
sCurrPath = Dir1.Path
End If
File1.Path = sCurrPath
File1.Pattern = sPattern
If File1.ListCount > 0 Then
'
For ii = 0 To File1._
ListCount - 1
ReDim Preserve _
sFound(UBound(sFound) _
+ 1)
sFound(UBound(sFound) - _
1) = sCurrPath & _
"\" & File1.List(ii)
Next ii
End If
iLen = Len(Dir1.Path)
Do While Mid(Dir1.Path, iLen, _
1) <> "\"
iLen = iLen - 1
Loop
Dir1.Path = Mid(Dir1.Path, 1, _
iLen)
End If
Next i
End Sub




36. WINDOWS 95/NT

VB4 32, VB5
Level: Advanced

WINDOWS 95/NT VB . API kernel32.dll:

Private Declare Function GetComputerNameA Lib "kernel32"_
(ByVal lpBuffer As String, nSize _
As Long) As Long

Public Function GetMachineName() As _
String
Dim sBuffer As String * 255
If GetComputerNameA(sBuffer, 255&) _
<> 0 Then
GetMachineName = Left$(sBuffer, _
InStr(sBuffer, vbNullChar) _
- 1)
Else
GetMachineName = "(Not Known)"
End If
End Function


37. ,

VB3, VB4 16/32, VB5
Level: Intermediate
, :

Private Sub Form_Load()
' .
For I = 0 To Screen.FontCount - 1
' .
cboFont.AddItem Screen.Fonts(I)
Next I
End Sub

, , - :

Private Sub cboFont_Click()
' FontName combobox
cboFont.FontName = cboFont.Text
End Sub


38. TREEVIEW


VB4 32, VB5
Level: Intermediate

TreeView Windows 95. , VB , (node) . Treeview_MouseDown NodeClick. , (Key) .

+ Root (R01) ' the letter gives
|--- Child 1 (C01) ' the indication to
|--+ Child 2 (C02) ' the context menu
| |--- Child 2.1 (H01)
| |--- Child 2.2 (H02)

Dim bRightMouseDown as Boolean

Private Sub Form_Load()
bRightMouseDown = False
End Sub

Private Sub treeview1_MouseDown_
(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button And vbRightButton Then
bRightMouseDown = True
Else
bRightMouseDown = False
End If
End Sub

Private Sub treeview1_MouseUp_
(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
bRightMouseDown = False
End Sub

Private Sub treeview1_NodeClick_
(ByVal Node As Node)
Select Case Left(Node.Key, 1)
Case "R"
If Not bRightMouseDown Then
' do the normal node click,
' so you must here the code
' for the node code click
Else
'
treeview1.Nodes(Node.Key).Selected = True
'
PopupMenu mnuContext1
End If

Case "C"
If Not bRightMouseDown Then
' do the normal node click,
' so you must here the code
' for the node code click
Else
'
treeview1.Nodes(Node.Key).Selected = True
'
PopupMenu mnuContext2
End If

'
' ....
End Select
End Sub


39. VB SENDTO

VB3, VB4 16/32, VB5
Level: Intermediate
"Shortcut to VB.exe" "Shortcut to VB32.exe" "Send To" right-click VBP VB4 16/32 VB5 - .
VB , right-click VB32.exe, "Create shortcut.". , C:\Windows\Sendto. right-click , . WordPad, Word, Excel , .


40. Ȕ VB

VB4 16/32, VB5
Level: Intermediate

1) VB5, Ctrl-F3 - . , . , .

2) VB4/5 Ctrl-Tab IDE, , Window.



41. USERID WINDOWS 95/NT

VB4 32, VB5
Level: Intermediate

userID , . API:

Option Explicit

Private Declare Function WNetGetUserA _
Lib "mpr" (ByVal lpName As String, _
ByVal lpUserName As String, _
lpnLength As Long) As Long

Function GetUser() As String
Dim sUserNameBuff As String * 255
sUserNameBuff = Space(255)
Call WNetGetUserA(vbNullString, _
sUserNameBuff, 255&)
GetUser = Left$(sUserNameBuff, _
InStr(sUserNameBuff, _
vbNullChar) - 1)
End Function



42

VB4 32, VB5
Level: Advanced

MousePointer, . /. - , Initialize. . , , - . , , Terminate.

Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

' , CHourGlass
Private Sub ProcessData()
Dim MyHourGlass As CHourGlass
Set MyHourGlass = New CHourGlass
'
Sleep 5000 '
'
End Sub

' CHourGlass:
Private Sub Class_Initialize()
' HourGlass
Screen.MousePointer = vbHourglass
End Sub

Private Sub Class_Terminate()
' MousePointer
Screen.MousePointer = vbDefault
End Sub


43. ( )

VB4 16/32, VB5
Level: Beginning
. :

lTotalMinutes = Minutes(Now) - _
Minutes(datStartTime)

01/01/1900:

Public Function Minutes(d As Date) _
As Long
' , 1900
Dim lPreviousDays As Long
Dim lTotalMinutes As Long

lPreviousDays = d - #1/1/1900#
lTotalMinutes = _
(lPreviousDays * 24) * 60
lTotalMinutes = lTotalMinutes + _
Hour(d) * 60
lTotalMinutes = lTotalMinutes + _
Minute(d)

Minutes = lTotalMinutes
End Function


44. !

VB3, VB4 16/32, VB5
Level: Beginning

recordset, . , recordset . Cancel, . , , , Cancel. Cancel True, Esc. :

Dim CancelNow As Integer

Put this code in the Click event of the Cancel button:
Click Cancel:

Sub cCancel_Click ()
CancelNow = -1
DoEvents
End Sub

Escape. , KeyPreview True :

Sub Form_KeyPress (KeyAscii As Integer)
' ESC
If KeyAscii = (27) Then
CancelNow = -1
DoEvents
End If
End sub

, :

'... - ...
' recordset database
Do While Not MyRecordSet.EOF
Printer.Print MyRecordSet!SomeRecord
MyRecordSet.MoveNext
DoEvents
' , Cancel
If CancelNow then Exit Do
Loop
Printer.EndDoc
'... ...


45.

VB3, VB4 16/32, VB5
Level: Intermediate

Use this algorithm to swap two integer variables:
, :

a = a Xor b
b = a Xor b
a = a Xor b





46.

VB3, VB4 16/32, VB5
Level: Intermediate

. ,
A*x^N + B*x^(N-1) + + Y*x + Z ( ^ ), :
(((A*x + B)*x + C)*x + +Y)*x + Z.


47. API

VB4 32, VB5
Level: Advanced

Win32 API , :

Private Declare Function SHFormatDrive _
Lib "shell32" (ByVal hwnd As Long, _
ByVal Drive As Long, _
ByVal fmtID As Long, _
ByVal options As Long) As Long
Private Declare Function GetDriveType _
Lib "kernel32" _
Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long

command buttons , cmdDiskCopy cmdFormatDrive, Click :

Private Sub cmdDiskCopy_Click()
' DiskCopyRunDll - From To
Dim DriveLetter$, DriveNumber&, _
DriveType&
Dim RetVal&, RetFromMsg&
DriveLetter = UCase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - _
65)
DriveType = GetDriveType_
(DriveLetter)
If DriveType = 2 Then 'Floppies, _
etc
RetVal = Shell_
("rundll32.exe " & _
"diskcopy.dll," _
& "DiskCopyRunDll " & _
DriveNumber & "," & _
DriveNumber, 1)
Else ' Just in case
RetFromMsg = MsgBox_
("Only floppies can be " & _
"copied", 64, _
"DiskCopy Example")
End If
End Sub

Private Sub cmdFormatDrive_Click()
Dim DriveLetter$, DriveNumber&, _
DriveType&
Dim RetVal&, RetFromMsg%
DriveLetter = UCase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - _
65)
' : A=0
DriveType = GetDriveType_
(DriveLetter)
If DriveType = 2 Then _
' ..
RetVal = SHFormatDrive(Me.hwnd, _
DriveNumber, 0&, 0&)
Else
RetFromMsg = MsgBox_
("This drive is NOT a " & _
"removeable drive! " & _
"Format this drive?", _
276, "SHFormatDrive Example")
If RetFromMsg = 6 Then
' ...
'RetVal = SHFormatDrive_
(Me.hwnd, _
' DriveNumber, 0&, 0&)
End If
End If
End Sub

DriveListBox Drive1:

Private Sub Drive1_Change()
Dim DriveLetter$, DriveNumber&, _
DriveType&
DriveLetter = UCase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - _
65)
DriveType = GetDriveType_
(DriveLetter)
If DriveType <> 2 Then _
'Floppies, etc
cmdDiskCopy.Enabled = False
Else
cmdDiskCopy.Enabled = True
End If
End Sub

: .


48.

VB4 16/32, VB5
Level: Intermediate

, , :

Public Function GetMyVersion() As String
' "1.02.0001"
Static strMyVer As String
If strMyVer = "" Then
strMyVer = Trim$(Str$(App.Major)) & "." & _
Format$(App.Minor, "##00") _
& "." Format$(App.Revision, "000")
End If
GetMyVersion = strMyVer
End Function


49.

VB3, VB4 16/32, VB5
Level: Beginning

, . , , , Add New Record, Delete Record, Find Record. print preview . general declarations . Offset , .

Sub ButtonRight(X As Control, _
Frm As Form, Offset as Integer)
X.Left = Frm.ScaleWidth - _
X.Width - Offset
End Sub

command button . Form_Resize, :

Private Sub Form_Resize()
ButtonRight Command1, Me, 0
ButtonRight Command2, Me, _
Command1.Width
End Sub


50. VAL( )

VB3, VB4 16/32, VB5
Level: Intermediate

Val(). . CInt(), CDbl().

FormattedString = Format(1250, _
"General")
' = "1,250.00"
Debug.Print Val(FormattedString)
' 1 !
Debug.Print cDbl(FormattedString)
' 1250



51. C ID

VB3, VB4 16/32, VB5
Level: Intermediate

, , ID . CheckForValid, CheckForValid True "203931." False "209331."

Function CheckForValid(Num As Long) _
As Boolean
' Check for valid number
Result = Num Mod 13
If Result <> 0 Then
CheckForValid = False
' if false then the number is wrong
Else
CheckForValid = True
'if true the number is OK
End If
End Function

Function Generate(Num As Long) As Long
'Generates the successor of a valid
'number
If CheckForValid(Num) Then
Generate = Num + 13
'if valid Generate
Else
Generate = -1
' Otherwise return -1
End If
End Function



52. COMBOBOXE

VB4 32, VB5
Level: Advanced
VB ListRows, .. 8 combobox, combobox:

Option Explicit

Type POINTAPI
x As Long
y As Long
End Type

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Declare Function MoveWindow Lib _
"user32" (ByVal hwnd As Long, _
ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Declare Function GetWindowRect Lib _
"user32" (ByVal hwnd As Long, _
lpRect As RECT) As Long
Declare Function ScreenToClient Lib _
"user32" (ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long

Public Sub Size_Combo(rForm As Form, _
rCbo As ComboBox)
Dim pt As POINTAPI
Dim rec As RECT
Dim iItemWidth As Integer
Dim iItemHeight As Integer
Dim iOldScaleMode As Integer

' Scale Mode Pixels
iOldScaleMode = rForm.ScaleMode
rForm.ScaleMode = 3
iItemWidth = rCbo.Width

' combobox
iItemHeight = rForm.ScaleHeight - rCbo.Top - 5
rForm.ScaleMode = iOldScaleMode

'
Call GetWindowRect(rCbo.hwnd, rec)
pt.x = rec.Left
pt.y = rec.Top

'
Call ScreenToClient(rForm.hwnd, pt)

' combobox
Call MoveWindow(rCbo.hwnd, pt.x, _
pt.y, iItemWidth, iItemHeight, 1)
End Sub


53. WIN32

VB4 32, VB5
Level: Advanced

, , 16 32 , , API GetFreeSystemResources . . API :

Declare Sub GlobalMemoryStatus Lib _
"kernel32" (lpBuffer As _
MEMORYSTATUS)

Type MEMORYSTATUS
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

dwlength MEMORYSTATUS. Long 4 , 4*8=32 :

Dim ms As MEMORYSTATUS

ms.dwLength = Len(ms)
GlobalMemoryStatus ms
MsgBox "Total physical memory:" & _
ms.dwTotalPhys & vbCr _
& "Available physical memory:" & _
ms.dwAvailPhys & vbCr & _
"Memory load:" & ms.dwMemoryLoad

, .


54. ?

VB5
Level: Intermediate

, :

Function GetAge(dtDOB As Date, _
Optional dtDateTo As Date = 0) _
As String
' dtDateto ?
If dtDateTo = 0 Then
dtDateTo = Date
End If
GetAge = Format$(dtDateTo - _
dtDOB, "yy - mm - dd")
End Function


55. ,

VB3, VB4 16/32, VB5
Level: Intermediate

. , , . , - .
, , "Start With Full Compile". , .




56. ARRAY

VB4 16/32, VB5
Level: Intermediate

GetRows Recordset (JET) rdoResultset (RDO) . OLE Server . Variant . ( VB)

Dim A As Variant
A = Array(10,2)



57. OPTION BUTTONS

VB4 16/32, VB5
Level: Intermediate
option buttons

Function WhichOption(Options As _
Object) As Integer

' Option Button, true.

Dim i
' Options - ,
On Error GoTo WhichOptErr
' Default to failed
WhichOption = -1
' OptionButton . ,
' ,
For i = Options.lbound To _
Options.ubound
If Options(i) Then
'
WhichOption = i
'
Exit For
End If
Next
WhichOptErr:

End Function

, iCurOptIndex integer, Option1 OptionButton.

iCurOptIndex = WhichOption(Option1)

: - . - variant.


58. CHECK-BOX INTEGER

VB4 16/32, VB5
Level: Intermediate

, check box:

Function WhichCheck(ctrl As Object) As _
Integer
' ,
'
' , . 0 : 2 ^ 0 = 1,
' 0 2 : 2^0 + 2^2 = 5

Dim i
Dim iHolder
'
' 0
On Error GoTo WhichCheckErr

'
'
For i = ctrl.LBound To ctrl.UBound
If ctrl(i) = 1 Then
' ,
iHolder = iHolder Or 2 ^ i
End If
Next
WhichCheckErr:
WhichCheck = iHolder

End Function

:

iCurChecked = WhichCheck(Check1)

Check1 - , iCurChecked - integer. , , .

Sub SetChecked(ctrl As Object, _
iCurCheck%)
' This sub sets the binary value of an
' array of controls where iCurChecked is
' 2 raised to the index of each checked
' control
Dim i
' in case ctrl is not a valid object
On Error GoTo SetCheckErr
' use the binary representation to
' set individual check box controls
For i = ctrl.LBound To ctrl.UBound
If iCurCheck And (2 ^ i) Then
' if it is checked add in its
' binary value
ctrl(i).Value = 1
Else
ctrl(i).Value = 0
End If
Next
SetCheckErr:

End Sub

:

Call SetChecked(Check1, iDesired)

Check1 - , iDesired- , .


59.

VB4 16/32, VB5
Level: Intermediate

Conditional Compilation VB4, Windows API 16- 32- :

#If Win#32 then
' 32-
Declare SomeApi....
#Else
' 16-
Declare SomeApi
#End IF
Windows API, :

#If Win32 Then
Dim lRc&
lRc& = ReturnSomeNumber(35000)
#Else
Dim lRc%
lRc% = ReturnSomeNumber(30000)
#End If

#If Win32 Then
Private Function ReturnSomeNumber_
(lVar&) As Long
ReturnSomeNumber = 399999
#Else
Private Function ReturnSomeNumber_
(lVar%) As Integer
ReturnSomeNumber = 30000
#End If

End Function


60.

VB4, VB5
Level: Intermediate

, GUI API:

'Declarations Section
#If Win32 Then
Declare Function LockWindowUpdate _
Lib "user32" _
(ByVal hwndLock As Long) As Long
#Else
Declare Function LockWindowUpdate _
Lib "User" _
(ByVal hwndLock As Integer) _
As Integer
#End If

Public Sub LoadSomeForm()

'
' .
' GUI
LockWindowUpdate frmTest.hWnd
'
frmTest.Show
' , ..

'
LockWindowUpdate 0
End Sub



61. DBGride


VB4 16/32, VB5
Level: Advanced

, DBGride ( grida), API LockWindowUpdate(gridname.hwnd) grid, LockWindowUpdate(0) :

'Declarations Section
#If Win32 Then
Declare Function LockWindowUpdate _
Lib "user32" _
(ByVal hwndLock As Long) As Long
#Else
Declare Function LockWindowUpdate _
Lib "User" _
(ByVal hwndLock As Integer) _
As Integer
#End If

Private Sub cmdHideSelector_Click()
LockWindowUpdate DBGrid1.hWnd
End Sub

Private Sub cmdShowSelector_Click()
LockWindowUpdate 0
End Sub



62. USE POPUP MENUS IN WINDOWS WITHOUT TITLE BAR

VB4 16/32
Level: Intermediate

ControlBox False BorderStyle fixed window, () titlebar ( ). - - . .

Private Sub Command1_Click()
Dim frm As New frmMenu
Load frm
frm.PopupMenu frm.mnutest
'select specific code
Unload frm
End Sub

VB5



63. API

VB3, VB4 16/32, VB5
Level: Intermediate

, Windows, Locale Settings API.

DateDelimiter = Mid$(Format(Date, _
"General Date"), 3, 1)
TimeDelimiter = Mid$(Format(0.5, _
"Long Time"), 3, 1)
DecimalDelimiter = Mid$(Format(1.1, _
"General Number"), 2, 1)


64. GETSETTING

VB4 16/32, VB5
Level: Intermediate

GetSetting , 16- INI . INI , "Invalid procedure call.". , :

Public Function GetRegSetting(AppName _
As Variant, Section As Variant, _
Key As Variant, Optional Default _
As Variant) As Variant

' - ,
' Set
Dim tmpValue As Variant

'
' ,
' Variant
If Not IsMissing(Default) Then _
tmpValue = Default

'
On Error Resume Next

' VB
tmpValue = GetSetting(AppName, _
Section, Key, tmpValue)

'
' tmpValue
GetRegSetting = tmpValue

End Function


65.

VB3, VB4 16/32, VB5
Level: Beginning
; , , , . VB . , . , . VB5, Block Uncomment. .

While Not mRS.EOF
oObject.FName = mRS!FName
oObject.LName = mRS!LName
oObject.Phone = mRS!Phone
.
.
cCollection.Add oObject, oObject.FName
Wend

20 30 , :

' oObject. = mRS!

, 20 30 , , . , .




66. VB

VB4 32
Level: Intermediate
VB , desktop . , desktop. , INI .

Option Explicit

Declare Function GetPrivateProfile_
String 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

Public Sub Main()
Dim temp As String, rVal$, tmp _
As Long
rVal$ = String$(256, 0)
tmp = GetPrivateProfileString_
("Visual Basic", _
"vb32location", "", rVal$, _
ByVal Len(rVal$) - 1, _
"c:\windows\vb.ini")
temp = Left$(rVal$, tmp)
rVal$ = String$(256, 0)
tmp = GetPrivateProfileString_
("Visual Basic", "RecentFile1", _
"", rVal$, ByVal Len(rVal$) _
- 1, "c:\windows\vb.ini")
temp = temp & " """ & Left$(rVal$, _
tmp) & """"
Shell temp, 1
End
End Sub


67. "&" LABEL

VB4 16/32, VB5
Level: Beginning

& , "UseMnemonic" False. , , , Label . "&" Caption, &&.


68.


VB3, VB4 16/32, VB5
Level: Beginning

, . , , SQL , . FileAux, . , :

Function FileAux(Ext As String) _
As String
Dim i As Long, X As String
If InStr(Ext, ".") = 0 Then
Ext = "." + Ext
End If

'
i = 0
Do
X = "Aux" + Format$(i, "0000") _
+ Ext
If FileExists(X) Then
i = i + 1
Else
Exit Do
End If
Loop
FileAux = X
End Function

FileExists:

Function FileExist(filename As String) _
As Boolean
FileExist = Dir$(filename) <> ""
End Function

:

Sub Test()
Dim File1 As String, File2 As _
String, File3 As String
Dim DB1 As database, DB2 As DataBase
Dim FileNum As Integer
File1 = FileAux("MDB")
Set DB1 = CreateDataBase(File1)
File2 = FileAux("MDB")
Set DB2 = CreateDataBase(File2)
File3 = FileAux("TXT")
FileNum = FreeFile
Open File3 For OutPut As FileNum
'
' ...
Close FileNum
End Sub

File1, File2, File3 "Aux0001.MDB," "Aux0002.MDB,"
"Aux0001.TXT," .


69. ENABLE FALSE

VB3, VB4 16/32, VB5
Level: Beginning
MouseMove , Enabled False. , Tooltips Notes , , enabled disabled.
Enabled False, , , . Command1_MoseMove Label1_MouseMove. Command1 .

Command1(0), Command1(1)-Command1 - .
Label1(0), Label1(1)- .
SSPanel1- .

Private Sub Form_Load()
Dim i As Integer
For i = 0 To 1
Label1(i).Left = Command1(i).Left
Label1(i).Top = Command1(i).Top
Label1(i).Width = Command1(i).Width
Label1(i).Height = _
Command1(i).Height
Next i
Command1(0).enabled = false
Command1(0).Tag = "Button to Add"
Command1(1).Tag = "Button to Modify"
Command1(0).Caption = "&Add"
Command1(1).Caption = "&Modify"

End Sub

Private Sub Label1_MouseMove(Index As _
Integer, Button As Integer, Shift _
As Integer, X As Single, Y As _
Single)
SSPanel1.Caption = Command1(Index).Tag
End Sub

Private Sub Command1_MouseMove(Index _
As Integer, Button As Integer, _
Shift As Integer, X As Single, Y _
As Single)
SSPanel1.Caption = Command!(Index).tag
End Sub


70. POPUP MENU TEXT BOXES

VB4 16/32, VB5
Level: Intermediate

VB4 VB5 , , TextBox , . , , . Mouse_Down, . , . PopContextMenu

Sub PopContextMenu(argoControl As _
Control, argoMenu As Control)
argoControl.Enabled = False
PopupMenu argoMenu
argoControl.Enabled = True
End Sub

MouseDown Text1 MyMenu:

Private Sub Text1_MouseDown(Button As _
Integer, Shift As Integer, X As _
Single, Y As Single)
If Button = vbRightButton Then
PopContextMenu Text1, MyMenu
End If
End Sub



71.

VB3, VB4 16/32, VB5
Level: Intermediate
API , . , GetSystemMetrics , Microsoft Office shortcut bar:

Public Const SM_CXFULLSCREEN = 16
Public Const SM_CYFULLSCREEN = 17

#If Win32 then
Declare Function GetSystemMetrics _
Lib "user32" _
(ByVal nIndex As Long) As Long
#Else
Declare Function GetSystemMetrics _
Lib "User" _
(ByVal nIndex As Integer) _
As Integer
#End If

Public Sub CenterForm(frm As Form)
frm.Left = Screen.TwipsPerPixelX * _
GetSystemMetrics_
(SM_CXFULLSCREEN) / 2 _
- frm.Width / 2
frm.Top = Screen.TwipsPerPixelY * _
GetSystemMetrics_
(SM_CYFULLSCREEN) / 2 _
- frm.Height / 2
End Sub



72.

VB3, VB4 16/32, VB5
Level: Beginning
, . , :

Function StringCleaner(s As String, _
Search As String) As String
Dim i As Integer, res As String
res = s
Do While InStr(res, Search)
i = InStr(res, Search)
res = Left(res, i - 1) & _
Mid(res, i + 1)
Loop
StringCleaner = res
End Function





73. TYPENAME

VB4 16/32, VB5
Level: Beginning

, , TypeName If TypeOf. TypeOf :

If TypeOf myObject is myType then
... -
End If

:

if TypeName(myObject) = "myType" Then
.... -....
End If

, ( OCXs), . (, ) , , TypeName Select Case.


74. TEXT BOX

VB4 16/32, VB5
Level: Intermediate

, TextBox , :

'
MyTextBox.SelStart = Len(MyTextBox.Text)
'
MyTextBox.SelText = NewText$


75. VAL

VB3, VB4 16/32, VB5
Level: Beginning

Val, VB , . , Val("25%") 25, Val("2.5%") . , "%" "&". , Val.


76. INTERNET

VB4 32, VB5
Level: Advanced

VB5 App Wizard Web Browser-, Microsoft Internet Explorer SHDOCVW.DLL . ShellExecute Internet Shortcut, Windows URL. Microsoft Netscape , , DLL .

Private 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
Private Const SW_SHOWNORMAL = 1

' frm : ShellExecute .
'
' sUrl : .url ( Internet shortcut)
' , .
' c:\MyWebPage.url Internet Explorer
'

Public Sub GoToMyWebPage(frm as Form, _
sUrl as string)
Dim lRet as Long
lRet = ShellExecute(frm.hwnd, _
"open", sUrl, vbNull, _
vbNullString, SW_SHOWNORMAL)
If lRet <= 32 Then
' . ,
' ShellExecute:
' ERROR_FILE_NOT_FOUND = 2&
' ERROR_PATH_NOT_FOUND = 3&
' ERROR_BAD_FORMAT = 11&
' SE_ERR_NOASSOC = 31
' SE_ERR_OOM = 8
Else
' !
End If
End Sub



77. HELP-


VB4 32, VB5
Level: Intermediate

-. - Windows ? Win32 API .

' ----
Const HELP_CONTENTS = &H3&
'
Declare Function WinHelp Lib "user32" _
Alias "WinHelpA" _
(ByVal hwnd As Long, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Long) As Long

' ---
Sub OpenHelpFile(HelpFileName As String)
' HelpFileName - -.
WinHelp hwnd, HelpFileName, _
HELP_CONTENTS, 0
End Sub


78. MDI DESIGN-TIME

VB3, VB4 16/32, VB5
Level: Beginning

MDI- border, MDI-. , ( ), MDIForm_Resize() ( - ):

Private Sub MDIForm_Resize()
' resizing MDI- ( ).
MDI , Normal Window
If WindowState = 0 Then
' MDI
Me.Height = 6900
' MDI
Me.Width = 10128
' MDI
Me.Left = 1020
' MDI
Me.Top = 1176
' Move,

End If
End Sub


79.

VB3, VB4 16/32, VB5
Level: Beginning
VB DLookUp . Name ID:

Public Function MyDLookUp(Column As _
String, TableName As String, _
Condition As String) As Variant
Dim Rec As Recordset
On Error GoTo MyDlookUp_Err

' gCurBase - ,
Set Rec = gCurBase.OpenRecordset_
("Select * From " & TableName)
Rec.FindFirst Condition
If Not Rec.NoMatch Then
' ,
MyDLookUp = Rec(Column)
Exit Function
End If

' , ,
MyDlookUp_Err:
MyDLookUp = -1
End Function


80.

VB3, VB4 16/32, VB5
Level: Intermediate

Lost_Focus and Got_Focus events . .
timer control , Interval property = 100 Enabled = True. Name the control tmrFocusTracking.
Timer event :

Private Sub tmrFocusTracking_Timer()
Dim strControlName As String
Dim strActive As String
strControlName = _
Me.ActiveControl.Name

Do
strActive = Me.ActiveControl.Name
If strControlName <> strActive _
Then
Print strControlName & _
" - Lost Focus", _
strActive & " - Got Focus"
strControlName = strActive
End If
DoEvents
Loop
End Sub

To implement universal highlighting, replace the Print statement with this code:

Me.Controls(strActive).SelStart = 0
Me.Controls(strActive).SelLength = _
Len(Me.Controls(strActive))

(validation) Print statement .
strActive in a Select Case structure
, Print , strActive , , strControlName , .
- .


81.

VB3, VB4 16/32, VB5
Level: Beginning

ControlBox False, Minimize Maximize . , Minimize Maximize, . Query_Unload:

' VB3,
' Const vbFormControlMenu = 0
Private Sub Form_QueryUnload(Cancel As _
Integer, UnloadMode As Integer)
If UnloadMode = vbFormControl_
Menu Then
Cancel = True
End If
End Sub


82.

VB3, VB4 16/32, VB5
Level: Beginning

/ . , , . F4, Tag , Group1. :

For ind = 0 To Formname.Controls.Count _
- 1
If Formname.Controls(ind).Tag = _
"Group1" Then
Formname.Controls(ind).Visible _
= True
End If
Next


83.

VB3, VB4 16/32, VB5
Level: Intermediate

.

n = 12.345
Format(n, "0.00\0")
' "12.350"
Format(n, "0.\0\0")
' "12.00"
Format(0.55, "#.0\0") ' ".60"


84. , !

VB3, VB4 16/32, VB5
Level: Intermediate

VB , , VB. :

Dim x As Integer
Dim y As Integer
Dim z As Integer

x = 10
y = 20
z = 0

' max
if (z = max(x, y)) > 0 then
Msgbox CStr(z)
Else
Msgbox "How Come?"
End if

, 20, ? , VB z RHS (right-hand side)- , , . .


8.5 BACKQUOTES

VB3, VB4 16/32, VB5
Level: Intermediate
Transact-SQL . , , , SQL Server . , KeyPress (ASCII(145)):

Private Sub Text1_Keypress_
(KeyAscii as Integer)
If KeyAscii = 39 Then
KeyAscii = 145
End If
End Sub

SQL Server.




86.

VB4 16/32, VB5
Level: Intermediate

VB 300 . , VB , . On. setup/upgrade ( UNC- (\\_\_) ), INI- , . , Form_Load:

Open IniFile$ For Input As #1
Line Input #1, sUpgradeVersion$
Close #1

If sUpgradeVersion > (Format(App.Major, "00") & "." & _
Format(App.Minor, "00") & "." & _
Format(App.Revision, "0000")) Then
'
End
End If

INI- , , .exe, , . , , .



87. , WINDOWS 95

VB3, VB4 16/32, VB5
Level: Intermediate

declaration section :

Public Sub Win95Shrivel(xForm As Form)
'
xForm.WindowState = 1
End Sub

Unload

Private Sub Form_Unload(Cancel As _
Integer)
Win95Shrivel Me
End Sub

unloade , . Windows 3.1x .



..........................................................................................................................

[ ] [ ] [ ] [ ] [ ] [ ] [ ]
..........................................................................................................................

Visaul Progs
Visual Basic
 '   Visaul Progs' >>> - , !!! >>>
-------->

>>>
-------->


  YandeG Rambler's Top100
:

...:::Design by Mystf0rse 2005-2010 year:::...