Results 1 to 10 of 10

Thread: I'm over my head on this VB project for school, please help.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    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
    If you think education is expensive, try ignorance.

  2. #2
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    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.
    JC

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    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?
    If you think education is expensive, try ignorance.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Pittsburgh, PA
    Posts
    329
    add this to the start of your command button code:

    on error resume next

    it just stops the error message
    ______________

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    323
    Perfect, thanks.
    If you think education is expensive, try ignorance.

  6. #6
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    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

  7. #7
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    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

  8. #8
    Guest

    Exclamation

    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???


  9. #9
    Lively Member
    Join Date
    Mar 2000
    Posts
    103
    By the way Nitrolic...you forgot your exit Cr@p before Hell:

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    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

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width