-
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
-
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.
-
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
-
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...