CodeItBetter Programming Another VB Programming Blog

How to Load any image in Picture box control

Posted on August 27, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'Controls - How to Load any image in Picture box control

'Using the LoadPicture function

Picture1.Picture = LoadPicture("c:\windows\setup.bmp")
 
'Clear the current image using either one of the following statements:

' These are equivalent.
Picture1.Picture = LoadPicture("")
Set Picture1.Picture = Nothing
 
'LoadPicture function has been extended in Visual Basic 6 to support icon files
'containing multiple icons. The new syntax is the following:
'
'LoadPicture(filename, [size], [colordepth], [x], [y])
'
'where values in square brackets are optional.
'
'To copy an image from one PictureBox control to another by assigning the target
'Control 's Picture property:

Picture2.Picture = Picture1.Picture
Filed under: Controls No Comments

How to generate random numbers, with the info

Posted on August 26, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'Coding Basics - How to generate random numbers, with the info
'1) How many values - txtValue
'2) What the max is - txtMax
'3) What the min is - txtMin
'4) If they want duplicate random numbers, or not
'        - OptionBoxes
'        - Option1 = Double
'        - Option2 = No Double

Option Explicit
 
Dim HowMany As Integer
Dim RndNum As Integer
Dim Answer As String
Dim I As Integer
Dim Search As Integer
 
Private Sub cmdGenerate_Click()
    On Error GoTo Problem
    Randomize
    ReDim Ans(TxtValue)
    If Option1.Value = True And TxtMax - TxtMin < TxtValue Then
        MsgBox "It is impossible to generate that amount of random numbers without doubles."
        Exit Sub
    End If
    Answer = ""
    For HowMany = 1 To TxtValue
5       RndNum = Int(Rnd * TxtMax) + TxtMin
        If RndNum > TxtMax Then GoTo 5
        If Option2.Value = True Then
            Ans(HowMany) = RndNum
        Else
            For Search = 1 To HowMany
                If RndNum = Ans(Search) Then GoTo 5
            Next Search
            Ans(HowMany) = RndNum
        End If
    Next HowMany
    For I = 1 To TxtValue
        Answer = Answer & Ans(I)
        If I <> TxtValue Then Answer = Answer & ", "
    Next I
    MsgBox Answer
    Exit Sub
 
Problem:
    MsgBox Err.Description
End Sub
Filed under: Coding Basics No Comments

How to move a form without a title bar

Posted on August 26, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
'Forms - How to move a form without a title bar
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
 
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
 
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Place this code in the MouseDown event of the form.
    ReleaseCapture
    SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
Filed under: Forms No Comments

How to determine if a number is even or odd (True for Odd; False for Even) (in three ways)

Posted on August 25, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'Math - How to determine if a number is even or odd (True for Odd; False for Even) (in three ways)
'Method 1:

Public Function IsEven(ByVal I As Long) As Boolean
   IsEven = Not -(i And 1)
End Function
 
'Method 2:

Public Function IsOdd(ByVal I As Long) As Boolean
   IsOdd = -(i And 1)
End Function
 
'Method 3:

Public Function IsOdd(ByVal lngNumber As Long) As Boolean
    IsOdd = (lngNumber Mod 2) <> 0
End Function
Filed under: Math No Comments

How to Erase an Array — removes all of its elements

Posted on August 25, 2011
1
2
'Arrays, Collections, Lists - How to Erase an Array -- removes all of its elements
Erase MyArray()