procedure Alpha_Triangle(p1,p2,p3: tpoint;r,g,b,ratio: byte; bit1: tbitmap);
{
p1,p2,p3 = the 3 vertices or points at the corners of the triangle
r,g,b = the red, green, and blue values being averaged with the colours behind
ratio = a value from 0 to 255 that determines how opaque the fill of the triangle will be
-> 0 for transparent, 255 for completely opaque, however,
in either of these extremes, it doesn't make sence to use this procedure
bit1 = the bitmap having the triangle drawn on
}
// this function draws a filled triangle
// by dividing it in half and stepping through
// each line
var
x,y: integer;
height: integer; // looping variables
dx_right,dx_left: real;
// the dx/dy ratio of the right and left edges of the line
xs, xe: real; // // the starting and ending points of the edges
temp_x, temp_y: integer;
right_x,left_x: integer;
pb: pbytearray;
w: integer; // (width of bitmap) * (# of bytes per pixel)
x2: integer; // x*(# of bytes per pixel)
miny,maxy,minx,maxx: integer;
nratio: byte;
begin
if (p1.x<0)and(p2.x<0)and(p3.x<0) then
exit;
if (p1.y<0)and(p2.y<0)and(p3.y<0) then
exit;
maxx:=bit1.width-1;
if (p1.x>maxx)and(p2.x>maxx)and(p3.x>maxx) then
exit;
maxy:=bit1.height-1;
if (p1.y>maxy)and(p2.y>maxy)and(p3.y>maxy) then
exit;
// exit if none of the triangle will be shown anyway
nratio:=255-ratio;
bit1.PixelFormat:=pf24bit;
w:=bit1.width*3;
// make sure points are in order
if (p2.y < p1.y) then
begin
temp_y := p1.y;
temp_x := p1.x;
p1.y := p2.y;
p1.x := p2.x;
p2.y := temp_y;
p2.x := temp_x;
end;
if (p3.y < p1.y) then
begin
temp_y := p1.y;
temp_x := p1.x;
p1.y := p3.y;
p1.x := p3.x;
p3.y := temp_y;
p3.x := temp_x;
end;
if (p3.y < p2.y) then
begin
temp_y := p3.y;
temp_x := p3.x;
p3.y := p2.y;
p3.x := p2.x;
p2.y := temp_y;
p2.x := temp_x;
end;
left_x := p2.x;
if p3.y=p1.y then
right_x := 10000
else
right_x := round(p1.x + (p2.y-p1.y)*(p3.x-p1.x)/(p3.y-p1.y));
if (right_x < left_x)then // messes up if right is on left
begin
temp_x := right_x;
right_x := left_x;
left_x := temp_x;
end;
/////!!DRAW TOP!!///////
//draw the triangle top
if (p1.y <> p2.y) then
begin
// compute height of subtriangle
height := p2.y - p1.y;
// set starting points
xs := p1.x;
xe := p1.x;
// compute edge ratios
dx_left := (left_x - p1.x) / height;
dx_right := (right_x - p1.x) / height;
///DRAW IT ALREADY!!!!
miny:=max(0,p1.y);
maxy:=min(bit1.height-1,p2.y);
for y := miny to maxy do
begin
pb:=bit1.ScanLine[y];
minx:=max(0,trunc(xs));
maxx:=min(bit1.width-1,trunc(xe));
for x := minx to maxx do
begin
x2:=x*3;
pb[x2]:=(pb[x2]*nratio+b*ratio) shr 8;
pb[x2+1]:=(pb[x2+1]*nratio+g*ratio) shr 8;
pb[x2+2]:=(pb[x2+2]*nratio+r*ratio) shr 8;
end;
//adjust starting and ending point
xs :=xs+ dx_left;
xe :=xe+ dx_right;
end;
end;
if (p2.y <> p3.y) then
begin
//now recompute slope of shorter edge to finish triangle bottom
// recompute slopes
height := p3.y - p2.y;
dx_right := (p3.x - right_x) / (height);
dx_left := (p3.x - left_x) / (height);
xs := left_x;
xe := right_x;
if p3.y>= bit1.height then
p3.y:=bit1.height-1; // prevent an access violation error
// draw the rest of the triangle
miny:=max(0,p2.y+1);
maxy:=min(bit1.height-1,p3.y);
for y := miny to maxy do
begin
pb:=bit1.ScanLine[y];
minx:=max(0,trunc(xs));
maxx:=min(bit1.width-1,trunc(xe));
for x := minx to maxx do
begin
x2:=x*3;
pb[x2]:=(pb[x2]*nratio+b*ratio) shr 8;
pb[x2+1]:=(pb[x2+1]*nratio+g*ratio) shr 8;
pb[x2+2]:=(pb[x2+2]*nratio+r*ratio) shr 8;
end;
//adjust starting and ending point
xs :=xs+ dx_left;
xe :=xe+ dx_right;
end; //end for
end;
end;
info : Planetsourcecode.com
var
h, i, j, z : Integer;
sDate : String;
Year, Month, Day : Word;
YearNode, MonthNode, DayNode : TTreeNode;
Const
MonthsInYear : Array [0..11] of String = ('January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December');
DaysInMonth : Array [0..11] of Integer = (31,28,31,30,31,30,31,31,30,31,30,31);
begin
YearNode := Nil;
DecodeDate(Date, Year, Month, Day);
{set default integers}
z := 0;
Tree.Items.BeginUpdate;
{years will be a variable that the user can configure, make sure user does not select years > 9999}
for h := 0 to NumberOfYears - 1 do
begin
if NumberOfYears > 1 then
begin
YearNode := Tree.Items.Add(Nil,IntToStr(Year));// Child(Tree.TopItem, IntToStr(Year));
YearNode.ImageIndex := 0;
YearNode.SelectedIndex := 0;
end;
{loop for how ever many months}
for i := 0 to high(MonthsInYear) - (high(MonthsInYear) - 2) do
begin
{add a new month each pass}
if NumberOfYears > 1 then
MonthNode := Tree.Items.AddChild(YearNode, MonthsInYear[Month - 1] + ' ' + IntToStr(Year))
Restrict Delete characters from a text box string
Diposting oleh Source Code Program | 07.53 | JavaScript | 0 komentar »Name : Restrict Delete characters from a text box string
Description :The user can set a character that the user wants to not allow in an text box entry field. This performs the check for all text boxes on a form.
By: Duane Warsham Assumes:The user can set a character that the user wants to not allow in an text box entry field. Change the Comma declaration to the numeric code of the key you want to exclude. I have added a simple alert function to message you the codes as you type them to simplify getting the correct key code. simply remove it when you have your keycode. Dont forget to put the script tags around this code,uploading would not allow the tags in the code.
document.onkeydown = keyHit;
Comma = 188;
function keyHit(evt)
{
thiskey = window.event.keyCode;
if (thiskey == Comma)
{window.event.keyCode = 46};
alert(thiskey); // remove this line when u have the keyCode number you want to exclude
}
Search for directory default browser
Diposting oleh Source Code Program | 19.14 | visual basic | 0 komentar »"Search for directory default browser
Option Explicit
Private Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal sResult As String) As Long
Private Const MAX_PATH As Long = 260
Private Const ERROR_FILE_SUCCESS As Long = 32
Private Function GetBrowserName(dwFlagReturned As Long) As String
Dim l_hFile As Long
Dim sResult As String
"html file created while the later will be called
sResult = Space$(MAX_PATH)
dwFlagReturned = FindExecutable("dummy.html", App.Path, sResult)
"delete a file that is created
Kill App.Path & "\dummy.html"
GetBrowserName = TrimNull(sResult)
End Function
Private Sub Command1_Click()
Dim l_Temp As Long
Dim sBrowser As String
sBrowser = GetBrowserName(l_Temp)
Select Case l_Temp
Case Is >= ERROR_FILE_SUCCESS
MsgBox "Location of default browser: " & sBrowser, vbInformation
Case Else
MsgBox "Can't find default browser", vbInformation
End Select
End Sub
Leaving the Mouse Pointer in the middle of control 2
Diposting oleh Source Code Program | 01.19 | visual basic | 0 komentar »Sempel visual basic code soutrce Mouse Pointer in the middle of control
Sub CenterCursor(hWnd As Long)
Dim rPosition As RECT
#If Win32 Then
Dim X As Long
Dim Y As Long
#Else
Dim X As Integer
Dim Y As Integer
#End If
GetWindowRect hWnd, rPosition
X = (rPosition.right + rPosition.left) / 2
Y = (rPosition.bottom + rPosition.top) / 2
SetCursorPos X, Y
End Sub
CenterCursor hWnd:=Command1.hWnd
Leaving the Mouse Pointer in the middle of control
Diposting oleh Source Code Program | 01.15 | visual basic | 0 komentar »#If Win32 Then
Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Declare Sub GetWindowRect Lib "User32" (ByVal hWnd As _
Long, lpRect As RECT)
Declare Sub SetCursorPos Lib "User32" (ByVal X As _
Long, ByVal Y As Long)
#Else
Type RECT
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
Declare Sub GetWindowRect Lib "User" (ByVal hWnd _
As Integer, lpRect As RECT)
Declare Sub SetCursorPos Lib "User" (ByVal X As _
Integer, ByVal Y As Integer)
#End If
vb connection example using app.path
Diposting oleh Source Code Program | 00.55 | visual basic | 0 komentar »Private Sub DataEnvironment_Initialize()
' The re-connection
Connection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data " _
"Source=C:\nc\ims.mdb "
End Sub
Window Status Bar - Link change
Diposting oleh Source Code Program | 18.51 | JavaScript | 0 komentar »<HTML>
<HEAD>
<TITLE>default Text in the Status Bar when mouse cursor is
over link</TITLE>
</HEAD>
<BODY>
Look in the status Bar and put mouse cursor over link<BR>
Planet source code<BR>
All the script is in the body of the document too!<BR><BR>
<A href="http://www.komputerprogramming.blogspot.com"
onMouseover="window.status='One of the best
places to post/get code to/from on the net!';return true"
onMouseout="window.status='';return true">'mouse over' this!</A>
</BODY>
</HTML>
sempel source code click right diabled<HTML>
<HEAD>
<TITLE>Just try to right click on me</TITLE>
</HEAD>
<SCRIPT>
<!-- JavaScript Start -----
function click() {if (event.button==2) { alert('Disabled') } }
document.onmousedown=click
----- JavaScript End ------>
</SCRIPT>
<BODY>
Just try to right click
</BODY>
</HTML>
Private Sub Command1_Click()
Dim Radius
Radius = InputBox("Type In The Radius", "Radius")
Dim Area
Area = 3.14 * (Radius * Radius)
MsgBox Area, vbDefaultButton1, "Answer"
Dim Answer
End Sub
CHANGE AOL'S WELCOME MENU'S CAPTION
Diposting oleh Source Code Program | 01.41 | visual basic | 0 komentar »Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function sendmessagebystring Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Const WM_SETTEXT = &HC
Function FindChildByClass(parentw, childhand)
firs% = GetWindow(parentw, 5)
If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then Goto bone
firs% = GetWindow(parentw, GW_CHILD)
If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then Goto bone
While firs%
firss% = GetWindow(parentw, 5)
If UCase(Mid(GetClass(firss%), 1, Len(childhand))) Like UCase(childhand) Then Goto bone
firs% = GetWindow(firs%, 2)
If UCase(Mid(GetClass(firs%), 1, Len(childhand))) Like UCase(childhand) Then Goto bone
Wend
FindChildByClass = 0
bone:
room% = firs%
FindChildByClass = room%
End Function
Function FindChildByTitle(parentw, childhand)
firs% = GetWindow(parentw, 5)
If UCase(GetCaption(firs%)) Like UCase(childhand) Then Goto bone
firs% = GetWindow(parentw, GW_CHILD)
While firs%
firss% = GetWindow(parentw, 5)
If UCase(GetCaption(firss%)) Like UCase(childhand) & "*" Then Goto bone
firs% = GetWindow(firs%, 2)
If UCase(GetCaption(firs%)) Like UCase(childhand) & "*" Then Goto bone
Wend
FindChildByTitle = 0
bone:
room% = firs%
FindChildByTitle = room%
End Function
Sub RenameWelcomeWindow(NewCaption As String)
ao% = FindWindow("AOL Frame25", vbNullString)
bb% = FindChildByClass(ao%, "MDIClient")
arf = FindChildByTitle(bb%, "Welcome, ")
Call ChangeWindowCap(arf, NewCaption)
End Sub
Sub ChangeWindowCap(WindowClassName, NewName As String)
b = sendmessagebystring(WindowClassName, WM_SETTEXT, 0, NewName)
End Sub
Sub Command1_Click ()
RenameWelcomeWindow("New Welcome Menu Caption")
End Sub
info: planetsourcecode.com
Random String Generator With Patterns and Extra Options
Diposting oleh Source Code Program | 01.32 | delphi | 0 komentar »Name : Random String Generator With Patterns and Extra Options
Description :Creates Random Strings of a specific length. There r sum options that u can use, and u can set ur own pattern. So, it can b pretty useful. Hope it is. :) if u want to c the code implemented in a Program, u can take a look at mycode example that i submitted. I'll put the link when i get it.
Function GenStr(MaxLen,Restrictions:Integer):String;Overload;
{Possible Resctiction Values:
1 - All
2 - Just Letters and Numbers
3 - Just Numbers
4 - Just Letters
}
Var St:Byte;
Total:String;
begin
Repeat
Randomize;
St := Random(255);
// All Caracters
If Restrictions = 1 then
Total := Total + chr(St);
//Just Letters and Numbers
If Restrictions = 2 then
If (St >= 48) and (St <= 57) or (St >= 65) and (St <= 90) or (St >= 97) and (St <= 122) then
Total := Total + chr(St);
//Just Numbers
If Restrictions = 3 then
If (St >= 48) and (St <= 57) then
Total := Total + chr(St);
//Just Letters
If Restrictions = 4 then
If (St >= 65) and (St <= 90) or (St >= 97) and (St <= 122) then
Total := Total + chr(St);
Until Length(Total) = MaxLen;
Result := Total;
end;
Function GenStr(MaxLen:Integer;Pattern:String):String;Overload;
{Possible Resctiction Values:
1 - All
2 - Just Letters and Numbers
3 - Just Numbers
4 - Just Letters
Possble Pattern Parameters:
A or a - All
L - Letter In Capitals
l - Letter not in capitals
C or c - Character ( A,B or a,b (etc.))
N or n - Numbers
R or r - Random Generated Pattern
Ex:
If u wanted a generated string that was Number, number,number,Captiol
letter then any letter, u would use this pattern:
NNNLC or NNNLc
}
Var St:Byte;
Total:String;
Ptrn:String;
P:Byte;
PtrnCount:Integer;
begin
//If pattern is set to random, we need to make a pattern ourselves
If (Pattern = 'R') or (Pattern = 'r') then
Begin
repeat
//Get ready for random
Randomize;
//Get random number
P := Random(225);
//Check to c if its a pattern number or not (ASCII values of A,N,L,l,etc.
Case P of
//A or a
65 or 97:Ptrn := Ptrn + 'A';
//L
78:Ptrn := Ptrn + 'L';
//l
108:Ptrn := Ptrn + 'l';
//C or c
67 or 99:Ptrn := Ptrn + 'C';
//N or n
78 or 110:Ptrn := Ptrn + 'N';
end;
until Length(Ptrn) = (MaxLen div 2) + 1;
//Set the New Pattern
Pattern := Ptrn;
end;
//String Generation Section
PtrnCount := 0;
Repeat
//Prepare to random
Randomize;
//Add 1 to PtrnCount
Inc(PtrnCount);
//A or a //Everything Is OK
If (Pattern[PtrnCount] = 'A') or (Pattern[PtrnCount] = 'a') then
Total := Total + chr(Random(255));
//L //Just Capitol Letters
If (Pattern[PtrnCount] = 'L') then
Begin
Repeat
//Get random number
St := Random(255);
Until (St >= 65) and (St <= 90);
Total := Total + chr(St);
end;
//l //Letters, but not it capitols
If (Pattern[PtrnCount] = 'l') then
Begin
Repeat
//Get random number
St := Random(255);
Until (St >= 97) and (St <= 122);
Total := Total + chr(St);
end;
//C or c //Any letter, wether its a capitol or not
If (Pattern[PtrnCount] = 'C') or (Pattern[PtrnCount] = 'c') then
begin
Repeat
//Get random number
St := Random(255);
Until (St >= 65) and (St <= 90) or (St >= 97) and (St <= 122);
Total := Total + chr(St);
end;
//N or n //Number
If (Pattern[PtrnCount] = 'N') or (Pattern[PtrnCount] = 'n') then
begin
Repeat
//Get random number
St := Random(255);
Until (St >= 48) and (St <= 57);
Total := Total + chr(St);
end;
//IF PtrnCount is at it's max, reset it
If PtrnCount = Length(Pattern) then
PtrnCount := 0;
Until Length(Total) = MaxLen;
Result := Total;
end;
info : planetsorcecode.com
Page Properties and Printing
Diposting oleh Source Code Program | 00.45 | microsoft office | 0 komentar »Set Print Titles
The print titles function allows you to repeat the column and row headings at the beginning of each new page to make reading a multiple page sheet easier to read when printed. To Print Titles:
- Click the Page Layout tab on the Ribbon
- Click the Print Titles button
- In the Print Titles section, click the box to select the rows/columns to be repeated
- Select the row or column
- Click the Select Row/Column Button
- Click OK

