Computer Science Canada temperature conversions |
Author: | chronicX [ Fri Nov 05, 2004 9:51 pm ] |
Post subject: | temperature conversions |
hi.. i'm new to VB.. n i'm creature a temperature conversion thingi.. umm.. i got the temperature converted from fahrnteit to celcius. i'm having trouble wid outputting the data.. c.. i have to output the farenheit n celsius in the txtbox. but i dunno how to output both at the same time.. herz the code that i made soo far..n i used the for loop so as to stop only 10 entrys to go in.. also attached the forms Private Sub cmdConvert_Click() txtCelsius.Text = Format(((5 / 9) * ((CInt(txtFarenheit.Text)) - 32)), "###0.00") Dim intCtr As Integer For intCtr = 1 To 10 Text1.Text = txtFarenheit Next End Sub Private Sub txtFarenheit_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case vbKey0 To vbKey9 Case vbKeyBack Case Else KeyAscii = 0 End Select End Sub |
Author: | wtd [ Fri Nov 05, 2004 10:12 pm ] | ||
Post subject: | |||
Please use code tags next time.
|
Author: | Brightguy [ Fri Nov 05, 2004 11:17 pm ] |
Post subject: | Re: temperature conversions |
If you want to have all of the temperatures converted in a list, then you should set the MultiLine property of that TextBox to True. You could consider splitting it up into two different TextBoxes so you have two columns. Or you could separate the Celsius/Fahrenheit columns by a Tab, so you would have something like: Text1.Text = txtFarenheit.Text & vbTab & txtCelsius.Text & vbCrLf & Text1.Text Take out the For loop... that only makes it print out the same answer 10 times. If you only want a max of 10, use a variable to hold how many conversions have been done and check against that. |
Author: | chronicX [ Sun Nov 07, 2004 8:34 am ] | ||
Post subject: | |||
thanks dat worked... i also set da txtResult property as multiline.. but.. it still doesnt work..when u said abt the forloop.. shud i use a count variable? n use a do while loop? n how do get it to print diff vaules.. like if da user keeps entering number.. show all the values the user has entered?
|
Author: | chronicX [ Sun Nov 07, 2004 5:51 pm ] | ||
Post subject: | |||
k.. i changed the code around a bit as i hav to take the average of both farenheit n celcius later.. n i did get it to print all the values.. but kinda still haveing problems.. n how do u cut down the decimals to only 2 places? n how do u get it to stop by gettin only 20 values...NEEEDDDDDDDDD HELLPPPPPPPPPPPp
|
Author: | Brightguy [ Sun Nov 07, 2004 10:47 pm ] | ||||
Post subject: | Re: temperature conversions | ||||
You can use the Round function to round the temperature to 2 decimal places:
To have it stop at 20 values, declare a global variable (or static) and every time you convert a temperature, increment it by 1. And before you display the temperature, check to make sure it's less than 20:
|
Author: | chronicX [ Mon Nov 08, 2004 1:55 am ] |
Post subject: | |
thanks it worrked.. but wat abt the prinitn gof the values?? iz all messed up... |
Author: | Brightguy [ Mon Nov 08, 2004 3:33 pm ] |
Post subject: | Re: temperature conversions |
Well, another thing you could consider is using 2 ListBoxes to store the conversions instead of a TextBox. You use the AddItem method to add data into the list. So you would have something like: lstCelsius.AddItem dblCelsius lstFahrenheit.AddItem dblFahrenheit |