frostwhitedc4 04-14-2003, 05:52 PM scenario: computer warehouse wants an application that will calculate both the total number of items sold and the total number sold by item. the application should allow the user to print the interface.
this is what i have done. dont know where to start now.
Option Explicit
Private Sub Form_Load()
frmComputer.Top = (Screen.Height - frmComputer.Height) / 2
frmComputer.Left = (Screen.Width - frmComputer.Width) / 2
lstItem.AddItem "ABC11"
lstItem.AddItem "CVA33"
lstItem.AddItem "BDX22"
lstItem.ListIndex = 0
End Sub
Private Sub mnuFileExit_Click()
Unload frmComputer
End Sub
the book says:
code the calculate total option so that it calculates the total sold, from the lc5.dat file (its on my disk). display an apporopriate message along with the total number sold in the lblTotall control. (For example, display the message "The total number sold is 300" in the lblTotal control.
this is whats in the lc5.dat file:
"BDX22",100
"ABC11",150
"BDX22",250
"CVA33",100
"ABC11",300
i dont know what to do. help please
VBJoe 04-14-2003, 09:46 PM I take it this project is for a homework assignment? If so, maybe you should read the book that came with the class... ;)
For starters, read the lc5.dat file and put the values into dynamic arrays. Then you can do all your processing on the arrays.
This is a fairly straightforward beginner VB assignment. Your text box should have all the answers you need.
frostwhitedc4 04-14-2003, 10:34 PM I take it this project is for a homework assignment? If so, maybe you should read the book that came with the class... ;)
For starters, read the lc5.dat file and put the values into dynamic arrays. Then you can do all your processing on the arrays.
This is a fairly straightforward beginner VB assignment. Your text box should have all the answers you need.
im a beginner with vb. yes i know you are right, but i still cant get it, when i follow the work in class i know what is going on, but when it comes to homework, its seems like its all different. please help.
starbitz 04-14-2003, 10:45 PM I suggest you start by opening the lc5.dat file. Now,if you encounter problems/errors in openning files, you can ask for help. We cant just write the codes for you. Do it step by step.
You can save the contents of the file in an array and manipulate it. Now if you encounter problems again, we are always ready to help, as long as you are also doing your part. :)
frostwhitedc4 04-14-2003, 10:48 PM I suggest you start by opening the lc5.dat file. Now,if you encounter problems/errors in openning files, you can ask for help. We cant just write the codes for you. Do it step by step.
You can save the contents of the file in an array and manipulate it. Now if you encounter problems again, we are always ready to help, as long as you are also doing your part. :)
alright. thanks for the encouragment. :confused:
frostwhitedc4 04-15-2003, 07:58 PM i still dont get how to start coding this, can someone point me in the right direction? do i use the do while funciton? or EOF?
frostwhitedc4 04-15-2003, 08:14 PM this is what i just got
Private Sub mnuStatisticsCalcTotal_Click()
Dim strItem As String
Open "E:\Visual Basic 6 Student Files\Tut06\la5.dat" For Append As #1
Do While Not EOF(1)
Input #1, strItem
Select Case strItem
Case "BDX22"
lblTotal.Caption = Val(lblTotal.Caption) + 100
Case "ABC11"
lblTotal.Caption = Val(lblTotal.Caption) + 150
Case "BDX22"
lblTotal.Caption = Val(lblTotal.Caption) + 250
Case "CVA33"
lblTotal.Caption = Val(lblTotal.Caption) + 100
Case "ABC11"
lblTotal.Caption = Val(lblTotal.Caption) + 300
End Select
Loop
Close #1
End Sub
i dont think using arrays is the right way becuase there is only one label (lbltotal)
starbitz 04-15-2003, 08:42 PM The best way is to define a type.Declare this in a module:
Type Items
Itemname as string
ItemTotal as string
end type
Public myItems() as Items
You can declare this in General Declaration of your form
Dim Templine(1) as string
Dim i as integer
Dim sTestline as string
i = 0
'Start by opening the file and saving it to an array:
Open sFilename For Input As #1
ReDim myItems(0)
While Not EOF(1)
Line Input #1, sTestline
Erase Templine
TempLine = Split(sTestline," ") ' Splits your sTestline into 2 parts, the itemname and total
Redim Preserve myItems(i) ' Resizes your dynamic array
myItems(i).Itemname = TempLine(0) 'save the first part into Itemname
myItems(i).ItemTotal = TempLine(1) 'save the second part total
i = i + 1
Wend
Close #1
You can then Loop through myItems to compute the Total Sold.
example:
dim subtotal as integer
For i = 0 to Ubound(myItems)
subtotal = subtotal + Val(myItems(i).ItemTotal)
next i
lblTotal.Caption = subtotal
BTW: To add a module, go to Projects, Add module
frostwhitedc4 04-15-2003, 10:03 PM thanks anyways bro, i found an easier way. thanks!
|