Create a Header or Footer
To create a header or footer:
- Click the Header & Footer button on the Insert tab
- This will display the Header & Footer Design Tools Tab
- To switch between the Header and Footer, click the Go to Header or Go to Footer button

- To insert text, enter the text in the header or footer
- To enter preprogrammed data such as page numbers, date, time, file name or sheet name, click the appropriate button
- To change the location of data, click the desired cell
Set Page Margins
To set the page margins:
- Click the Margins button on the Page Layout tab
- Select one of the give choices, or

- Click Custom Margins
- Complete the boxes to set margins
- Click Ok

Change Page Orientation
To change the page orientation from portrait to landscape:
- Click the Orientation button on the Page Layout tab
- Choose Portrait or Landscape

Set Page Breaks
You can manually set up page breaks in a worksheet for ease of reading when the sheet is printed. To set a page break:
- Click the Breaks button on the Page Layout tab
- Click Insert Page Break

Print a Range
There may be times when you only want to print a portion of a worksheet. This is easily done through the Print Range function. To print a range:
- Select the area to be printed
- Click the Print Area button on the Page Layout tab
- Click Select Print Area
Sort and Filter office 2007
Diposting oleh Source Code Program | 00.31 | microsoft office | 0 komentar »Sorting and Filtering allow you to manipulate data in a worksheet based on given set of criteria.
Basic Sorts
To execute a basic descending or ascending sort based on one column:
- Highlight the cells that will be sorted
- Click the Sort & Filter button on the Home tab
- Click the Sort Ascending (A-Z) button or Sort Descending (Z-A) button

