Showing posts with label VB Programs. Show all posts
Showing posts with label VB Programs. Show all posts

Friday, January 8, 2010

CSE 122 / IT 122 Study and Debug the vb game program (MIDTERM)

These are the objects: 2 shapes(circle and rectangle), 1 timer(interval=500), 1 label (caption=Score:), 1 command button (caption=&Reset)

Note: Use a prefixes in naming of each objects/controls.
controls that has a code: form_load, form_mousemove,timer,command button

Dim v As Integer, Y As Integer, score As Integer

Private Sub Form_Load()
ball.Left = 2500
ball.Top = 1300
X = -50
Y = -50
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
pad.Left = X - pad.Width / 2
End Sub

Private Sub reset_Click()
ball.Left = 2500
ball.Top = 1300
X = -50
Y = -50
reset..Visible = False
score = 0 ' reset the score
scorecard.Caption = "score:" & score ' show the score on our label
Me.Caption = "score:" & score
Timer1.Enabled = True ' start the timer again to get the ball moving
End Sub

Private Sub Time1_Timer()

ball.Move ball.Left + X, ball.Top + Y

If balll.Top <= 0 Then Y = Y * -1 End If If ball.Left <= 0 Then X = X * -1 End If If ball.Left + ball.Width >= Me.ScaleWidth Then
X = X * -1
End If

If ball.Top + ball.Height >= pad.Top Then
If (ball.Left + ball.Width < pad.Left) Or (ball.Left > pad.Left + pad.Width) Then
'if the ball is to the left or right of the pad then
Me.Caption = "game over" ' set the forms captions to read game over
reset.Visible = True 'make the reset button visible
Timer.Enabled = False ' pause the program

Else
Y = Y * -1.05 'speed up the ball
X = X * 1.05 '
score = score + 1 'add 1 more hit to the score
scorecard.Caption = "score:" & score 'show the score on our label
Me.Caption = "score:" & score ' show the score as our forms caption
If (ball.Left + ball.Width / 2) < (pad.Left + pad.Width / 2) Then 'if the ball is to the left or the pad center then If X > 0 Then ' if it is going to the right
X = X * -1 'make it go left
End If
Else ' the ball must be on the right of the pad
If X < 0 Then 'if it is going left
X = X * -1 'make it go right
End If
End If
End If
End If
endif
End Sub

  Design View














 Output View









Tuesday, December 15, 2009

Wednesday, September 30, 2009

Creating VB database applications using ADO control

In this sample, you will create a ADO database application to manage your home library.  First of all, create a database in MS Access and name home_Library. In this database, create a table with the following field names;

Title:
Author:
Publisher:
Year:
Category:
and save the table as booktitle.mdb

Design the Interface as follow:

Key in the codes as follows:
Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtAuthor.Text = ""
txtPublisher.Text = ""
txtYear.Text = ""
txtCategory.Text = ""
End Sub

Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
adoLibrary.Recordset.Delete
MsgBox "Record Deleted!", , "Message"
Else
MsgBox "Record Not Deleted!", , "Message"
End If
End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdNew_Click()
adoLibrary.Recordset.AddNew
End Sub

Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MoveNext
If adoLibrary.Recordset.EOF Then
adoLibrary.Recordset.MovePrevious
End If
End If
End Sub

Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MovePrevious
If adoLibrary.Recordset.BOF Then
adoLibrary.Recordset.MoveNext
End If
End If
End Sub

Private Sub cmdSave_Click()
adoLibrary.Recordset.Fields("Title") = txtTitle.Text
adoLibrary.Recordset.Fields("Author") = txtAuthor.Text
adoLibrary.Recordset.Update
End Sub

Using Crystal Reports in VB

The crystal report writer is an add-in program that comes with visual basic. You use the Crystal Report Writer to create custom reports, lists, labels and form letters using datga from an existing database. However, most of the time- the Crystal Report Writer is used to create reports.

The crystal report writer can be used with the following programs:
  • Microsoft Access
  • dBase
  • Paradox
  • FoxPro
  • Clipper
  • Btrieve
  • SQL Server (via ODBC)
To access the crystal report writer (in visual basic 6.0) click on Add-Ins --> Report Designer. This will take you into Crystal Reports.

CREATING A REPORT:
To create a report, open crystal report writer...
  1. click on File --> New (a Create New dialog will appear).
  2. click on the Standard icon (the Create Report Expert dialog box appears).
  3. click on Datafile (the Choose Database File dialog box appears).
To the left you will see a list of files. To the right is the path showing the folder tree, indicating where the file will be stored.
  1. Click on the file you want to open
  2. Click on Add
  3. Click on Done (the Choose Database File dialog box disappears).
SELECTING FIELDS:
Click on 2: FIELD in the create report expert dialog box. This is where you select the fields that you want to appear in your report. You can select the fields individually by clicking on them and then clicking on ADD, or you can click on ALL, which will select all fields. When a field has been selected, it will be displayed in the REPORT FIELDS window.
You can change column headings as well by clicking and highlighting a field in the Report Fields window, and moving down and typing a new heading for that field. Default headings will appear for each field.

SORTING FIELDS:

Click on 3: SORT tab in the Create Report Expert dialog box. Now select the field you want to have the records sorted by (the selected field will be used to sort all of the records in order by the field selected when the report is produced). You can also set the order to have the table sort in descending order by clicking on the array. Ascending order is the default.

