An array can be converted into a binary tree
An array can be converted into a binary tree
1) Parent : Parent of a node at index lies at (n-1)/2 except the root node.
Quadratic equation is a fairly straight forward high school mathematics problem. The
quadratic equation solver was programmed to determine the number of roots the
equation has as well as to compute the roots. It uses the determinant b2 -4ac to solve
the problems. If b2 -4ac>0, then it has two roots and if b2-4ac=0, then it has one root,
else it has no root. To obtain the roots, the program uses the standard quadratic
formula :
The Code
det = (b ^ 2) - (4 * a * c)
If det > 0 Then
Lbl_numroot.Caption = 2
root1 = (-b + Sqr(det)) / (2 * a)
root2 = (-b - Sqr(det)) / (2 * a)
Answers.Caption = "The roots are "
Lbl_and.Visible = True
txt_root1.Visible = True
txt_root2.Visible = True
txt_root1.Text = Round(root1, 4)
txt_root2.Text = Round(root2, 4)
In Visual Basic 6, there are a number of built-in database management tools which we
can use to manage the data.To start building a good inventory system, we need to have
a good planning. First of all, you have to sit down with your client to get detail information
about his or her businesses and establish the kind of system he or she wants. For
example, you need to know what types of goods they are dealing with, the turn-over
volumes, cost prices, selling prices and more. Besides that, you need to know what kind
of documents the system needs to deal with like invoices, delivery orders and more.
After getting all the necessary information from your client, you can then start to build a
database. Based on the number and types of products, you need to decide what are the
variables or fields needed to be included in the database’s tables.
The figure below shows the inventory management system developed by us using
Visual Basic 6.
We shall use a hypothetical case to illustrate how to build an inventory system as shown
above. Let’s say our client is dealing with electrical goods. To design the database
tables, we need to determine how many tables are needed. In order to keep things
simple, we shall limit to two tables in our example. The first table shall be used to store
the data of the inventory or stock in hand. The second table shall be used to record
stocks coming in and stocks going out.
The first table shall comprise the following fields:
Category
Brand
Item Description
Model Number
Stock
Unit Cost
Total Cost
Date
Category
Brand
Item Description
Model Number
Stock In
Stock Out
Unit Cost
Total Cost
In our example, we named the first table Inventory and the second table Stock .After
designing the tables, we can then proceed to create a database that comprises the two
tables. We can either use Microsoft Access to create the database or we can use the
built-in Visual Data Manager in Visual Basic 6. Visual Data Manager can be used to
create tables, add new data as well as edit data. Besides that, it can be used to modify
table structure. To learn how to create database using Visual Data Manager, follow the
link below:
http://www.vbtutor.net/index.php/creating-database-using-visual-data-manager/
The next step is to insert some relevant controls into the form for displaying and
manipulating the data of the database. The controls to be inserted are ADO controls,
DataGrid controls, FlexGrid control and various command buttons. DataGrid controls
and FlexGrid controls are used to display and store the data from the database tables.
On the other hand, ADO is used to manipulate the database such as connecting the
DataGrid and FleGrid to the database.
. As ADO is ActiveX-based, it can work in different platforms (different computer
systems) and different programming languages. Besides, it can access many different
kinds of data such as data displayed in the Internet browsers, email text and even
graphics other than the usual relational and non relational database information.
To be able to use ADO data control, you need to insert it into the toolbox. To do this,
simply press Ctrl+T to open the components dialog box and select Microsoft ActiveX
Data Control 6. After this, you can proceed to build your ADO-based VB database
applications.
In our example, we insert two ADO controls and name them AdoInventory and AdoStock
respectively. The first is to deal with data in the Inventory table and the second is to deal
with data in the Stock table. We also insert two DataGrid controls and named them
DataInventory and DataStock respectively. They are use to display the data to the user.
Besides, we insert one FlexiGrid control to store the data and also to print out the data
by connecting it to MS Excel spreadsheet.
After inserting the necessary controls, it is time to write code to coordinate the controls
and to manipulate the data. The first most important code for our program is to connect
the ADO controls to the database when the form is loaded. The code is as shown below:
The next code is to let user enter data into the DataInventory table and double click to
update the data as well as to calculate the total cost. It also add brands and categories
into the brand combo box and the category combo box respectively .The code is as
follows:
AdoInventory.Recordset.Fields("TCost") = ""
End If
'To load all brands into comboBrand
'To load all Categories into comboCategory
Do Until AdoInventory.Recordset.EOF
ReDim B(i), C(j) As String
B(i) = AdoInventory.Recordset.Fields("Brand")
C(j) = AdoInventory.Recordset.Fields("Category")
ComboBrand.AddItem B(i)
ComboCategory.AddItem C(j)
AdoInventory.Recordset.MoveNext
Loop
AdoInventory.Recordset.MoveFirst
End Sub
We also need to write the code to search for the items once they are entered into the
inventory table. The code is as follows:
If ComboBrand.Text <> "All Brands" And ComboCategory.Text <> "All Categories" Then
End If
AdoInventory.Refresh
Next, we write code to entering new item in DataStock table. The code is as follows:
*Please note that AddNew is to allow adding new data and Update is to save data.
Inventory mgt system Code
hex_val = AdoStock.Recordset.Fields("TCost")
trueVal = CInt("&H" & hex_val) 'To convert hexadecimal to decimal value
Text1.Text = Str(trueVal)
End Sub
AdoStock.Recordset.Fields("TCost") = Str(Val(AdoStock.Recordset.Fields("Out")) *
Val(CostPU))
AdoInventory.Recordset.Update
AdoStock.Recordset.Update
End Sub
Text1.Text = Str(mysum)
'To add last line to Flexigrid table that shows total cost
MSFlexGrid1.AddItem "" & vbTab & "" & vbTab & "" & vbTab & "" & vbTab & "" _
& vbTab & "" & vbTab & "" & vbTab & "" & vbTab & "Total Cost" & vbTab & Str(mysum)
'This Adds a new workbook, you could open the workbook from file also
With ObjExcel.Application.ActiveSheet
End With
End Sub
End
End Sub
Dim StockValue
AdoStock.Recordset.Fields("In") = InputBox("Enter Stock In")
StockValue = Val(AdoStock.Recordset.Fields("In")) +
Val(AdoInventory.Recordset.Fields("Stock"))
AdoInventory.Recordset.Fields("Stock") = Str(StockValue)
AdoInventory.Recordset.Update
AdoStock.Recordset.Update
End Sub
End If
End Sub
StockValue = Val(AdoInventory.Recordset.Fields("Stock")) -
Val(AdoStock.Recordset.Fields("Out"))
AdoInventory.Recordset.Fields("Stock") = Str(StockValue)
AdoInventory.Recordset.Update
AdoStock.Recordset.Update
End Sub
If ComboBrand.Text <> "All Brands" And ComboCategory.Text <> "All Categories" Then
End If
AdoInventory.Refresh
'Formatting DataInventory (DataGrid)
With DataInventory
.Columns(0).Width = 2000 'Setting width for first column
.Columns(1).Width = 1500
.Columns(2).Width = 2500
.Columns(3).Width = 2000
.Columns(4).Width = 1200
.Columns(5).Width = 1100
.Columns(5).Caption = "Unit Cost" 'Set caption of column 8
.Columns(6).Width = 1200
.Columns(6).Caption = "Total Cost"
End With
End Sub
AdoInventory.Recordset.Update
End Sub
AdoStock.Recordset.Delete
Else
MsgBox ("No Item to Delete")
End If
End Sub
End Sub
ComboCategory.RemoveItem j + i
End If
Next
i=i+1
Loop
End Sub
nrow = MSFlexiGrid1.Rows
For r = 0 To nrow - 1
mysum = mysum + Val(MSFlexiGrid1.TextMatrix(nrow, 9))
Next
End Sub
AdoInventory.Recordset.Fields("TCost") = ""
End If
End Sub
AdoInventory.Recordset.Fields("TCost") = ""
End If
'To load all brands into comboBrand
B(i) = AdoInventory.Recordset.Fields("Brand")
C(j) = AdoInventory.Recordset.Fields("Category")
ComboBrand.AddItem B(i)
ComboCategory.AddItem C(j)
AdoInventory.Recordset.MoveNext
Loop
AdoInventory.Recordset.MoveFirst
End Sub
End If
End Sub
linetext = DateStr & vbTab & CategoryStr & vbTab & BrandStr & vbTab & _
MoNumStr & vbTab & ItemStr & vbTab & InStrng & vbTab & OutStr & vbTab &
BranchStr & vbTab & _
CostStr & vbTab & TCostStr & vbTab & AllCostStr
MSFlexGrid1.ColAlignment(ColAlign) = flexAlignLeftTop
Next
MSFlexGrid1.AddItem linetext
AdoStock.Recordset.Update
End Sub
Do Until AdoInventory.Recordset.EOF
ReDim B(i), C(j) As String
B(i) = AdoInventory.Recordset.Fields("Brand")
C(j) = AdoInventory.Recordset.Fields("Category")
ComboBrand.AddItem B(i)
ComboCategory.AddItem C(j)
AdoInventory.Recordset.MoveNext
Loop
AdoInventory.Recordset.MoveFirst
End With
End Sub
ComboBrand.RemoveItem j + i
End If
Next
i=i+1
Loop
End Sub
Dim i, j As Integer
Do Until i = ComboCategory.ListCount
For j = 1 To ComboCategory.ListCount - i - 1
If ComboCategory.List(j + i) = ComboCategory.List(i) Then
End If
Next
i=i+1
Loop
End Sub
End Sub