Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

An array can be converted into a binary tree

The document provides instructions on converting an array into a binary tree and details on a quadratic equation solver programmed in Visual Basic. It also discusses building an inventory management system using Visual Basic 6, including database design, control insertion, and coding for data manipulation. The document includes code snippets for various functionalities such as calculating roots of a quadratic equation and managing inventory data.

Uploaded by

paulas2014
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

An array can be converted into a binary tree

The document provides instructions on converting an array into a binary tree and details on a quadratic equation solver programmed in Visual Basic. It also discusses building an inventory management system using Visual Basic 6, including database design, control insertion, and coding for data manipulation. The document includes code snippets for various functionalities such as calculating roots of a quadratic equation and managing inventory data.

Uploaded by

paulas2014
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

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.

2) Left Child : Left child of a node at index n lies at (2*n+1).

3) Right Child : Right child of a node at index n lies at (2*n+2).

4) Left Sibling : left Sibling of a node at index n lies at (n-1).

5) Right Sibling : Right sibling of a node at index n lies at (n+1).

C program for converting a list of array into a binary tree

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

Private Sub Form_Load()


Dim a, b, c, det As Integer
Dim root1, root2 As Single
Dim numroot As Integer
End Sub

Private Sub new_Click()


' To set all values to zero
Coeff_a.Text = ""
Coeff_b.Text = ""
Coeff_c.Text = ""
Answers.Caption = ""
txt_root1.Visible = False
txt_root2.Visible = False
txt_root1.Text = ""
txt_root2.Text = ""
Lbl_and.Visible = False
Lbl_numroot.Caption = ""
End Sub

Private Sub Solve_Click()


a = Val(Coeff_a.Text)
b = Val(Coeff_b.Text)
c = Val(Coeff_c.Text)

'To compute the value of the determinant

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)

ElseIf det = 0 Then


root1 = (-b) / 2 * a
Lbl_numroot.Caption = 1
Answers.Caption = "The root is "
txt_root1.Visible = True
txt_root1.Text = root1
Else
Lbl_numroot.Caption = 0
Answers.Caption = "There is no root "
End If
End Sub
All businesses involve inventory and need to manage it efficiently to ensure smooth
running of the business activities and profitability. To manage inventory efficiently,
business owners need to develop a good inventory management system . Building a
sound inventory management system usually incur high cost. Fortunately, we can use
Visual Basic 6 to build an inventory management system which does not require big
capital, you can do it at home.

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

The second table shall comprise the following fields:

 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/

Step 2 : Inserting controls into Form

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.

Step 3 : Writing the Code

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:

Private Sub Form_Load()


'To connect AdoInventory to MS Access database inventory_br.mdb
AdoInventory.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\
Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\
inventory_br.mdb;Persist Security Info=False"
AdoInventory.RecordSource = "SELECT * FROM Inventory"
AdoInventory.Refresh
Set DataInventory.DataSource = AdoInventory

'To connect AdoStock to MS Access database inventory_br.mdb


AdoStock.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\
Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\
inventory_br.mdb;Persist Security Info=False"
AdoStock.RecordSource = "SELECT * FROM Stock"
AdoStock.Refresh
Set DataStock.DataSource = AdoStock
Notice that we use SQL syntax SELECT * FROM to select all the data from the
Inventory table and the stock table. SQL is a powerful language that is used to
manipulate databases.

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:

Private Sub DataInventory_DblClick()


If AdoInventory.Recordset.Fields("CPU") <> "" Then

Dim TotalCost As Integer


TotalCost = Val(AdoInventory.Recordset.Fields("CPU")) *
Val(AdoInventory.Recordset.Fields("Stock"))
AdoInventory.Recordset.Fields("TCost") = Str(TotalCost)
Else

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:

'Search for items using SQL query

Dim SearchString1, SearchString2 As String


SearchString1 = ComboBrand.Text
SearchString2 = ComboCategory.Text

If ComboBrand.Text <> "All Brands" And ComboCategory.Text <> "All Categories" Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" &


SearchString1 & "' and Category='" & SearchString2 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text <> "All Categories"


Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Category='" &


SearchString2 & "'"

ElseIf ComboBrand.Text <> "All Brands" And ComboCategory.Text = "All Categories"


Then
AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" &
SearchString1 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text = "All Categories"


Then

AdoInventory.RecordSource = "SELECT * FROM Inventory"

End If
AdoInventory.Refresh

Next, we write code to entering new item in DataStock table. The code is as follows:

'To add items to Ado Stock


