|
-
May 5th, 2002, 11:51 PM
#1
Thread Starter
Lively Member
declare a varible so I can use it anywhere??
I have a question. I have a program that uses a common dialogue box to import a .dat file. the .dat file has lines of info like this for example:
"905","Car, Sedan",22897
"503","Yogurt, Plain",1.28
"601","Cola, 2 ltr",1.29
"602","Cola, diet 2 ltr",1.29
"603","Cola, 6 pack",1.85
I open the file like this:
ProdFileName = CDL1.FileName '** Remember product file name
Open ProdFileName For Input As #6 '** Open the product file
I = 1 '** Start with first product
Do Until EOF(6) '** Until the end of the file
Input #6, UPC(I), ProdDesc(I), ProdPrice(I) '** Read I-th product
I = I + 1 '** Anticipate next product
Loop
NumProducts = I - 1 '** Remember number of products read
Close #6
having CDL1 the name of the common dialogue box. Now when I want to call UPC(I), ProdDesc(I), or ProdPrice(I), I will have to call them in two different form. This means that I have to declare the varibles Globally. How exactly do I do this?? Do I have to use a modual? I tried this:
Global UPC(MaxProducts) As String '** Array for UPC codes
Global ProdDesc(MaxProducts) As String '** Product descriptions
Global ProdPrice(MaxProducts) As Currency '** Product prices
Global I As Integer '** Variable used to index these arrays
Global NumProducts As Integer '** Variable providing number of products read.
I put that into a modual, and I recieved an error when I was trying to open ProdFileName. I defined ProdFileName as Global in the modual as well.
'------Varibles to define the arrays------------
Global ProdFileName As String '** Variable providing name of product file.
What am I doing wrong?? Please help me. Thanks 
Brian
-
May 5th, 2002, 11:55 PM
#2
Hyperactive Member
Visual Baisc 6 (SP5)
Windows Xp
-
May 5th, 2002, 11:57 PM
#3
Thread Starter
Lively Member
runtime error '62'
input past end-of-file
the debugger stops here:
Input #6, UPC(I), ProdDesc(I), ProdPrice(I) '** Read I-th product
-
May 6th, 2002, 12:03 AM
#4
Hyperactive Member
This:
VB Code:
Do Until EOF(6) '** Until the end of the file
Should Be this:
Visual Baisc 6 (SP5)
Windows Xp
-
May 6th, 2002, 12:19 AM
#5
Thread Starter
Lively Member
nope. That wasn't the answer. Thanks though for your help. I am still searching... I think I declared my varibles wrong. if I have an array, and I want the program to read the array, but the varibles in the array defined globally, how would I do that? (I basically want to be able to use the varibles anywhere)
Brian
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 12:22 AM
#6
Thread Starter
Lively Member
arrg! this is bothering me..
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 12:27 AM
#7
Thread Starter
Lively Member
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 12:31 AM
#8
Hyperactive Member
Post your Project and The .dat File
Visual Baisc 6 (SP5)
Windows Xp
-
May 6th, 2002, 12:32 AM
#9
Thread Starter
Lively Member
You want me to just copy and paste the code?
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 12:32 AM
#10
Is there a carriage return or line feed at the end of the file? If there is, that might cause some problems.
-
May 6th, 2002, 12:36 AM
#11
Hyperactive Member
Ya unless you dont wan to past the code on here for some reason
Visual Baisc 6 (SP5)
Windows Xp
-
May 6th, 2002, 12:37 AM
#12
Frenzied Member
add a module
Public VARIABLE as String (or whatever)
then you can use VARIABLE wherever
-
May 6th, 2002, 12:40 AM
#13
Thread Starter
Lively Member
'**this is my module
Option Explicit
'** The following constant is the width of the receipt in characters.
'** Note, the receipt Text Box was widened and its point size decreased
'** to 10. If you change the width or point size of the receipt Text Box,
'** this constant must also be changed.
Const ReceiptWidth As Integer = 29
Const MaxProducts As Integer = 200 ' Maximum number of Products store can carry
Const MaxEmployee As Integer = 12 ' Maximum number of Employees in the employee file
Const MaxTrans As Double = 100000 ' Maximum number of Transactions that the store can do
Const TaxRate As Currency = 0.065 ' Sales tax rate
Global AmountTendered As Currency ' Amount of money offered by custmer to pay bill
Global SubTotal As Double ' Running subtotal of items purchased
Global SalesTax As Double ' Sales tax due on the order
Global AmountDue As Single ' Total amount to charge customer = SubTotal + SalesTax
'------Variables for the Products File---------
Global UPC(MaxProducts) As String '** Array for UPC codes
Global ProdDesc(MaxProducts) As String '** Product descriptions
Global ProdPrice(MaxProducts) As Currency '** Product prices
Global I As Integer '** Variable used to index these arrays
Global NumProducts As Integer '** Variable providing number of products read.
'------Variables for the Employee File---------
Global EmployeeNum(MaxEmployee) As String '** This is the Employee's Number
Global EmployeeName(MaxEmployee) As String '** This is the Employee's Name
Global EmployeePass(MaxEmployee) As String '** This is the Employee's Password
Global ManagerStatus(MaxEmployee) As Boolean '** This is to determine if the Employee has Manager Status/Rights
Global J As Integer '** Variable used to index these arrays
Global NumEmployee As Integer '** Variable providing number of Employees Logged in.
'------Varibles for the Transactions File-------
Global TransDate(MaxTrans) As Date '** This is the Date when the sale was made
Global TransEmpNum(MaxTrans) As String '** This is the Employee Number of the individual who was logged in
Global TransUPC(MaxTrans) As String '** This is the UPC of the product sold
Global TransPrice(MaxTrans) As Currency '** This is the price of the item sold
Global K As Integer '** Variable used to index these arrays
Global NumTrans As Integer '** Variable providing number of Transactions preformed.
'------Varibles to define the arrays------------
Global ProdFileName As String '** Variable providing name of product file.
Global EmpFileName As String '** Variable providing name of employee file.
Global TransFileName As String '** Variable providing name of trans file.
Function PL(A As String, I As Integer)
Dim Result As String
Result = A
Do Until Len(Result) >= I
Result = " " & Result
Loop
PL = Left(Result, I)
End Function
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 12:41 AM
#14
Thread Starter
Lively Member
and this is the form load code:
'** Procedure added to allow definition of the input file
'** and to read all data from it.
Private Sub Form_Load()
CDL1.DialogTitle = "Open the Product Data File" '** set title for the dialog box
CDL1.FileName = "C:\WINDOWS\Desktop\hw10\hw10\sample\products.dat" '** identifies file on my pc
CDL1.Flags = cdlOFNFileMustExist '** allow existing files only
CDL1.Filter = "All Data Files (*.dat)|*. dat|All Files (*.*)|*. *" '** set filter of files to display
CDL1.CancelError = True '** ShowOpen method returns error if Cancel clikced
On Error Resume Next '** Disable VB error trapping and handling
CDL1.ShowOpen '** Pop up ShowOPen dialog
If Err.Number = cdlCancel Then '** If Cancel Button Clicked
MsgBox "Cancel button clicked. Program ends." '** Inform user
End '** And, stop the program
Else
If Err.Number > 0 Then
'** All other error should be reported
'** to programmer for correction.
MsgBox ("Catastrophic Error. Please inform programmer. Program stops.")
End
End If
End If
Err.Clear '** Clear the error, if any.
On Error GoTo 0 '** Have VB handle error trapping.
CDL2.DialogTitle = "Open the Employee Data File" '** set title for the dialog box
CDL2.FileName = "employee.dat" '** identifies file on my pc
CDL2.Flags = cdlOFNFileMustExist '** allow existing files only
CDL2.Filter = "All Data Files (*.dat)|*. dat|All Files (*.*)|*. *" '** set filter of files to display
CDL2.CancelError = True '** ShowOpen method returns error if Cancel clikced
On Error Resume Next '** Disable VB error trapping and handling
CDL2.ShowOpen '** Pop up ShowOPen dialog
If Err.Number = cdlCancel Then '** If Cancel Button Clicked
MsgBox "Cancel button clicked. Program ends." '** Inform user
End '** And, stop the program
Else
If Err.Number > 0 Then
'** All other error should be reported
'** to programmer for correction.
MsgBox ("Catastrophic Error. Please inform programmer. Program stops.")
End
End If
End If
Err.Clear '** Clear the error, if any.
On Error GoTo 0 '** Have VB handle error trapping.
CDL3.DialogTitle = "Open the Transactions Data File" '** set title for the dialog box
CDL3.FileName = "trans.dat" '** identifies file on my pc
CDL3.Flags = cdlOFNFileMustExist '** allow existing files only
CDL3.Filter = "All Data Files (*.dat)|*. dat|All Files (*.*)|*. *" '** set filter of files to display
CDL3.CancelError = True '** ShowOpen method returns error if Cancel clikced
On Error Resume Next '** Disable VB error trapping and handling
CDL3.ShowOpen '** Pop up ShowOPen dialog
If Err.Number = cdlCancel Then '** If Cancel Button Clicked
MsgBox "Cancel button clicked. Program ends." '** Inform user
End '** And, stop the program
Else
If Err.Number > 0 Then
'** All other error should be reported
'** to programmer for correction.
MsgBox ("Catastrophic Error. Please inform programmer. Program stops.")
End
End If
End If
Err.Clear '** Clear the error, if any.
On Error GoTo 0 '** Have VB handle error trapping.
ProdFileName = CDL1.FileName '** Remember product file name
Open ProdFileName For Input As #6 '** Open the product file
I = 1 '** Start with first product
Do Until EOF(6) '** Until the end of the file
Input #6, UPC(I), ProdDesc(I), ProdPrice(I) '** Read I-th product
I = I + 1 '** Anticipate next product
Loop
NumProducts = I - 1 '** Remember number of products read
Close #6 '** Close the file
EmpFileName = CDL2.FileName '** Remember employee file name
Open EmpFileName For Input As #2 '** Open the employee file
J = 1 '** Start with first employee
Do Until EOF(2) '** Until the end of the file
Input #2, EmployeeNum(J), EmployeeName(J), EmployeePass(J), ManagerStatus(J) '** Read J-th product
J = J + 1 '** Anticipate next employee
Loop
NumEmployee = J - 1 '** Remember number of employees read
Close #2
TransFileName = CDL3.FileName '** Remember Transactions file name
Open TransFileName For Input As #3 '** Open the Transactions file
K = 1 '** Start with first Transaction
Do Until EOF(3) '** Until the end of the file
Input #3, TransDate(K), TransEmpNum(K), TransUPC(K), TransPrice(K) '** Read K-th product
K = K + 1 '** Anticipate next Transaction
Loop
NumTrans = K - 1 '** Remember number of Transactions read
Close #3
Me.Show '** Show the cash register form
cmdSignOn.SetFocus '** Set Focus to sign on button
End Sub
I couldn't paste the whole project. but that is where i get errors
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 01:00 AM
#15
Frenzied Member
thats very very hard to read..
post your code using
['vbcode]CODE IN HERE[/'vbcode]
without the '
-
May 6th, 2002, 01:03 AM
#16
Thread Starter
Lively Member
here is my module
['vbcode]
Option Explicit
'** The following constant is the width of the receipt in characters.
'** Note, the receipt Text Box was widened and its point size decreased
'** to 10. If you change the width or point size of the receipt Text Box,
'** this constant must also be changed.
Const ReceiptWidth As Integer = 29
Const MaxProducts As Integer = 200 ' Maximum number of Products store can carry
Const MaxEmployee As Integer = 12 ' Maximum number of Employees in the employee file
Const MaxTrans As Double = 100000 ' Maximum number of Transactions that the store can do
Const TaxRate As Currency = 0.065 ' Sales tax rate
Global AmountTendered As Currency ' Amount of money offered by custmer to pay bill
Global SubTotal As Double ' Running subtotal of items purchased
Global SalesTax As Double ' Sales tax due on the order
Global AmountDue As Single ' Total amount to charge customer = SubTotal + SalesTax
'------Variables for the Products File---------
Global UPC(MaxProducts) As String '** Array for UPC codes
Global ProdDesc(MaxProducts) As String '** Product descriptions
Global ProdPrice(MaxProducts) As Currency '** Product prices
Global I As Integer '** Variable used to index these arrays
Global NumProducts As Integer '** Variable providing number of products read.
'------Variables for the Employee File---------
Global EmployeeNum(MaxEmployee) As String '** This is the Employee's Number
Global EmployeeName(MaxEmployee) As String '** This is the Employee's Name
Global EmployeePass(MaxEmployee) As String '** This is the Employee's Password
Global ManagerStatus(MaxEmployee) As Boolean '** This is to determine if the Employee has Manager Status/Rights
Global J As Integer '** Variable used to index these arrays
Global NumEmployee As Integer '** Variable providing number of Employees Logged in.
'------Varibles for the Transactions File-------
Global TransDate(MaxTrans) As Date '** This is the Date when the sale was made
Global TransEmpNum(MaxTrans) As String '** This is the Employee Number of the individual who was logged in
Global TransUPC(MaxTrans) As String '** This is the UPC of the product sold
Global TransPrice(MaxTrans) As Currency '** This is the price of the item sold
Global K As Integer '** Variable used to index these arrays
Global NumTrans As Integer '** Variable providing number of Transactions preformed.
'------Varibles to define the arrays------------
Global ProdFileName As String '** Variable providing name of product file.
Global EmpFileName As String '** Variable providing name of employee file.
Global TransFileName As String '** Variable providing name of trans file.
Function PL(A As String, I As Integer)
Dim Result As String
Result = A
Do Until Len(Result) >= I
Result = " " & Result
Loop
PL = Left(Result, I)
End Function
['\vbcode]
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 01:05 AM
#17
Thread Starter
Lively Member
Sorry. Here is my module
['vbcode]
Option Explicit
'** The following constant is the width of the receipt in characters.
'** Note, the receipt Text Box was widened and its point size decreased
'** to 10. If you change the width or point size of the receipt Text Box,
'** this constant must also be changed.
Const ReceiptWidth As Integer = 29
Const MaxProducts As Integer = 200 ' Maximum number of Products store can carry
Const MaxEmployee As Integer = 12 ' Maximum number of Employees in the employee file
Const MaxTrans As Double = 100000 ' Maximum number of Transactions that the store can do
Const TaxRate As Currency = 0.065 ' Sales tax rate
Global AmountTendered As Currency ' Amount of money offered by custmer to pay bill
Global SubTotal As Double ' Running subtotal of items purchased
Global SalesTax As Double ' Sales tax due on the order
Global AmountDue As Single ' Total amount to charge customer = SubTotal + SalesTax
'------Variables for the Products File---------
Global UPC(MaxProducts) As String '** Array for UPC codes
Global ProdDesc(MaxProducts) As String '** Product descriptions
Global ProdPrice(MaxProducts) As Currency '** Product prices
Global I As Integer '** Variable used to index these arrays
Global NumProducts As Integer '** Variable providing number of products read.
'------Variables for the Employee File---------
Global EmployeeNum(MaxEmployee) As String '** This is the Employee's Number
Global EmployeeName(MaxEmployee) As String '** This is the Employee's Name
Global EmployeePass(MaxEmployee) As String '** This is the Employee's Password
Global ManagerStatus(MaxEmployee) As Boolean '** This is to determine if the Employee has Manager Status/Rights
Global J As Integer '** Variable used to index these arrays
Global NumEmployee As Integer '** Variable providing number of Employees Logged in.
'------Varibles for the Transactions File-------
Global TransDate(MaxTrans) As Date '** This is the Date when the sale was made
Global TransEmpNum(MaxTrans) As String '** This is the Employee Number of the individual who was logged in
Global TransUPC(MaxTrans) As String '** This is the UPC of the product sold
Global TransPrice(MaxTrans) As Currency '** This is the price of the item sold
Global K As Integer '** Variable used to index these arrays
Global NumTrans As Integer '** Variable providing number of Transactions preformed.
'------Varibles to define the arrays------------
Global ProdFileName As String '** Variable providing name of product file.
Global EmpFileName As String '** Variable providing name of employee file.
Global TransFileName As String '** Variable providing name of trans file.
Function PL(A As String, I As Integer)
Dim Result As String
Result = A
Do Until Len(Result) >= I
Result = " " & Result
Loop
PL = Left(Result, I)
End Function
[/'vbcode]
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 01:05 AM
#18
Thread Starter
Lively Member
fujiyama17 (representing KSU)
-=-=-==-=-=
"There is something funny about life. If you never settle for anything but the very best, you will very often recieve it."
-Margaret M. Somet
-
May 6th, 2002, 01:18 AM
#19
Hyperactive Member
-
May 6th, 2002, 02:00 AM
#20
Originally posted by ZeroCool
This:
VB Code:
Do Until EOF(6) '** Until the end of the file
Should Be this:
They ARE the same
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|