Creating an array of a Data Type
In module1, i created a data type like this.
Option Explicit
Type Sales
Name As String
Apples As Currency
Oranges As Currency
Grapes As Currency
'ect.....
End Type
In Form1, i used this code to access the data
Dim FrstCustomer As Sales
'Here is the question:
'How can i make frstCustomer an array
'like SecCustomer, Ect.....
Private Sub Command1_Click()
FrstCustomer.Name = Text1.Text
FrstCustomer.Apples = Text2.Text
FrstCustomer.Oranges = Text3.Text
FrstCustomer.Grapes = Text4.Text
If Text1.Text = "Enter customer name" Then
MsgBox ("Please enter a customer name")
Exit Sub
End If
MsgBox (FrstCustomer.Name & " " & _
FrstCustomer.Apples & " " _
& FrstCustomer.Oranges & " " & _
FrstCustomer.Grapes)
End Sub
Private Sub VScroll1_Change()
'I wish to use the scroll bar to view a
'different record
Label4.Caption = VScroll1.Value
'I dont know the code to go to the next record
End Sub
If anyone would like to create this app.
Place these controlls on form1 and paste the code below in the form1.load event.
There is no need to size and place the controls, leave all the properties to default.
The code will set all the properties at run time.
On Form1 place these controls:
Command1
label1
label2
label3
label4
label5
Text1
Text2
Text3
Text4
Vscroll1
In the form1.Load event, place this code
Private Sub Form_Load()
Form1.Height = 4700
Form1.Width = 7100
Command1.Caption = "Record Customer Sales"
Command1.Height = 375
Command1.Left = 360
Command1.Top = 2160
Command1.Width = 2175
Label1.Caption = "How Many Apples?"
Label1.Height = 255
Label1.Left = 120
Label1.Top = 860
Label1.Width = 2055
Label2.Caption = "How many Orenges?"
Label2.Width = 2055
Label2.Height = 255
Label2.Left = 120
Label2.Top = 1200
Label3.Caption = "How many Grapes?"
Label3.Width = 2055
Label3.Height = 255
Label3.Left = 120
Label3.Top = 1560
Label4.Caption = 0
Label4.Width = 3135
Label4.Height = 255
Label4.Left = 2880
Label4.Top = 480
Label5.Caption = 0
Label5.Width = 6615
Label5.Height = 255
Label5.Left = 240
Label5.Top = 2880
Text1.Text = "Enter customer name"
Text1.Height = 375
Text1.Left = 120
Text1.Top = 240
Text1.Width = 2175
Text2.Text = 0
Text2.Height = 315
Text2.Left = 1680
Text2.Top = 720
Text2.Width = 615
Text3.Text = 0
Text3.Height = 315
Text3.Left = 1680
Text3.Top = 1080
Text3.Width = 615
Text4.Text = 0
Text4.Height = 315
Text4.Left = 1680
Text4.Top = 1440
Text4.Width = 615
VScroll1.Min = 0
VScroll1.Max = 10
VScroll1.Height = 735
VScroll1.Left = 2520
VScroll1.Top = 240
VScroll1.Width = 255
End Sub
Re: Creating an array of a Data Type
Dim Customer(10) As Sales 'This is array for 10 records
Use:
Customer(0).Name = Text1.Text
Customer(0).Apples = Text2.Text
Customer(0).Oranges = Text3.Text
Customer(0).Grapes = Text4.Text
This is code for 1 customer, for 5 customer
Customer(4).Name = Text1.Text
Customer(4).Apples = Text2.Text
Customer(4).Oranges = Text3.Text
Customer(4).Grapes = Text4.Text