It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Newbie textbox help

Moderator: dafunkymunky

Newbie textbox help

Postby Wookie on Mon Aug 11, 2008 3:43 am

I am trying to create a Forex calculator. And i am completely lost in VB. I have tried several tutorials but none that will do what i would like it to do.

I have 4 textboxes and 1 listbox.

I would like to make these boxes so you can only insert numeric values, and make the inserted value of textbox1 and value of textbox2 to be multiplied to equal teaxtbox3. This is what i have come up with so far

Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer

number1 = Val(textbox1.Text)
number2 = Val(textbox2.Text)
answer = number1 * number2
textbox3.Text = answer

textbox3 has nothing in it unless i add numbers to textbox1 and textbox2 through text in the properties window. Wen i run the program if i were to insert numbers into textbox1 and textbox2 no value is put in textbox3. Also i need these textboxes to support decimal places.

As for the list box there are 3 items in the collection. Standard 100k, Mini 10k and Micro 1k. I would like to make each collection equal to a numeric value. Ex. Standard 100k would be equal to 100,000.

Any help would be much appreciated.

Regards,
Wookie
Wookie
 
Posts: 2
Joined: Mon Aug 11, 2008 2:58 am

Postby chubzyko on Tue Aug 12, 2008 4:48 pm

why dont you just use a command button in showing the answer? or use ascii. wherein if you hit the enter key in the keyboard, the answer will be shown?
"Failure is the key to success, so try and try until you succeed."
User avatar
chubzyko
100+ Club
 
Posts: 104
Joined: Wed Jul 30, 2008 10:48 pm
Location: Marikina City, Philippines

Postby chubzyko on Tue Aug 12, 2008 6:18 pm

anyway, here's how to do it.

Code: Select all
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)

    Dim number1 As Integer
    Dim number2 As Integer
    Dim answer As Integer
     
    number1 = Val(Textbox1.Text)
    number2 = Val(Textbox2.Text)
    answer = number1 * number2
    Textbox3.Text = answer
End Sub

"Failure is the key to success, so try and try until you succeed."
User avatar
chubzyko
100+ Club
 
Posts: 104
Joined: Wed Jul 30, 2008 10:48 pm
Location: Marikina City, Philippines

Postby Wookie on Thu Aug 14, 2008 2:46 pm

I entered what you suggested but nothing happened. Does it matte where i insert the code. Also What is Text2_keyup?
Wookie
 
Posts: 2
Joined: Mon Aug 11, 2008 2:58 am

Postby chubzyko on Thu Aug 14, 2008 4:34 pm

ooops! sorry for that! i forgot that you doesn't have a text2.text textbox name. anyway, you should learn how to debug dude. here's the code again.

Code: Select all
Private Sub Textbox2_KeyUp(KeyCode As Integer, Shift As Integer)

    Dim number1 As Integer
    Dim number2 As Integer
    Dim answer As Integer
     
    number1 = Val(Textbox1.Text)
    number2 = Val(Textbox2.Text)
    answer = number1 * number2
    Textbox3.Text = answer
End Sub




make sure that your textbox are named
Textbox1.Text
Textbox2.Text
Textbox3.Text

because in default, the textbox are named
Text1.Text
Text2.Text
Text3.Text
"Failure is the key to success, so try and try until you succeed."
User avatar
chubzyko
100+ Club
 
Posts: 104
Joined: Wed Jul 30, 2008 10:48 pm
Location: Marikina City, Philippines

Postby ukamed on Sun Aug 17, 2008 10:44 pm

Or if you want numbers shown in textbox 3 as you enter the other numbers in textbox1 and textbox2 you can use the TextChanged event!

it looks something like this:

Private Sub Textbox2_TextChanged()
ukamed
 
Posts: 3
Joined: Mon Aug 11, 2008 11:05 pm


Who is online

Users browsing this forum: No registered users and 4 guests