Solved

File Size Calc 4 CD

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 57
using Access 8 59
VBA filters 2 51
fso.FolderExists("\\server\HiddenFolder$") 4 52
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

26 Experts available now in Live!

Get 1:1 Help Now