Wednesday, 7 March 2012

A Module Object for Automated Customer ID Generation

The Customer.bas module has a procedure named customer_ID_auto to generate automated customer ID numbers to be loaded into the customer form on form load. The call Customer_ID_auto() statement is used to invoke this method: Private Sub Form_Load()
Call customer_ID_auto
Text1.Text = str
End Sub
in the Form_Load sub procedure. The str string is public and hence the value is populated in the form text field on form load.
The Customer.bas module:
Option Explicit
Public str As String
Sub customer_ID_auto()
Dim rvalue As Integer
Dim upperbound As Integer
Dim lowerbound As Integer
Dim i As Integer
' Initialize the random-number generator.
Randomize
' Generate random value between 1 and 6.
upperbound = 65
lowerbound = 90
'rvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
str = "CMP"
For i = 1 To 8
rvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))
str = str + Chr(rvalue)
Next i
'Form6.List1.AddItem str
End Sub

No comments:

Post a Comment