Solved

File Size Calc 4 CD

Posted on 2001-06-20
5
182 Views
Last Modified: 2010-05-02
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
Comment
Question by:hollstar
  • 3
5 Comments
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6212476
why dont you tack on some more points because what you are asking for is custom code and that takes time.
0
 

Author Comment

by:hollstar
ID: 6212486
How many do you want in total?
0
 

Author Comment

by:hollstar
ID: 6212532
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
 
LVL 6

Accepted Solution

by:
sharmon earned 200 total points
ID: 6212570
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
 

Author Comment

by:hollstar
ID: 6212629
Fine with me sharmon!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now