Results 1 to 4 of 4

Thread: Comparing KB MB GB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Comparing KB MB GB

    Can anyone help me

    when i'm comparing two data sizes i'm having some trouble

    i'm comparing 64 MB with 32 MB and my program correctly identifies that 64 MB is the larger size

    but when i compare 64 MB with 512 MB it tells me that 64 MB is the larger size

    heres my code can anyone amend it so that it compares the two data sizes correctly?

    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            If TextBox1.Text > TextBox2.Text Then
                MessageBox.Show("TextBox1 is the biggest")
            Else
                MessageBox.Show("TextBox2 is the biggest")
    
            End If
        End Sub

  2. #2
    Lively Member
    Join Date
    May 2004
    Posts
    104

    Re: Comparing KB MB GB

    You are comparing Text Not data size. You are going to have to use an if then or select case statements. Or use arrays. Or you can convert the text into a number type data. ie CInt.
    Last edited by Polariss; Apr 10th, 2006 at 06:25 AM.

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Comparing KB MB GB

    To expand on what Polariss said, you need to think about what it is your comparing. The string

    "64 MB"

    is greater than

    "512 MB" because the first digit has a higher ascii value in the first string.

    You might want to convert the numbers to bytes first, then compare the values. Keep in mind, that 120 GB is 128849018880 bytes or so, so you will need to pick a data type capable of dealing with those numbers. Also, if this is just entering data into a textbox, then you will have to assume all sorts of input like "120MB" "10 MB", "20 mb" etc..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    Re: Comparing KB MB GB

    cheers you have given me some great ideas....what i have is a class that converts bytes to it's correct format I.E KB MB GB....

    so what i could do is assign the byte to the textbox tag property and compare the tag instead of the text property

    Just an idea...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width