|
-
Nov 16th, 1999, 01:54 PM
#1
Thread Starter
Lively Member
day two of trying to figure this out can any one please help
icannot figiure out how to get the txtTotal to work with the way i have this combo box loaded and adding the cbolistindex to the grid i keep getting subscipt out of range here's my code i have tried it i don't know how many ways error, error and more errors
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()
If cboMovies.ListIndex < 0 Then Exit Sub
'adds moviename and cost to grid
grdMovieSelect.AddItem Chr(9) & cboMovies & Chr(9) & Format(S_TagMovieFile(cboMovies.ItemData(cboMovies.ListIndex)).dblPrice, "currency")
grdMovieSelect.Row = intMovieCount + 1
intMovieCount = intMovieCount + 1
grdMovieSelect.Rows = intMovieCount + 1
Movie_Price
End Sub
Public Sub Movie_Price()
Dim iIndex As Integer
Dim dblTempDollar As Double
ReDim S_TagMovieFile(0)
dblTempDollar = 0
With FrmVideo
For iIndex = 0 To intMovieCount - 1
ReDim Preserve S_TagMovieFile(iIndex)
.grdMovieSelect.Row = iIndex + 1
.grdMovieSelect.Col = 1
S_TagMovieFile(iIndex).strMovieName = .grdMovieSelect.Text
.grdMovieSelect.Col = 2
S_TagMovieFile(iIndex).dblPrice = .grdMovieSelect.Text
dblTempDollar = dblTempDollar + S_TagMovieFile(iIndex).dblPrice
Next iIndex
.txtTotal = Format(dblTempDollar, "currency")
End With
End Sub
Private Sub cmdDelete_Click()
If grdMovieSelect.Rows = 1 Then
Exit Sub
End If
grdMovieSelect.RemoveItem grdMovieSelect.RowSel
-
Nov 16th, 1999, 03:12 PM
#2
Junior Member
With out seeing more of your program (it looks like there are module or even globle level variable not visibly defined) and with out knowing exactly when the problem occures (ie. does it finish reading the file, does it finish loading the combo box, what has to occure to reproduce the problem) it is difficult to narrow down the problem.
However, you might want to check intMovieCount. In the sub cmdAddMovie_Click, you do this :
grdMovieSelect.Row = intMovieCount + 1
intMovieCount = intMovieCount + 1
grdMovieSelect.Rows = intMovieCount + 1
that might be your subscipt error
-
Nov 16th, 1999, 11:20 PM
#3
It looks like you're doing some things you don't need to and making it more complicated for yourself in the long run.
Here's my interpretation of what you're trying to achieve, I've commented pretty much everything,
so you should be able to figure out what's going on fairly easily..
On a Form with an MSFlexGrid (grdMovieSelect), 3 Command Buttons (cmdAdd, cmdDelete & cmdClose), a Combobox (cboMovies) and a Textbox (txtTotal)..
Code:
'Movie File Name/Path
Private Const sMoviedata = "C:\Movies.txt"
'Movie File Type
Private Type tMovieFile
sName As String 'Movie Name
dPrice As Double 'Movie Price ($)
End Type
'Array of Movie File Types
Private atMoviesFiles() As tMovieFile
Private Sub Form_Load()
'Initialize the Combobox list of Movies
Dim sTemp As String
Dim iCount As Integer
Dim iFreeFile As Integer
Dim iInstr As Integer
txtTotal.Enabled = False
txtTotal.Alignment = vbRightJustify
txtTotal = "$0.00"
'Setup the Flexgrid
With grdMovieSelect
'Need to setup the Header,
'can't have a Fixed Row with less than 2 Rows
.Rows = 2
.Cols = 2 'Col1 = Movie Name, Col2 = Movie Price
'Set the Column widths
.ColWidth(0) = .Width - 1500
.ColWidth(1) = 1400
'Right Justify the Price Column
.ColAlignment(1) = flexAlignRightCenter
'Make the Heading Row Fixed
.FixedRows = 1
'Set the Headers
.TextMatrix(0, 0) = "Movie Title"
.TextMatrix(0, 1) = "Price ($)"
'Now we can set the Rows to 1
.Rows = 1
'Turn off the Highlight until something is in the Grid
.HighLight = flexHighlightNever
.SelectionMode = flexSelectionByRow
End With
'Get the Next available File Number
iFreeFile = FreeFile
'Open the Data File to load in the Movies and Prices
Open sMoviedata For Input As iFreeFile
Do
'Increase the Array Size
ReDim Preserve atMoviesFiles(iCount)
Input #iFreeFile, sTemp
iInstr = InStr(sTemp, "|")
'Split the Input into Movie Name and Price
atMoviesFiles(iCount).sName = Left(sTemp, iInstr - 1)
atMoviesFiles(iCount).dPrice = Right(sTemp, Len(sTemp) - (iInstr))
'Add the Movie to the Combo
cboMovies.AddItem atMoviesFiles(iCount).sName
'Store the Array Index in the Combo ItemData as a Cross Reference
cboMovies.ItemData(cboMovies.NewIndex) = iCount
iCount = iCount + 1
Loop Until EOF(iFreeFile)
Close iFreeFile
'If Moves got loaded, select the first one in the list ready.
If cboMovies.ListCount Then cboMovies.ListIndex = 0
End Sub
Private Sub cmdAdd_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 MovieFiles Array
dTemp = atMoviesFiles(cboMovies.ItemData(cboMovies.ListIndex)).dPrice
'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 = .Cols - 1
End With
'Adjust the Total of all Movies Selected
txtTotal = Format(Val(Mid(txtTotal, 2)) + dTemp, "currency")
End Sub
Private Sub cmdClose_Click()
Unload Me
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)), "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
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
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
|