Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » VB6 KB to MB to GB Calculator
Closed Thread
Old 12-27-2005, 10:32 PM   #1 (permalink)
 
Ultra Techie

Join Date: Jun 2004

Posts: 546

Musjunk22 is on a distinguished road

Default VB6 KB to MB to GB Calculator

I'm just starting to learn VB6 with no other coding expierience and I need some help. I know this simple calcualtor I'm trying to make has been made and can be found on 100,000 websites but I wanted to see if Ic an make it.

Basically I have 3 labels (Kilobytes, Megabytes, Gigabytes), 3 text boxes (Named KB, MB, and GB) , and a command button. this is what the code looks like:

Private Sub Command1_Click()
If KB.Text = Int(KB.Text) Then (GB.Text = Val(KB.Text / 1048576) and (MB.Text = Val(KB.Text / 1024)
End If
If MB.Text = Int(MB.Text)
Then (KB.Text = Val(MB.Text * 1024) and (GB.Text = Val(MB.Text / 1024)
End If
If GB.Text = Int(GB.Text)
Then (MB.Text = Val(GB.Text * 1024) and (KB.Text = Val(GB.Text * 1048576)
End If
End Sub

I've tried 30 tutorials and I'm loosing patience what am I doing wrong? It won't work. I'm guessing it's something really stupid. oh and BTW how do you use the Cbyte(expression) command?
__________________

Musjunk22 is offline  
Old 12-29-2005, 05:04 PM   #2 (permalink)
 
Junior Techie

Join Date: Jan 2005

Posts: 74

Nyper

Default

I hate to just post code without explaining what you did wrong in yours, but yours simply makes no sense. (don't take offense to that!).

What I did below is to check and see if the first box (kb) was blank. If it wasn't blank, I did the calculations. If it was blank, then I checked the next box to see if it was blank. I used integer.parse out of habbit, and realize now integers aren't the correct thing to use. Sorry, but I'm in a hurry. Post again if you would like more explanation & help and I'll catch you again.

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If kb.Text <> "" Then      'If kb is not blank
            mb.Text = Integer.Parse(kb.Text) / 1024
            gb.Text = Integer.Parse(kb.Text) / 1048576

        ElseIf mb.Text <> "" Then  'if kb is blank and mb isn't
            kb.Text = Integer.Parse(mb.Text) * 1024
            gb.Text = Integer.Parse(mb.Text) * 1024

        ElseIf gb.Text <> "" Then  'if kb and mb are blank, but gb isn't
            kb.Text = Integer.Parse(gb.Text) / 1048576
            mb.Text = Integer.Parse(gb.Text) / 1024
        End If

    End Sub

Nyper is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On