Custom Sorts
To sort on the basis of more than one column:
- Click the Sort & Filter button on the Home tab
- Choose which column you want to sort by first
- Click Add Level
- Choose the next column you want to sort
- Click OK

Filtering
Filtering allows you to display only data that meets certain criteria. To filter:
- Click the column or columns that contain the data you wish to filter
- On the Home tab, click on Sort & Filter
- Click Filter button
- Click the Arrow at the bottom of the first cell
- Click the Text Filter
- Click the Words you wish to Filter

- To clear the filter click the Sort & Filter button
- Click Clear
info :www.fgcu.eduAdd a horizontal scrollbar to a listbox
Diposting oleh Source Code Program | 05.53 | delphi | 0 komentar »procedure TForm1.Timer1Timer(Sender: TObject);
var
i,len,width: integer;
begin
with listbox1 do
begin
width := 0;
for i := 0 to items.count -1 do
begin
len := canvas.textwidth(items[i]);
if len > width then width := len;
end;
//set listbox's horizontal scrollbar width
Perform(LB_SETHORIZONTALEXTENT,width+100,0);
end;
end;
access application information programmatically
Diposting oleh Source Code Program | 05.22 | delphi | 0 komentar »function Application_Version: String;
const
InfoNum = 10;
InfoStr: array[1..InfoNum] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments');
var
S: string; n, Len, i: DWORD;
Buf: PChar; Value: PChar;
begin
S := Application.ExeName; //this application's EXE filename
n := GetFileVersionInfoSize(PChar(S), n); // the return value is the size in bytes of the file's version information.
Result := ''; (* this sets a default result in case a file version isn't found.
I add this to functions because the compiler will bug you that
the result may not be defined otherwise. you could change this,
or remove it alltogether, although it's probably best to leave it. *)
if n > 0 then begin
Buf := AllocMem(n); // allocate the needed amount of memory into the buffer
GetFileVersionInfo(PChar(S), 0, n, Buf); // store the file version information in the memory buffer. it stores all of the values listed in the InfoStr array.
for i := 1 to InfoNum do
if VerQueryValue(Buf, PChar('StringFileInfo\040904E4\' + InfoStr[i]), Pointer(Value), Len) then
if trim(lowerCase(InfoStr[i])) = 'fileversion' then Result := Value;// loop through each value until we find the "FileVersion" information.
FreeMem(Buf, n); // free the memory we stored in the buffer.
end;
end;
Your Complex Number Class
Imports System
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim X, Y As Complex
X = New Complex(1, 2)
Y = New Complex(3, 4)
Console.WriteLine( (X + Y).ToString )
Console.WriteLine( (X - Y).ToString )
Console.WriteLine( (X * Y).ToString )
Console.WriteLine( (X = Y).ToString )
Console.WriteLine( (X <> Y).ToString )
Console.WriteLine( (-X).ToString )
Dim abs_x As Double = CDbl(X)
Console.WriteLine( abs_x.ToString )
End Sub
End Class
Public Class Complex
Public realPart As Double
Public imaginaryPart As Double
' Constructors.
Public Sub New()
End Sub
Public Sub New(ByVal real_part As Double, ByVal imaginary_part As Double)
realPart = real_part
imaginaryPart = imaginary_part
End Sub
' ToString.
Public Overrides Function ToString() As String
Return realPart.ToString & " + " & imaginaryPart.ToString & "i"
End Function
' Operators.
Public Shared Operator *(ByVal c1 As Complex, ByVal c2 As Complex) As Complex
Return New Complex( _
c1.realPart * c2.realPart - c1.imaginaryPart * c2.imaginaryPart, _
c1.realPart * c2.imaginaryPart + c1.imaginaryPart * c2.realPart)
End Operator
Public Shared Operator +(ByVal c1 As Complex, ByVal c2 As Complex) As Complex
Return New Complex( _
c1.realPart + c2.realPart, _
c1.imaginaryPart + c2.imaginaryPart)
End Operator
Public Shared Operator -(ByVal c1 As Complex, ByVal c2 As Complex) As Complex
Return New Complex( _
c1.realPart - c2.realPart, _
c1.imaginaryPart - c2.imaginaryPart)
End Operator
Public Shared Operator =(ByVal c1 As Complex, ByVal c2 As Complex) As Boolean
Return (c1.realPart = c2.realPart) AndAlso (c1.imaginaryPart = c2.imaginaryPart)
End Operator
Public Shared Operator <>(ByVal c1 As Complex, ByVal c2 As Complex) As Boolean
Return (c1.realPart <> c2.realPart) OrElse (c1.imaginaryPart <> c2.imaginaryPart)
End Operator
Public Shared Operator -(ByVal c1 As Complex) As Complex
Return New Complex(c1.imaginaryPart, c1.realPart)
End Operator
Public Shared Narrowing Operator CType(ByVal c1 As Complex) As Double
Return System.Math.Sqrt(c1.realPart * c1.realPart + c1.imaginaryPart * c1.imaginaryPart)
End Operator
End Class
Nested Class Demo
Public Class Fraction
Private numerator As Integer
Private denominator As Integer
Public Sub New( _
ByVal numerator As Integer, ByVal denominator As Integer)
Me.numerator = numerator
Me.denominator = denominator
End Sub 'New
Public Overrides Function ToString( ) As String
Return [String].Format("{0}/{1}", numerator, denominator)
End Function 'ToString
' Nested Class
Class FractionArtist
Public Sub Draw(ByVal f As Fraction)
Console.WriteLine("Drawing the numerator: {0}", f.numerator)
Console.WriteLine( _
"Drawing the denominator: {0}", f.denominator)
End Sub 'Draw
End Class 'FractionArtist
End Class 'Fraction
Declare Function ShowCursor& Lib "user32" _
(ByVal bShow As Long)
'Add this code to Command1.
Private Sub Command1_Click()
ShowCursor (bShow = True)
End Sub
'Add this to Command2.
Private Sub Command2_Click()
ShowCursor (bShow = False)
End Sub
What is Visual Basic?
Visual Basic is a "visual programming" environment for developing Windows (also Web now) applications. Visual Basic makes it possible to develop complicated applications very quickly. The programmer designs windows graphically, drags program elements from the Visual Basic Toolbox and writes basic code for each element. Visual Basic is " event driven" which means that procedures are called automatically when the end user chooses menu items, clicks the mouse, moves objects on the screen, etc.
Why is Visual Basic popular?
Programmers have undergone a major change in many years of programming various machines. For example, what could take days to create an application in other programming languages like C, C++ could be done in hours with Visual Basic. Visual Basic provides many interesting sets of tools to aid us in building exciting applications. Visual Basic provides these tools to make our life far more easier because all the real hard code is already written for us.
Visual Basic is not only a programming language but also a true graphical development environment. This environment allows programmers with little programming experience to quickly develop powerful Windows applications. Visual Basic also has the ability to develop programs that can be used as a front-end application to a database system, serving as the user interface which collects user input and displays formatted output in a more appealing and useful form.
Visual Basic is very popular for the ease with which it allows the programmer to create nice looking graphical programs with less coding unlike many other languages that take thousands of lines of programmer keyed code. As the programmer works in the graphical environment much of the program code is automatically generated by the Visual Basic program.
Areas of Use
Using Visual Basic's tools we can quickly translate an abstract idea into a program design that we can actually see on the screen. VB encourages you to experiment, revise, correct, and network your design until the new project meets your requirements. However, most of all, it inspires your imagination and creativity. Visual Basic is ideal for developing applications that run on the Windows operating system. Developing applications with VB can be said to be a 3-step approach:
1) Design the appearance of application
2) Assign property settings to the objects of the program
3) Write the code to direct specific tasks at runtime
Visual Basic is used to develop applications in a number of different areas. Some of them are listed below:
• Accounting
• Business
• Commerce
• Consulting
• Education
• Law
• Marketing and Sales
• Medicine
• Research
• Science
Many of the things that we do with Visual Basic really aren’t very basic. The Visual Basic language is powerful, if you can imagine a programming task, it can be accomplished using Visual Basic.
History of Visual Basic
Microsoft first released Visual Basic in 1987. It was the first visual development tool from Microsoft, and it was to compete with C, C++, Pascal and other well-known programming languages. From the start, Visual Basic wasn't a hit. It wasn't until release 2.0 that people really discovered the potential of the language, and with release 3.0 it had become the fastest-growing programming language on the market.
Below is the order and the approximate year in which a new version of Visual Basic was released:
• 1991, VB1 Debuts
• 1992, VB2 Debuts
• 1993, VB3 Debut
• 1996, VB4 Debuts
• 1997, VB5 Debuts
• 1998, VB6 Debuts
• 2001, VB. NET Debuts
Imports System.IO
public class Tester
public Shared Sub Main
On Error GoTo ErrorHandle
Exit Sub
ErrorHandle:
Select Case Err.Number
Case 52
Console.WriteLine("File Name Exception")
Case 53
Console.WriteLine("File cannot be found")
Case 54
Console.WriteLine("File Mode Exception")
Case 55
Console.WriteLine("File is aleady open")
Case 58
Console.WriteLine("File exists")
Case 68
Console.WriteLine("Device is not available")
Case 75
Console.WriteLine("Path Exception")
Case 76
Console.WriteLine("Path cannot be found")
Case Else
Console.WriteLine("Other")
End Select
End Sub
End class
Imports System.IO
public class Tester
public Shared Sub Main
Dim myfile As System.IO.File
Dim w As System.IO.StreamWriter
On Error GoTo errorhandle
w = myfile.AppendText("a:\temp.txt")
w.Write("a")
w.Close()
Exit Sub
errorhandle:
Console.WriteLine("Please Insert")
Exit Sub
Resume
End Sub
End class
In this tutorial we'll be learning how to make a simple stopwatch.
2 Labels with:
#1 Label:
Name: Label1
Caption: SIMPLE STOPWATCH
#2 Label:
Name: Label2
Caption: 0.00
4 Command Buttons with:
#1 Command Button:
Name: Command1
Caption: START
#2 Command Button:
Name: Command2
Caption: STOP
#3 Command Button:
Name: Command3
Caption: RESET
#4 Command Button:
Name: Command4
Caption: QUIT
1 Timer with:
Name: Timer1
Caption: (None)
Interval: 1
Code
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Label2.Caption = "0.00"
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Format(Val(Label2.Caption) + 0.01, _
"fixed")
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Label2.Caption = "0.00"
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Timer1_Timer()
Label2.Caption = Format(Val(Label2.Caption) + 0.01, _
"fixed")
End Sub
This means make Label2's caption change by adding +0.01 to it every millisecond.
1. InStr is a function that looks for the position of a substring in a phrase.
InStr(phrase,"ual") will find the substring "ual" from "Visual Basic" and then return its position, in this case, it is 4 from the left.
2. Left is a function that extracts characters from a phrase, starting from the left. Left(phrase,4) means 4 characters are extracted from the phrase, starting from the leftmost position.
3. Right is a function that extracts characters from a phrase, starting from the Right. Right(phrase,5) means 5 characters are extracted from the phrase, starting from the rightmost position.
4. Mid is a function that extracts a substring from a phrase, starting from the posiiton specified by the second parameter in the bracket.Mid(phrase,8,3) means a substring of three characters are extracted from the phrase, starting from the 8th position from the left
5. Len is a function that return the length of a phrase.
Private Sub cmdInstr_Click()Dim phrase As String
phrase = Cells(1, 1).Value
Cells(4, 1) = InStr(phrase, "ual")
End Sub
Private Sub cmdLeft_Click()
Dim phrase As String
phrase = Cells(1, 1).Value
Cells(2, 1) = Left(phrase, 4)
End Sub
Private Sub cmdLen_Click()
Dim phrase As String
phrase = Cells(1, 1).Value
Cells(6, 1) = Len(phrase)
End Sub
Private Sub cmdMid_Click()
Dim phrase As String
phrase = Cells(1, 1).Value
Cells(5, 1) = Mid(phrase, 8, 3)
End Sub
Private Sub cmdRight_Click()
Dim phrase As String
phrase = Cells(1, 1).Value
Cells(3, 1) = Right(phrase, 5)
Private Sub Label1_Click()
Top = (Screen.Height - Width) / 1
Left = (Screen.Width - Height) / 2
Top = (Screen.Height - Width) / 3
Left = (Screen.Width - Height) / 4
Top = (Screen.Height - Width) / 5
Left = (Screen.Width - Height) / 6
Top = (Screen.Height - Width) / 7
Left = (Screen.Width - Height) / 8
Top = (Screen.Height - Width) / 9
Top = (Screen.Height - Width) / 10
Left = (Screen.Width - Height) / 12
Top = (Screen.Height - Width) / 13
Left = (Screen.Width - Height) / 14
Top = (Screen.Height - Width) / 15
Left = (Screen.Width - Height) / 16
Top = (Screen.Height - Width) / 17
Left = (Screen.Width - Height) / 18
Top = (Screen.Height - Width) / 19
Left = (Screen.Width - Height) / 20
Top = (Screen.Height - Width) / 21
Left = (Screen.Width - Height) / 22
Top = (Screen.Height - Width) / 23
Left = (Screen.Width - Height) / 24
Top = (Screen.Height - Width) / 25
Left = (Screen.Width - Height) / 26
Top = (Screen.Height - Width) / 27
Left = (Screen.Width - Height) / 28
Top = (Screen.Height - Width) / 29
Left = (Screen.Width - Height) / 30
Top = (Screen.Height - Width) / 31
Left = (Screen.Width - Height) / 32
Top = (Screen.Height - Width) / 31
Top = (Screen.Height - Width) / 30
Left = (Screen.Width - Height) / 29
Top = (Screen.Height - Width) / 28
Left = (Screen.Width - Height) / 27
Top = (Screen.Height - Width) / 26
Left = (Screen.Width - Height) / 25
Top = (Screen.Height - Width) / 24
Left = (Screen.Width - Height) / 23
Top = (Screen.Height - Width) / 22
Top = (Screen.Height - Width) / 21
Left = (Screen.Width - Height) / 20
Top = (Screen.Height - Width) / 19
Left = (Screen.Width - Height) / 18
Top = (Screen.Height - Width) / 17
Left = (Screen.Width - Height) / 16
Top = (Screen.Height - Width) / 15
Left = (Screen.Width - Height) / 14
Top = (Screen.Height - Width) / 13
Left = (Screen.Width - Height) / 12
Top = (Screen.Height - Width) / 11
Left = (Screen.Width - Height) / 10
Top = (Screen.Height - Width) / 9
Left = (Screen.Width - Height) / 8
Top = (Screen.Height - Width) / 7
Left = (Screen.Width - Height) / 6
Top = (Screen.Height - Width) / 5
Left = (Screen.Width - Height) / 4
Top = (Screen.Height - Width) / 3
Left = (Screen.Width - Height) / 2
Top = (Screen.Width + Height) / 2
Left = (Screen.Height + Width) / 3
Top = (Screen.Width + Height) / 4
Left = (Screen.Height + Width) / 5
Top = (Screen.Width + Height) / 6
Left = (Screen.Height + Width) / 7
Top = (Screen.Width + Height) / 8
Left = (Screen.Height + Width) / 9
Top = (Screen.Width + Height) / 10
Left = (Screen.Height + Width) / 11
Top = (Screen.Width + Height) / 12
Left = (Screen.Height + Width) / 13
Top = (Screen.Width + Height) / 14
Left = (Screen.Height + Width) / 15
Top = (Screen.Width + Height) / 16
Left = (Screen.Height + Width) / 17
Top = (Screen.Width + Height) / 18
Left = (Screen.Height + Width) / 19
Top = (Screen.Width + Height) / 20
Left = (Screen.Height + Width) / 21
Top = (Screen.Width + Height) / 22
Left = (Screen.Height + Width) / 23
Top = (Screen.Width + Height) / 24
Left = (Screen.Height + Width) / 25
Top = (Screen.Width + Height) / 26
Left = (Screen.Height + Width) / 27
Top = (Screen.Width + Height) / 28
Left = (Screen.Height + Width) / 29
Top = (Screen.Width + Height) / 30
Left = (Screen.Height + Width) / 31
Top = (Screen.Width + Height) / 32
Left = (Screen.Height + Left) / 31
Top = (Screen.Width + Top) / 30
Left = (Screen.Height + Left) / 29
Top = (Screen.Width + Top) / 28
Left = (Screen.Height + Left) / 27
Top = (Screen.Width + Top) / 26
Left = (Screen.Height + Left) / 25
Top = (Screen.Width + Top) / 24
Left = (Screen.Height + Left) / 23
Top = (Screen.Width + Top) / 22
Left = (Screen.Height + Left) / 21
Top = (Screen.Width + Top) / 20
Left = (Screen.Height + Left) / 19
Top = (Screen.Width + Top) / 18
Left = (Screen.Height + Left) / 17
Top = (Screen.Width + Top) / 16
Left = (Screen.Height + Left) / 15
Top = (Screen.Width + Top) / 14
Left = (Screen.Height + Left) / 13
Top = (Screen.Width + Top) / 12
Left = (Screen.Height + Left) / 11
Top = (Screen.Width + Top) / 10
Left = (Screen.Height + Left) / 9
Top = (Screen.Width + Top) / 8
Left = (Screen.Height + Left) / 7
Top = (Screen.Width + Top) / 6
Left = (Screen.Height + Left) / 5
Top = (Screen.Width + Top) / 4
Left = (Screen.Height + Left) / 3
Top = (Screen.Width + Top) / 2
Left = (Screen.Height + Left) / 1
Form1.Show
End Sub
String Tokenizer Similar To strtok() in C++
Diposting oleh Source Code Program | 20.34 | delphi | 0 komentar »//Declare private string for the unit
implementation
var
TokS: string
//Function To Get Characters From The String function StrMid(const sData: string; nStart: integer; nLength: integer): string; overload;
begin
Result := copy(sData, nStart, nLength);
end;
//Function To Get Characters From The String function StrMid(const sData: string; nStart: integer): string; overload;
begin
Result := copy(sData, nStart, Length(sData) - (nStart - 1));
end;
//String Tokenizer function
function StrTok(S: string; Tok: string = ''): string;
var
i,
LenTok: integer;
begin
if not(S = '') then begin //New String
TokS := S;
result := '';
Exit;
end;
if Tok = '' then begin //If No Token
result := TokS;
Exit;
end;
LenTok := Length(Tok);
for i := 0 to Length(TokS) - LenTok do begin
if StrMid(TokS, i, LenTok) = Tok then begin //If Token Found
result := StrMid(TokS, 1, i - LenTok);
TokS := StrMid(TokS, i + LenTok + 1);
Exit;
end;
end;
//If Program Reaches Here, Return The Rest Of The String
result := TokS;
TokS := '';
end;
Therefore, for example, if you defined a string:
var
S: string
and set S to 'Hello World'
S := 'Hello World';
and then call StrTok() like so:
StrTok(S);
The procedure will store the string, from now on, calling StrTok() with no S value and a token (such as a space ' '), the program will return everything in the string up to the token.
EX:
var
firstWord,
secondWord: string
begin
StrTok(S);
firstWord := StrTok('', ' ');
secondWord := StrTok('', ' ');
end;
//Doing this will break apart the string S at the token (' ') into the first word and the second word.
procedure Delay(ms : longint);
var
TheTime : LongInt;
begin
TheTime := GetTickCount + ms;
while GetTickCount < TheTime do Application.ProcessMessages;
end;

