vb.gif (17510 bytes)

 

Home      About      Products      Links      VBasic      WinNT      Flight Sim       Other GD Sites



These codes are all made by me and with a help of two people who has added a little input with two codes...If using these codes please give me a little credit if you want. My email address is [email protected] and my handle is GD. Thanks GD

 

 


This is very important in API
&=Long
%=Integer
$=String ex:(Hello!)

Open a text files to add stuff

Open "c:\Test\GD.txt" For Random As #1
Print #1, "GD196's Page is real cool!"
Close #1
End If

How to make a label count up

You will need:
One label and a command button
In the command button under click put:
Label1.caption=VAL (label1.caption)+1

How to count the number of entries in a ListBox

You will need:
One ListBox, One command button and one label
In the Command_Click put:
label1.Caption = Trim(Str(List1.ListCount))

How to make a Form Roll Up and Down
Requirments:
One Timer, One Form
In the Form_Load Put:
Timer1.Interval=100
In the Timer Put:
Form1.Height=VAL(Form1.Height)+100
If Form1.Height > 5000 then
Timer1.Enabled=0
End if

How to make a form in the background show an Image everywhere you click

Requirements:
Label1,Label2
Form1
Under the Mouse_Move Event Put:
Dim currentx, Currenty
CurrentX = X
CurrentY = Y
Label1.caption = Current X
Label2.Caption = Current X
Under Form1_Click Put:
Image1.Move label1,Label2

To shutdown th computer in Windows 95

Declaration:
Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1
Code:
ExitWindowsEx EWX_SHUTDOWN, 0&

To make a program detect first time run

