Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:11:01+00:00 2026-05-17T16:11:01+00:00

SEE BOTTOM OF THIS POST FOR UPDATE ON THIS PLEASE. I have the below

  • 0

SEE BOTTOM OF THIS POST FOR UPDATE ON THIS PLEASE.

I have the below code that searches through directories and displays the largest file in the directory. the problem is that it displays it in KB – how on earth do I convert it to MB? The file size comes out way too large so want easier reading – thanks for the help:

Private Sub btnGetMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetMax.Click
    ClearList()

    Dim dblSize As Integer = 0
    Dim dblMax As Integer = 0
    Dim strMax As String = ""

    Dim objFileInfo As System.IO.FileInfo

    For Each strFile As String In My.Computer.FileSystem.GetFiles("c:\temp", FileIO.SearchOption.SearchAllSubDirectories)

        objFileInfo = My.Computer.FileSystem.GetFileInfo(strFile)
        /*whats the size of the files?*/
        dblSize = objFileInfo.Length

        If dblSize > dblMax Then
            dblMax = dblSize
            strMax = objFileInfo.FullName
        End If
    Next

    MessageBox.Show("Largest file in .Net folder is " & vbCrLf &
                    strMax & vbCrLf &
                    dblMax.ToString("N0"))
End Sub

SHOULD HAVE MADE MYSELF MORE CLEAR! I KNOW HOW TO CONVERT KB TO MB BUT NO IDEA HOW I INCORPORATE THAT INTO MY CODE – DO I ADD ANOTHER VARIABLE FOR STRMAX AS /1024…..EXCEPT I ALREADY HAVE STRMAX VARIABLE…..STILL VERY MUCH A BEGINNER GUYS.

I know how to convert KB to MB – the problem is how do I incorporate that into my code? Do I add another variable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:11:01+00:00Added an answer on May 17, 2026 at 4:11 pm

    (Sorry for the previous answer with 1024, a mistaken assumption)

    To your question of converting from kB to MB, you can surely assume by SI standard:

    1 MB = 1000 kB
    

    Ergo, divide by 1000.

    For the unconvinced, I encourage you to read this.

    Since software like Microsoft Windows expresses storage quantities in multiples of 1024 bytes, change your code to:

      dblMax = dblMax/(1024*1024)  
    
      MessageBox.Show("Largest file in .Net folder is " & vbCrLf &
      strMax & vbCrLf &
      dblMax.ToString("N0"))
    

    (since you are printing dblMax & your file size is in bytes, not kB)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update Added jsfiddle - see bottom of post I currently have a function that
UPDATE: Sorry I seemed to have forgot some things...see bottom of the post for
Update: See the bottom of this question for a C# workaround. Hi there, Consider
Intro: EDIT: See solution at the bottom of this question (c++) I have a
Update Solution Found See Bottom of post if interested Seems simple enough and for
(Please see update at bottom) I've looked at dozens of questions and haven't been
Solved the problem see the bottom of my post. So I have a simple
This post has been 'somewhat' addressed (see links at bottom of post) but not
Scroll down to the bottom of this post to see a work around /
Note: See the bottom of this post for an explanation for why this wasn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.