• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

File Size Calc 4 CD

Hi PPL:
I have a huge amount of CD's I have to carry around in my car and I want to cut it down as much as possible. What I have done is in a ListView I have listed the program name in col 1 and its size in MB in the second. What I want to now do is have my program calculate which programs can be shorted and will add up as close to 700MB to fill a CD.

So basiclly I have a list of apps and the file size for that app. I need some code which will write in col 3 which CD that app should go onto. IE 1,2,3 so that it will total up to 700MB or around 700MB. Bottom line I want to get as much as I can on each CD...
0
hollstar
Asked:
hollstar
  • 3
1 Solution
 
Maxim10553Commented:
why dont you tack on some more points because what you are asking for is custom code and that takes time.
0
 
hollstarAuthor Commented:
How many do you want in total?
0
 
hollstarAuthor Commented:
I should also mention that I do need to be able to save & load this information to file. A TXT file will do. I have used a sample below:

Icon Edit Pro|1.37|
WinZip|2.97|


Please Note: After the last | this is the location of the CD number once the user has calculated the information.

Also note the save and load function must use a dialog box.
0
 
sharmonCommented:
I wrote a sample for you to do this with.  Anyhow, to run this sample, just create a form with one listview and one command button.  Leave them at their default names, (Listview1 & Command1).  Copy this code to it and run it...I manually added generic numbers to the listview at runtime to test with....I am sure there are other ways to do it, this is the first thing I thought of.  As far as loading and saving a listview, there are already alot of questions about this asked, you should search the site, no point in rewriting all that again.  I have already answered that a couple times for people.  If you can't find it, I'll post my answer again.


'Copy this code to the form as setup above...

Option Explicit

Private Type TCDMEGS
  dblMBs As Double
End Type

Dim CDMegs() As TCDMEGS

Private Sub Form_Load()
  ListView1.ColumnHeaders.Clear
  ListView1.ColumnHeaders.Add , , "Program"
  ListView1.ColumnHeaders.Add , , "Size"
  ListView1.ColumnHeaders.Add , , "Which CD"
  ListView1.View = lvwReport
 
  Dim xItem As ListItem
 
  Set xItem = ListView1.ListItems.Add(, , "Program A")
  xItem.SubItems(1) = "50"
 
  Set xItem = ListView1.ListItems.Add(, , "Program B")
  xItem.SubItems(1) = "250"
 
  Set xItem = ListView1.ListItems.Add(, , "Program C")
  xItem.SubItems(1) = "450"
 
  Set xItem = ListView1.ListItems.Add(, , "Program D")
  xItem.SubItems(1) = "250"
 
  Set xItem = ListView1.ListItems.Add(, , "Program E")
  xItem.SubItems(1) = "5"
 
  Set xItem = ListView1.ListItems.Add(, , "Program F")
  xItem.SubItems(1) = "85"
 
  Set xItem = ListView1.ListItems.Add(, , "Program G")
  xItem.SubItems(1) = "1.44"
 
  Set xItem = ListView1.ListItems.Add(, , "Program H")
  xItem.SubItems(1) = "100"
 
  Set xItem = ListView1.ListItems.Add(, , "Program I")
  xItem.SubItems(1) = "750"
End Sub

Private Sub Command1_Click()
  Dim i As Integer
  ReDim CDMegs(0)
 
  CDMegs(0).dblMBs = 0
 
  If ListView1.ListItems.Count < 1 Then Exit Sub
 
  For i = 1 To ListView1.ListItems.Count
    ListView1.ListItems(i).SubItems(2) = _
      WhichCD(CDbl(ListView1.ListItems(i).SubItems(1)))
  Next i
End Sub

Private Function WhichCD(ByVal dblMBs As Double) As Integer
  Const intMaxMB As Integer = 700
  Dim i As Integer
  Dim x As Integer
 
  If dblMBs > intMaxMB Then
    WhichCD = 0
    Exit Function
  End If
 
  For i = 0 To UBound(CDMegs)
    If CDMegs(i).dblMBs + dblMBs <= intMaxMB Then
      WhichCD = i + 1
      CDMegs(i).dblMBs = CDMegs(i).dblMBs + dblMBs
      Exit Function
    End If
  Next i
 
  x = UBound(CDMegs) + 1
  ReDim Preserve CDMegs(x)
  CDMegs(x).dblMBs = dblMBs
  WhichCD = x + 1
End Function
0
 
hollstarAuthor Commented:
Fine with me sharmon!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now