TOTALS AND SUBTOTALS:
Your report has the ability to calculate totals for numeric fields. You can add additional fields by clicking the field and then click the add button. And to delete fields, click on the remove button.
Click on 4: TOTAL tab in the Create Report Expert dialog box. Select field by clicking on it to highlight it. This will create subtotals for that field, and will create section breaks in your report for each record and display a total for the selected field. Now click on the Add button, and this will add the field on the right hand side.
Note: if the check box in the lower right-hand corner is checked, you will get grand totals for your report.
FONTS AND FONT SIZE:
If you would like to adjust the font and font size of your report, first select the field you want to change by clicking on it. And if you want to change more than one, hold the CONTROL key and select the fields you want to change. Now click the arrow to the right of the font window, a drop down menu will appear. Select the font you want by clicking on it to highlight it. And click the arrow to the right of the font size, a drop down menu will appear- and select the font size you want by highlighting it.
SPEEDING UP PROCESSING:
This section is used often if you have large files and want conditions set on the key field or other fields in the file where only certain records will be selected for printing. Setting some keys in this section will speed up processing of records for your report since several records will be skipped.
Click on 5: SELECT tab in the Create Report Expert dialog box. Next, click on SPEED TIP button. This will discuss how records will be selected and how reports will be sped up, if not all records will be used for processing. Now click on OK when finnished reading. Click ADD to add the highlighted field to the Select Fields list box.
The highlight button appears next to the key field in the Report Fields list box. This is because the table contains an index for this field. The key field is often used for filtering out records.
At the bottom of the window, there are two other list boxes, one containing the word "is" and the other containing the words "any value". These two list boxes are used to set conditions to filter out records when producing your report.

DETERMINING THE STYLE:

Click on 6: STYLE tab in the Create Report Expert dialog box. On the left will be a list of styles that you can choose your report to appear in. Click on the one you want. Enter a title for your report by typing it in where it says TITLE at the tob of the Select Fields List Box.
PREVIEWING YOUR REPORT:
To preview the 'final product' simply click PREVIEW REPORT. This will take you to your preview screen showing teh actual report that you have created. There are two modes you can look at in preview report, DESIGN mode and PREVIEW mode.
DESIGN SECTION:
The design section shows the layout of each field in the report, along with titles, headings and totals. You can change the position of a field, making it longer or shorter by clicking on it. You can also change the font and font size of that field.
The design tab contains six sections, as described below...
  1. Title -- Contains information you want to display on the first page only.
  2. Page Header -- Specifies information such as the report title, field headings, and the date.
  3. Details -- Contains the body of the report, database records and subtotals (if you include them).
  4. Grand Total -- Shows the grand totals of all numeric fields talked about in "Totals and Subtotals" above. This section will only appear if you included a grand total in your report.
  5. Page Footer -- Contains page number and any other information you want to appear at the bottom of the page.
  6. Summary -- Contains information you want to appear on the last page only.

Saturday, August 22, 2009

how to search and delete a record in vb6

Option Explicit


Private Sub cmdSearch_Click()

Adodc1.RecordSource = "SELECT * FROM tblStudent where Lastname = ' " '& Text1.Text & " ' "
Adodc1.Refresh

If Adodc1.Recordset.RecordCount = 0 Then
'Timer1.Enabled = True
MsgBox "type the lastname to search wala"
End If

End Sub


Private Sub cmdDelete_Click()

Prompt$ = "Do you really want to delete?"
reply = MsgBox(Prompt$, vbOKCancel, "Delete Record")

If reply = vbOK Then
    Adodc1.Recordset.Delete
    Adodc1.Recordset.MoveNext
End If

End Sub

sample vb color


Private Sub Stop_Click()
Shape1.BackStyle = 1
Shape1.BackColor = &HFF&
Label1.Caption = "Please Stop"
End Sub

Private Sub Go_Click()
Shape1.BackStyle = 1
Shape1.BackColor = &HFF00&
Label1.Caption = "you can go now..."
End Sub

Private Sub End_Click()
MsgBox ("This will end the sytem")
End Sub

Thursday, August 20, 2009

How to plan and create vb6 projects

The three steps for planning and creating Visual Basic projects and what happens in each step.
Planning
1.When you plan the user interface, you draw a sketch of the screens the user will see when running your project. On your sketch, show the forms and all of the controls that you plan to use. Indicate the names that you plan to give the form and each of the objects on the form.
2. For each of the objects, write down the properties that you plan to set changed for each project during the design of the form.
3.This is where you plan the procedures that will execute when your project runs. You will determine which events require action to be taken, and plan, step-by-step, what those actions should be.
Programming
After you have completed the planning steps and have agreement from your user, you are ready to begin the actual construction of the project. You will use the same three step process that you used for planning.
1.Define the user interface. When you define the user interface, you create the forms and controls that you designed in the planning stage. Think of this step as all of the objects you will use in your project.
2.Set the properties. When you set the properties of the objects, you give each object a name and define such attributes as the contents of a label, the size of the text, and the words that appear on top of a command button and in the form’s title bar. You might think of this step as describing each of your objects.
3.Write the Basic code. This is where you write the procedures that will execute when your project runs. You will use Basic programming statements (called Basic code) to carry out the actions needed by your program. You will be surprised and pleased by how few statements you need to create a powerful Windows program. You can think of this third step as defining the of your program

how to add and delete record in Visual Basic 6.0

guys, here are the simple code in vb6 on how to add,delete a record
1. for Add --> adodc1.recordset.addnew
2. for Delete --> adodc1.recordset.delete
note: be sure that you add adodc component.