AdoStock.Recordset.AddNew
AdoStock.Recordset.Fields("Date") = Format(Date, "dd/mm/yyyy")
AdoStock.Recordset.Fields("Category") = AdoInventory.Recordset.Fields("Category")
AdoStock.Recordset.Fields("Brand") = AdoInventory.Recordset.Fields("Brand")
AdoStock.Recordset.Fields("Item Description") = AdoInventory.Recordset.Fields("Item
Description")
AdoStock.Recordset.Fields("Model Number") = AdoInventory.Recordset.Fields("Model
Number")
AdoStock.Recordset.Fields("CPU") = AdoInventory.Recordset.Fields("CPU")
AdoStock.Recordset.Update

*Please note that AddNew is to allow adding new data and Update is to save data.
Inventory mgt system Code

'To set border styles for Excel


Private Enum ExlBorderAround
xlHairline = 1
xlMedium = -4138
xlThick = 4
xlThin = 2
xlColorIndexAutomatic = -4105
End Enum
Private Sub CmdEnd_Click()
End
End Sub

Private Sub CmdConvert_Click()


Dim hex_val As String
Dim trueVal As Double

hex_val = AdoStock.Recordset.Fields("TCost")
trueVal = CInt("&H" & hex_val) 'To convert hexadecimal to decimal value
Text1.Text = Str(trueVal)
End Sub

Private Sub CmdCpu_Click()

Dim CostPU As String

CostPU = InputBox("Enter Unit Cost")


AdoStock.Recordset.Fields("CPU") = Str(Val(CostPU))

AdoStock.Recordset.Fields("TCost") = Str(Val(AdoStock.Recordset.Fields("Out")) *
Val(CostPU))

AdoInventory.Recordset.Update
AdoStock.Recordset.Update

End Sub

Private Sub CmdDo_Click()


'To sum up all the values in column 9
Dim mysum As Double
Dim nrow As Integer
Dim r As Integer
nrow = MSFlexGrid1.Rows 'To count all the rows in MSFlexiGrid1
For r = 0 To nrow - 1
mysum = mysum + Val(MSFlexGrid1.TextMatrix(r, 9))
Next

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)

'Printing Delivery order Via Excel

Dim ObjExcel As Object


Dim wbk As Object
Dim wst As Object
Dim i%
Dim myrow, mycol, noofusedrows As Integer

Set ObjExcel = CreateObject("Excel.Application")


Set wbk = ObjExcel.Workbooks.Add
Set wst = wbk.ActiveSheet

'This Adds a new workbook, you could open the workbook from file also

Clipboard.Clear 'Clear the Clipboard


With MSFlexGrid1
'Select Full Contents (You could also select partial content)
.Col = 0 'From first column
.Row = 0 'From first Row (header)
.ColSel = .Cols - 1 'Select all columns
.RowSel = .Rows - 1 'Select all rows
Clipboard.SetText .Clip 'Send to Clipboard
End With

With ObjExcel.Application.ActiveSheet

.Range("A1").EntireColumn.Columnwidth = 8 'Set Columnwidth for column1=10


.Range("B1").EntireColumn.Columnwidth = 10
.Range("C1").EntireColumn.Columnwidth = 8
.Range("D1").EntireColumn.Columnwidth = 10
.Range("E1").EntireColumn.Columnwidth = 12
.Range("F1").EntireColumn.Columnwidth = 4
.Range("G1").EntireColumn.Columnwidth = 4
.Range("H1").EntireColumn.Columnwidth = 6
.Range("I1").EntireColumn.Columnwidth = 10
.Range("J1").EntireColumn.Columnwidth = 6
.Range("F1").EntireColumn.HorizontalAlignment = 2
.Range("G1").EntireColumn.HorizontalAlignment = 2

.Range("A1").Select 'Select Cell A1 (will paste from here, to different cells)


.Paste 'Paste clipboard contents

noofusedrows = wst.UsedRange.Rows.Count 'To get number of used rows

'To set borders for the selected cells


For myrow = 2 To noofusedrows
For mycol = 1 To 10

wst.Cells(myrow, mycol).BorderAround , ExlBorderAround.xlThin,


ExlBorderAround.xlColorIndexAutomatic, vbBlack
Next
Next
'To set borders for the last row
wst.Range(.Cells(noofusedrows + 1, 1), .Cells(noofusedrows + 1, 10)).BorderAround ,
ExlBorderAround.xlThin, ExlBorderAround.xlColorIndexAutomatic, vbBlack

.PrintOut 'To print out the selection

End With

End Sub

Private Sub CmdExit_Click()

End

End Sub

Private Sub CmdIn_Click()


Dim hex_val As String

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

Private Sub cmdNew_Click()


'Add new item to stock
Dim MsgInstr As Integer
MsgInstr = MsgBox("Have you selected one item from Stock List? If YES, Click OK to
Proceed", vbYesNoCancel + vbQuestion, "Select Item")
If MsgInstr = 6 Then
Timer4.Enabled = True
Else
Timer4.Enabled = False

End If

End Sub

Private Sub Cmdout_Click()


'Enter total item out
Dim StockValue

AdoStock.Recordset.Fields("Out") = InputBox("Enter Stock Out")

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

Private Sub CmdSearch_Click()

'Search for items using SQL query


Dim SearchString1, SearchString2 As String
SearchString1 = ComboBrand.Text
SearchString2 = ComboCategory.Text

If ComboBrand.Text <> "All Brands" And ComboCategory.Text <> "All Categories" Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" &


SearchString1 & "' and Category='" & SearchString2 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text <> "All Categories"


Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Category='" &


SearchString2 & "'"

ElseIf ComboBrand.Text <> "All Brands" And ComboCategory.Text = "All Categories"


Then
AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" &
SearchString1 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text = "All Categories"


Then

AdoInventory.RecordSource = "SELECT * FROM Inventory"

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

Private Sub CmdView_Click()


'View all items
AdoInventory.RecordSource = "SELECT * FROM Inventory"
AdoInventory.Refresh
End Sub

Private Sub Command2_Click()

AdoInventory.Recordset.Update

End Sub

Private Sub Command3_Click()


AdoInventory.Recordset.Delete
End Sub

Private Sub Command4_Click()


If AdoStock.Recordset.BOF = False Then

AdoStock.Recordset.Delete

Else
MsgBox ("No Item to Delete")
End If

End Sub

Private Sub Command5_Click()


AdoInventory.Refresh.Refresh
End Sub

Private Sub ComboBrand_DropDown()


Timer1.Enabled = False

End Sub

Private Sub ComboCategory_DropDown()


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

ComboCategory.RemoveItem j + i

End If
Next
i=i+1

Loop
End Sub

Private Sub Command1_Click()


Dim r, nrow As Integer
Dim mysum As Double

nrow = MSFlexiGrid1.Rows
For r = 0 To nrow - 1
mysum = mysum + Val(MSFlexiGrid1.TextMatrix(nrow, 9))
Next

End Sub

Private Sub DataInventory_AfterUpdate()


If AdoInventory.Recordset.Fields("CPU") <> "" Then

Dim TotalCost As Integer


TotalCost = Val(AdoInventory.Recordset.Fields("CPU")) *
Val(AdoInventory.Recordset.Fields("Stock"))
AdoInventory.Recordset.Fields("TCost") = Str(TotalCost)
Else

AdoInventory.Recordset.Fields("TCost") = ""
End If

End Sub

Private Sub DataInventory_DblClick()


If AdoInventory.Recordset.Fields("CPU") <> "" Then

Dim TotalCost As Integer


TotalCost = Val(AdoInventory.Recordset.Fields("CPU")) *
Val(AdoInventory.Recordset.Fields("Stock"))
AdoInventory.Recordset.Fields("TCost") = Str(TotalCost)
Else

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

Private Sub DataStock_Click()


Dim TotalCost As Integer
If AdoStock.Recordset.Fields("Out") <> "" Then
TotalCost = Val(AdoStock.Recordset.Fields("CPU")) *
Val(AdoStock.Recordset.Fields("Out"))
AdoStock.Recordset.Fields("TCost") = Str(TotalCost)

End If
End Sub

Private Sub DataStock_DblClick()


'To populate the MSFlexiGrid with data from Adostock in different columns
'whenever the user clicks the row in dataStock
MSFlexGrid1.Visible = True

Dim DateStr, CategoryStr, BrandStr, MoNumStr, ItemStr, OutStr, InString, BranchStr,


CostStr, TCostStr, AllCostStr, linetext As String
Dim AllCost As Double

DateStr = AdoStock.Recordset.Fields("Date") 'To assign the value in Date field to


DateStr
CategoryStr = AdoStock.Recordset.Fields("Category")
BrandStr = AdoStock.Recordset.Fields("Brand")
MoNumStr = AdoStock.Recordset.Fields("Model Number")
ItemStr = AdoStock.Recordset.Fields("Item Description")
OutStr = AdoStock.Recordset.Fields("Out")
InStrng = AdoStock.Recordset.Fields("In")
BranchStr = AdoStock.Recordset.Fields("Branch")
CostStr = AdoStock.Recordset.Fields("CPU")
TCostStr = AdoStock.Recordset.Fields("TCost")
AllCost = AllCost + Val(TCostStr)
AllCostStr = Str(AllCost)

linetext = DateStr & vbTab & CategoryStr & vbTab & BrandStr & vbTab & _
MoNumStr & vbTab & ItemStr & vbTab & InStrng & vbTab & OutStr & vbTab &
BranchStr & vbTab & _
CostStr & vbTab & TCostStr & vbTab & AllCostStr

MSFlexGrid1.ColWidth(0) = 1200 'sets the first column width to 1000.


MSFlexGrid1.ColWidth(1) = 1500 'sets the Second column width to 2500.
MSFlexGrid1.ColWidth(2) = 1500 'sets the Third column width to 1500.
MSFlexGrid1.ColWidth(3) = 1600 'sets the Fourth column width to 1600.
MSFlexGrid1.ColWidth(4) = 2000 'sets the Fifth column width to 3000.
MSFlexGrid1.ColWidth(5) = 500 'sets the Sixth column width to 2000.
MSFlexGrid1.ColWidth(6) = 500 'sets the Seven column width to 500.
MSFlexGrid1.ColWidth(7) = 600 'sets the Seven column width to 1000.
MSFlexGrid1.ColWidth(8) = 800 'sets the Seven column width to 1000.
MSFlexGrid1.ColWidth(9) = 600 'sets the Seven column width to 1000.

'To set columns alignments


Dim ColAlign As Integer
For ColAlign = 0 To 9

MSFlexGrid1.ColAlignment(ColAlign) = flexAlignLeftTop

Next

MSFlexGrid1.AddItem linetext

AdoStock.Recordset.Update
End Sub

Private Sub Form_Load()

'To connect to MS Access database inventory_br.mdb


AdoInventory.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\
Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\
inventory_br.mdb;Persist Security Info=False"
AdoInventory.RecordSource = "SELECT * FROM Inventory"
AdoInventory.Refresh
Set DataInventory.DataSource = AdoInventory

'To connect to MS Access database inventory_br.mdb


AdoStock.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\
Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\
inventory_br.mdb;Persist Security Info=False"
AdoStock.RecordSource = "SELECT * FROM Stock"
AdoStock.Refresh
Set DataStock.DataSource = AdoStock

'To set the alignment of the windows to centre of screen


Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2

'To set the alignment of the datagrid to centre of Form

DataInventory.Left = (Form1.Width - DataInventory.Width) \ 2


DataStock.Left = (Form1.Width - DataStock.Width) \ 2

'To load all brands into comboBrand


ComboBrand.Text = "All Brands"
ComboBrand.AddItem "All Brands"

'To load all Categories into comboCategory


ComboCategory.Text = "All Categories"
ComboCategory.AddItem "All Categories"

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

'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

'Formatting DataStock (DataGrid)


With DataStock

.Columns(0).Width = 1500 'Setting width for first column


.Columns(1).Width = 2000
.Columns(2).Width = 1500
.Columns(3).Width = 2500
.Columns(4).Width = 1800
.Columns(5).Width = 600
.Columns(6).Width = 600
.Columns(7).Width = 1100
.Columns(8).Width = 1100
.Columns(8).Caption = "Unit Cost" 'Set caption of column 8
.Columns(9).Width = 1200
.Columns(9).Caption = "Total Cost"
End With

End Sub

'Add item brand to combo box

Private Sub Timer1_Timer()


Dim i, j As Integer
Do Until i = ComboBrand.ListCount
For j = 1 To ComboBrand.ListCount - i - 1
If ComboBrand.List(j + i) = ComboBrand.List(i) Then

ComboBrand.RemoveItem j + i

End If
Next

i=i+1
Loop

End Sub

Private Sub Timer2_Timer()

'Add category to combo box

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

ComboCategory.RemoveItem j + i ' To remove duplicated items

End If
Next

i=i+1

Loop
End Sub

Private Sub Timer3_Timer()


Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub

Private Sub Timer4_Timer()


'To add items to Ado Stock
AdoStock.Recordset.AddNew
AdoStock.Recordset.Fields("Date") = Format(Date, "dd/mm/yyyy")
AdoStock.Recordset.Fields("Category") = AdoInventory.Recordset.Fields("Category")
AdoStock.Recordset.Fields("Brand") = AdoInventory.Recordset.Fields("Brand")
AdoStock.Recordset.Fields("Item Description") = AdoInventory.Recordset.Fields("Item
Description")
AdoStock.Recordset.Fields("Model Number") = AdoInventory.Recordset.Fields("Model
Number")
AdoStock.Recordset.Fields("CPU") = AdoInventory.Recordset.Fields("CPU")
AdoStock.Recordset.Update
Timer4.Enabled = False

End Sub

You might also like