Summary:
This is very use full for making a welcome screen but only for the first time in your program this is how you use it:
Code:
If LEN(Dir(App.Path + "\" + "first.txt") = 0 Then
Msgbox "This is the first time your running this program"
Open (App.Path + "\" + "first.txt") For Append as #1
Print #1, "Hey!"
Close #1
Else
Open (App.Path + "\" + "first.txt") For Append as #1
Print #1, "Hey!"
Close #1
End If

To Make a Listbox not put two strings in  twice

Summary:  This can be very useful when your making something that the listbox has to register like: Lets say I am going to add GD to the listbox it will add but the second time it will not or it will and you can make a msgbox appear or something like that:
Constant:
Public Const LB_FINDSTRINGEXACT = &H1A2
Code:
entry& = SendMessageByString(List1.hwnd, LB_FINDSTRINGEXACT, -1, text1.text)
If entry& <> -1 Then
Msgbox "You cannot add your name twice",0,"Error"
Exit Sub
Else
List1.AddItem text1.text
Requirments:
1 Listbox
1 Textbox

To Find the Windows Directory

Put a simple code like this:

A$ = String$ (255,1)

B = GetWindowsDirectory (A$,255)

Msgbox A$

Declaration:

Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long


Hexidecimals

0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15
Remember to always Put &H infront of the HeX Value Like: &H14 that is E.

Take Off Text From The Left Of A Word

A = Text1.Text

B = Left$ (A,2)

Msgbox B

Summary:  What this does is it extract two words from the left of a word You can Switch Left$ with Right$ or Mid$


How to make a Program end after 4 tries

Requirements:

Put this code under the load section of a FORM

retvalue = GetSetting("A", "0", "Runcount")

GD$ = Val(retvalue) + 1

SaveSetting "A", "0", "RunCount", GD$

If GD$ > 3 Then

MsgBox "HeY!!!, Well it's time for you to register this program for now BYE!!!"

Unload me

End If


Counting the Amount of times a program is runned

num = GetSetting("Test", 0, "Run")

num = Val(num) + 1

SaveSetting "Test", 0, "Run", num

Msgbox num


Getting a Window Caption

Code:

GDs$ = String$ (200,150)

AOL% =  FindWindow ("AOL FRAME25", VBNULLSTRING)

blabla = GetWindowText(AOL%, GDs$, 100)

Msgbox GDs%


Using LB_SETCURSEL

Summary:

LB_SETCURSEL is used to move from one list index to another it's very easy to use

Code:

Set = SendMessageByNum(HWND%, LB_SETCURSEL, 1, 0)

'This will set the selection on the SECOND index in the listbox in Windows 95 the 0 is the first and 1 is the second

HWND% is the listbox handle


Gaming Movements

This does a special function when something is pressed add it to the KEYDOWN Proc in a form or anything you want:

If keycode = 39 Then

Msgbox "You  pressed the right key"

End If

If keycode = 37 Then

Msgbox "You  pressed the left key"

End If

If keycode = 38 Then

Msgbox "You  pressed the Up arrow key"

End If

If keycode = 40 Then

Msgbox "You  pressed the down arrow key"

Picture1.Move Picture1.Top - 100

End If

End Sub


Loading Lists in VB

Dim a As Variant

Dim b As Variant

CMDialog1.DialogTitle = "Load List File" ' set title

CMDialog1.Filter = "Tee (*.txt)|*.txt|All Files (*.*)|*.*|"

CMDialog1.FileName = "*.txt"

CMDialog1.FLAGS = &H1000&

CMDialog1.Action = 1

a = 1

If (CMDialog1.FileTitle <> "") Then

List1.Clear ' clear the list

Open CMDialog1.FileTitle For Input As a

While (EOF(a) = False)

Line Input #a, b

List1.AddItem b

Wend

Close a

End If


Saving a List in VB

Dim b As Variant

CMDialog1.DialogTitle = "Save List File" ' set CMDialog's title bar

CMDialog1.Filter = "Tee (*.txt)|*.txt|All Files (*.*)|*.*|"

CMDialog1.FLAGS = &H1000&

CMDialog1.FileName = "*.txt"

CMDialog1.Action = 2

If (CMDialog1.FileTitle <> "") Then

a = 2

Open CMDialog1.FileName For Output As a

b = 0

Do While b < List1.ListCount

Print #a, List1.List(b)

b = b + 1

Loop

Close a

End If


Moving a form with a titlebar

Summary: What this does is move a form with really a piece of atr or a label and without the original  WINDOWS titlebar.

Steps:

1. Make sure the form Border under properties is set to NONE

2. Stick in a piece of art for the titlebar and in the MOUSE_DOWN event of that image put in this simple code:

DoEvents

ReleaseCapture

Returnl% = SendMessage(Form1.hwnd, &HA1, 2, 0)

Declarations:

In a bas file under General_Declarations put this:

Declare Sub ReleaseCapture Lib "User32" ()

Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long


Painting Desktop Image

Source:

a = Form1.hwnd ' Gets the Handle of the form

b = GetDC(a) ' Get's the Device Context of that window

c = PaintDesktop(b) ' Paint the desktop image without the physical icons and images which you added

Declaration:

Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Boolean


Playing an MIDI File in VB

Form1.MMControl1.Command = "CLOSE"

Form1.MMControl1.Notify = True

Form1.MMControl1.DeviceType = "Sequencer"

Form1.MMControl1.filename = App.Path + "\" + "mk.mid"

Form1.MMControl1.Command = "Open"

Form1.MMControl1.Command = "PLAY"

Summary: This will play a MID file which you have in the same directory as the project

Note:  Please note that you need the MCI Control added in the project for this to work


Getting the linecount from a textbox
a = SendMessageByString(Text1.hwnd, EM_GETLINECOUNT, 0, 0&)
Msgbox a
Summary:
Text1.hwnd = The handle it's going to get the linecount from

Setting up the double click  time
a = SetDoubleClickTime(60)
Declaration:
Declare Function SetDoubleClickTime Lib "user32" Alias "SetDoubleClickTime" (ByVal wCount As Long) As Long
Summary:
Sets the time in milliseconds between which the mouse is clicked MOUSE_DOWN, MOUSE_UP

Finding a String in an exe file (Credits: Galactus)
file$ = Text1.Text
Open file$ For Binary As #2
step1 = LOF(2)
Step2 = step1
Step3 = 1
While Step2 >= 0
If Step2 > 32000 Then
Step4 = 32000
ElseIf Step2 = 0 Then
Step4 = 1
Else
Step4 = Step2
End If
Step5$ = String$(Step4, " ")
Get #2, Step3, Step5$
WhatToFind = InStr(1, Step5$, "hello", 1)
If WhatToFind >= 1 Then
Msgbox "Hello was Found"
End If
Exit Sub
Wend
Close #2

Removing something from a listbox
In List1_Click put this:
a = List1.ListIndex
List1.RemoveItem (a)

Getting the list string
In List1_Click put this:
a = List1.ListIndex
b = List1.List(a)
MsgBox b

Printing
Printer.FontSize = 12
Printer.FontName = "Arial"
Printer.Print  "GD's Page is the best :)"
Printer.EndDoc

Launching a website address
Note: [email protected]   has helped me with the following code:
Declaration:
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
Constant:
Private Const SW_SHOWNORMAL = 1
Code:
Site = ShellExecute(Form1.hwnd, vbNullString, "http://members.aol.com/GD196", vbNullString, "c:\", SW_SHOWNORMAL)

Messagebox Values
 
Command Value
OK 1
Cancel 2
Abort 3
Retry 4
Ignore 5
Yes 6
No 7
 
Example:
Now lets make a yes and no messagebox:
a = msgbox ("Do you want to exit?,16,"Exit?") ' 16 is where u place the value but the value 16 is for yes and no
if a = 6 then
end
else
msgbox "You did not exit!"
end if

About Box (MS Format)

 

Declaration:

Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long

Code:

a = ShellAbout(Form1.hwnd, "GD's Application", "Made By: GD", 0&)


Input Box

Code:

x = inputbox ("Hi this is GD what's your name?","GD")

msgbox "Your name is " & x,64,"Did you know..."

 

Note: Most of the time we use InputBox to save space when making the program and it's a lot easier to get the User's input

 


Blocking Ctrl + Alt + Del

Declaration:

Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Code:

Sub GDDis(v As Boolean)
GD = SystemParametersInfo(97, v, CStr(1), 0)
End Sub


Making a circular form


Note: Put the declarations in General_Declarations NOT in a module

Declaration:
Private Declare Function CreateEllipticRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 As Long) As Long

Private Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hRgn As Long, _
ByVal bRedraw As Boolean) As Long

Code:
Show
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 500), True

**Put the code in form1_load


Making a wave file play from RES

First make a directory called Res

Copy these files into that directory:

RC.exe
RCdll.dll
...also copy any wave file and call it gd.wav

In notepad put in the following text

1 SOUND MOVEABLE PURE "gd.wav"

Then save the file as gd.rc

After that in windows explorer drag and drop gd.rc to rc.exe and it will make gd.res

Then in VB5 click Project-->Add File then add gd.res.

Then download gdplay.bas by  clicking here....Add it to your VB project

Then in a command button put in the following code:

BeginPlaySound 1

And that's how you make a wave file play from memory you no longer need to add the wave file with your exe program it's compiled into the program :)

Note: GDPlay.bas came from ATM.bas which came with VB5 :)

 


Opening and Closing CD-Rom Drive

 

Delcarations:

Declare Function mcisendstring Lib "MMSystem" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal wReturnLength As Integer, ByVal hCallback As Integer) As Long

 

Code:

gdx = MCISendString("set CDAudio door closed", returnstring, 127, 0) ' 'This is to close it

 

gdxx = MCISendString("set CDAudio door open", returnstring, 127, 0) ' This is to Open it

 

 

 

 

 


Email Address: [email protected]

Copyright � 1996-1998 GD Corp - Zero-Inc. All Rights Reserved.

Main URL: GD.Cjb.Net