
-----------------------------------
chronicX
Fri Nov 05, 2004 9:51 pm

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

-----------------------------------
wtd
Fri Nov 05, 2004 10:12 pm


-----------------------------------
Please use code tags next time.  :)

[code]This is code[/code]

-----------------------------------
Brightguy
Fri Nov 05, 2004 11:17 pm

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.

-----------------------------------
chronicX
Sun Nov 07, 2004 8:34 am


-----------------------------------
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?


Private Sub cmdConvert_Click()

    txtCelsius.Text = Format(((5 / 9) * ((CInt(txtFarenheit.Text)) - 32)), "###0.00")
    
    Dim intCtr As Integer
 
    txtResult.Text = txtFarenheit.Text & vbTab & vbTab & vbTab & vbTab & txtCelsius.Text & vbclrf
     
 
      
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


-----------------------------------
chronicX
Sun Nov 07, 2004 5:51 pm


-----------------------------------
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


Private Sub cmdConvert_Click()

    Dim intF As Double
    Dim intC As Double
    Dim intCount As Integer
    

        intF = txtFarenheit.Text
        intC = (intF - 32) * 5 / 9
        txtCelsius.Text = intC
        txtResult.Text = txtResult.Text & intF & vbTab & vbTab & vbTab & intC
     
    


      
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


-----------------------------------
Brightguy
Sun Nov 07, 2004 10:47 pm

Re: temperature conversions
-----------------------------------
You can use the Round function to round the temperature to 2 decimal places:

dblCelsius = Round((dblFahrenheit - 32) * 5 / 9, 2)
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:

Static intConversions As Integer
If intConversions < 20 Then
   ...
   intConversions = intConversions + 1
End If

-----------------------------------
chronicX
Mon Nov 08, 2004 1:55 am


-----------------------------------
thanks it worrked.. but wat abt the prinitn gof the values?? iz all messed up...  :cry:

-----------------------------------
Brightguy
Mon Nov 08, 2004 3:33 pm

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
