name is not declare?

mshahid

Active member
Joined
Aug 23, 2012
Messages
29
Programming Experience
Beginner
I am new in vb i want to design a function that returns a custom data types. for this purpose structure is located in the code file in which i declare
Class
Form

Private Customers(7) As Customer
Private Cust As Customer
Private CurrentIndex As Integer
End
Class

but i got the error message



name currentindex is not declare and name customers is not declare.

i am attacing word file .can anyone help me.


 

Attachments

  • attach.txt
    1.5 KB · Views: 16
Well, first there's no need to add classes here. I've moved everything into Form1, corrected silly mistakes like spelling and failure to include spaces, added a property to the structure to account for a value that you never defined, and placed a dangling section inside an appropriate sub. I suggest that you make a detailed comparison of my version and your original. I haven't run any operational tests, merely tidied up the code so that it at least has the potential to run.

Public Class Form1 
    Structure Customer
        Dim Name As String
        Dim Company As String
        Dim Address As String
        Dim city As String
        Dim Country As String
        Dim CustomerSince As Date
        Dim Balance As Decimal


    End Structure


    Private Customers(7) As Customer
    Private Cust As Customer
    Private CurrentIndex As Integer








    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CurrentIndex = CountCustomers() Then CurrentIndex = 0
        Dim aCustomer As Customer
        aCustomer = GetCustomer(currentIndex)
        ShowCustomer(CurrentIndex)
        CurrentIndex = CurrentIndex + 1
    End Sub


    Function CountCustomers() As Integer
        Return (Customers.Length)
    End Function


    Function GetCustomer(ByVal idx As Integer) As Customer
        Return (Customers(idx))
    End Function


    Sub ShowCustomer(ByVal idx As Integer)
        Dim aCustomer As Customer
        lblcompany.Text = aCustomer.Company
        lblsince.Text = aCustomer.CustomerSince
        lblAddress.Text = aCustomer.Address
        lblCity.Text = aCustomer.city
        lblcountry.Text = aCustomer.Country
        lblbalance.Text = aCustomer.Balance
    End Sub


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Cust.Name = "Ahmed Ali"
        Cust.Address = "A 9393 Karachi"
        Cust.city = "Karachi"
        Cust.Country = "Pakistan"
        Cust.CustomerSince = #3/23/1990#
        Cust.Balance = 999
        Customers(1) = Cust
    End Sub
End Class
 
Back
Top