|
-
Nov 18th, 1999, 01:07 PM
#1
Thread Starter
Lively Member
ok the cmdadd works now but now i need get the cmdDelete to finish the task it works fine but what i cannot figure out is how to
add the grid data back to the combo box after a user deletes the row and if a better way can be figured out to add the 7% tax a more
precise way dtemp*1.07"currency" if I add and delete a number of times i will end up with a sum of 1 cent
Private Sub Create_Movie_List() 'loads moviedata to cbomovies
Dim strTemp As String 'declare variables
Dim intCount As Integer
Dim intFreeFile As Integer
Dim intInstr As Integer
intCount = 0 'declare values
intFreeFile = FreeFile
Open MovieData For Input As #intFreeFile
Do 'start of loop
ReDim Preserve S_TagMovieFile(intCount)
Input #intFreeFile, strTemp
intInstr = InStr(strTemp, "|")
'finds movie name in string
S_TagMovieFile(intCount).strMovieName = Left(strTemp, intInstr - 1)
'finds movie price in string
S_TagMovieFile(intCount).dblPrice = Right(strTemp, Len(strTemp) - (intInstr))
'adds movie names to combobox
cboMovies.AddItem S_TagMovieFile(intCount).strMovieName
cboMovies.ItemData(cboMovies.NewIndex) = intCount
intCount = intCount + 1
'end of loop
Loop Until EOF(intFreeFile)
Close #intFreeFile
End Sub
Private Sub cmdAddMovie_Click()
Dim dtemp As Double
'only add a movie if one is selected
If cboMovies.ListIndex < 0 Then Exit Sub
With grdMovieSelect
'get the Movie Price from the Moviefile arry
dtemp = S_TagMovieFile(cboMovies.ItemData(cboMovies.ListIndex)).dblPrice
'add the selection to the grid
.AddItem cboMovies & Chr(9) & Format(dtemp, "currency")
'enable the highlight
.HighLight = flexHighlightAlways
'make sure the Entire row is selected
.ColSel = .Col = 1
End With
'remove Movie from Combobox
cboMovies.RemoveItem cboMovies.ListIndex
'Add the total of all the Movies Selected
txtTotal = Format(Val(Mid(txtTotal, 2)) + dtemp * 1.07, "currency")
End Sub
Private Sub cmdDelete_Click()
With grdMovieSelect
'Only Remove an Item if there is one..
If .Rows < 2 Then Exit Sub
'Adjust the Total to Exclude the selected Movie Price
txtTotal = Format(Val(Mid(txtTotal, 2)) - Val(Mid(.TextMatrix(.Row, 1), 2)) * 1.07, "currency")
'If this is the Last Item Just Set the Rows to 1
If .Rows = 2 Then
.Rows = 1
Else
'Otherwise Remove the Selected Row
.RemoveItem .Row
End If
'Turn the highligh off if there are no more Items
If .Rows = 1 Then .HighLight = flexHighlightNever
End With
End Sub
[This message has been edited by Jessie (edited 11-19-1999).]
[This message has been edited by Jessie (edited 11-19-1999).]
-
Nov 18th, 1999, 01:32 PM
#2
Create a Private Variable in the General Section of the Form to hold the Total without Tax.
Then just display this Total in the txtTotal Textbox Multiplied by the Tax.
This way you don't need to include Tax in your Calculations, eg.
Adding Values..
Code:
dTotalExTax = dTotalExTax + dTemp
txtTotal = Format(dTotalExTax * 1.07, "currency")
Removing Values..
Code:
dTotalExTax = dTotalExTax - Val(Mid(.TextMatrix(.Row, 1), 2))
txtTotal = Format(dTotalExTax * 1.07, "currency")
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 18th, 1999, 01:59 PM
#3
Thread Starter
Lively Member
ok that make better sense Aaron i haven't tried your code yet to see if it works, i'm sure it will
that answers 1 part of my question
now with the way the .removeitem .row in the cmddelete i have tried to send the row info
eg what ever movie and price is in that row back to the combo box so that it may be selected later if need be
[This message has been edited by Jessie (edited 11-19-1999).]
-
Nov 18th, 1999, 02:17 PM
#4
OK, I hadn't notice you were removing the Item from the Combobox.
In that case, it would be a Good Idea to store the S_TagMovieFile Index In the Grids RowData Property.
This would make it alot easier to add the Item back after removing it from the Grid, eg.
In the cmdAddMovie_Click()..
Code:
.AddItem cboMovies & Chr(9) & Format(dtemp, "currency")
.RowData(.Rows - 1) = cboMovies.ItemData(cboMovies.ListIndex)
Then in the cmdDelete_Click()..
Code:
'Add Movie Back to Combobox
cboMovies.AddItem S_TagMovieFile(.RowData(.Row)).strMovieName
cboMovies.ItemData(cboMovies.NewIndex) = .RowData(.Row)
If .Rows = 2 Then
.Rows = 1
Else
'Otherwise Remove the Selected Row
.RemoveItem .Row
End If
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
[This message has been edited by Aaron Young (edited 11-19-1999).]
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
|