Solved

File Size Calc 4 CD

Posted on 2001-06-20
5
192 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TT Auto Dashboard 13 101
Help me. 3 70
Need Nag Screen for Reboot if system up time is over 14 days 12 81
VB6 - Cannot type when doing an extract from MSHFlexgrid to Excel 6 38
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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