-
I have tried to make a program for school using some basic combo boxes, text boxes, and a few command buttons. I am over my head, but anyone that knows VB would know this stuff like the back of their hand.
I have made a webpage (because I'm better at that) to help everyone understand where I'm at now.
You can find that page @ http://artsapimp.8m.com
I need the equation to be ET=kpt/100
k is the first box at the top.
p is a value determined by deciding the month and Latitude from the drop down boxes.
t is the temperature (3rd box).
when you click calculate it should show the value of ET in the last text box.
Please reply with any questions if you have any.
Thanks for your help
-
Hi. I looked at your code and you aren't to far from being finished. I won't give you the answer, but I'll help you get pointed in the right direction. Here are a few things you can do to get on the right track.
1. Name your controls better. Give them a name that means something you can identify in the code. Examples: call the text box that holds the value of k something like txtK, and the command button that calculates the answer cmdCalc. That will clear up some of the confusion on what your code is doing. You talk about t = Temperature, but you don't have anything on your form referencing t. There is the F for Farenheit on your form so modify your form or formula to be more consistant or clear.
2. Remember that Integer values are whole numbers only. They don't have any fractions or decimal places. You will need to use CDbl() to convert to doubles, CInt() to convert values to integers, etc. You can use integers in the calculations, but with K being a fraction, your answer will not be an integer.
3. Do you really need Form2? You don't unless it is a requirement for your assignment. Just put the list box on Form1 and store the value in a variable. It doesn't really matter if the user knows that Corn = .8. Getting rid of the second form will reduce the complexity a bit.
4. You can use the LostFocus event of the text boxes to validate the entries for each text box. Here is an example of checking the value of your Temperature box on exit.
Code:
Private Sub Text3_LostFocus()
If Not IsNumeric(Text3.Text) Then
MsgBox "Invalid Entry.", vbOKOnly, "Bad Value"
Text3.SetFocus
End If
End Sub
If the value in text3 is not numeric it will tell you and return focus to the text box. (Again, rename this to something useful like txtTemperature.)
5. Your formula will be something like this... Use this in your cmdCalc click event.
dblK = Cdbl(txtK.text)
dblP = Cdbl(txtP.text)
dblT = Cdbl(txtT.text)
dblAnswer = (dblK * dblP * dblT)/100
txtAnswer.text = dblAnswer
Good luck & Hope this helps.
-
Thank you very much. I have it working now.
I still have a basic problem. If I click Calculate and I haven't chosen a month or latitude it gives me an error saying:
invalid outside procedure.
How would I stop that?
-
add this to the start of your command button code:
on error resume next
it just stops the error message
-
-
or at the top put for example
private cr@p command1_click()
on error goto hell
'some code
'some code
'some code
'some code
hell:
msgbox"there was an error please try using ur brain when filling things out",,"error"
end cr@p
cr@p = sub
what this does is when an error occurs it tells the error to go to hell and instead of showing the default error it does whats after hell:
i think you will have to add a on error resume next after hell: though because i think it will display your error and the default error
-
by the way that cr@p thing was a joke dont actually type that into your code. type in sub instead of cr@p i just forgot what came after private in private sub so i just wrote private crap
-
jcouture100 ~
I've been learning VB by developing my own application as I progress through a manual. Currently I'm playing with ErrorCheck for my text boxes. With IsNumeric, I'm assuming it can be incorporated within the ErrorCheck???
It was my thinking to add this to prevent mistypes from entering alpha characters into the text box and causing a runtime error. Is this a correct assumption???
-
By the way Nitrolic...you forgot your exit Cr@p before Hell:
-
IsNumeric
that function checks the string to see if it is numeric
if you want to disallow alpha entry you can use this..
'allow only numeric data in a textbox
Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 13
Beep 'if not numeric then beep
End Sub