close

Privacy guaranteed - Your email is not shared with anyone.

Visual Basic help!

Discussion in 'Tech Talk' started by epsylum, Nov 17, 2005.


  1. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
    Okay this may sound bad. But I am taking a general computer class at my community college. It is called "computer fundementals for technology". Anyhow, the first half of the semester was Microsoft Office. I aced the whole thing since I use office every day at work. But the last half is VB. I have never used VB and so far have only had limited experience programming my TI-83 calculator. I HATE programming and am horrible at it. Anyhow I have tried for 3 days now to get just the basics to work (like getting entered numbers in a textbox to calculate in a formula and display on a label) and I can't. My teacher is useless and is more monotone than Ben Stein. The book is horrible as it's one of those do exactly what I say books so you wind up only making exactly what it wants you to make and doesn't go into the basic ideas of how things work, just "type this and this happens". I am majoring in Design Technology with maybe a minor in machine design. I want to be a draftsman (I already passed all the AutoCAD classes), not a programmer. But, I have to pass this course to get my degree.

    There is only one assignment for the VB portion of the semester. Make a VB program. If I can't get this done, I will probably fail.

    So basically, if anyone is good with VB, could you please help me out. I will take tips all the way to if you feel like banging out a simple ballistic data program (just eneter weight, diameter, and velocity to get ME, TKO, and sectional density and such) and e-mailing me the non-compiled VB file, I would owe you big time.

    PM me if you wish to help.

    Thanks.
     

    Wanna kill these ads? We can help!
  2. cgwahl

    cgwahl
    Expand Collapse
    Sheriffs a near

    Joined:
    Feb 15, 2002
    6,283
    12
    Location:
    CA
    VB6 or VB.NET?
     

  3. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
  4. David_G17

    David_G17
    Expand Collapse
    /\/\/\/\/\/\/\/

    Joined:
    Oct 7, 2002
    2,046
    0
  5. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
    Thanks, that is a lot clearer than my book.
     
  6. grokdesigns

    grokdesigns
    Expand Collapse

    Joined:
    Dec 23, 2004
    507
    0
    Location:
    Chandler, AZ
  7. David_G17

    David_G17
    Expand Collapse
    /\/\/\/\/\/\/\/

    Joined:
    Oct 7, 2002
    2,046
    0
    99.99% of the programming I know, I learned by googling "c++ tutorial", "coldfusion tutorial", "php tutorial", etc.

    textbooks are worthless in my experience.
     
  8. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
    I wish they were worthless, but I paid $100 for this POS book. Damn college textbooks.

    Oh well I am buying next semesters books on ebay and selling these. Screw the bookstore.
     
  9. Nyper

    Nyper
    Expand Collapse

    Joined:
    Jan 2, 2004
    351
    0
    Location:
    Lebanon TN
    Check your PMs.
     
  10. Creeper1313

    Creeper1313
    Expand Collapse
    Aequitas

    Joined:
    Feb 3, 2004
    277
    0
    Location:
    Pittsburgh, PA
    You may have already gotten your answers by PM, but here's a quick and dirty explanation on how to do that assignment.

    In VB6, create a new project. On the gray canvas of the form that you have to work with add the following.

    Three textboxes with labels. Set their names and labels to be meaningful like: "Weight", "Diameter", and "Velocity".

    A command button called "Calculate".

    Labels for your answers. "ME: ", "TKO: ", "Sectional Density: ", etc.
    You can just have the caption now, we'll add the answer later. Make sure you also give them names you'll remember (eg TKOanswer). Also make them wide enough to accept your answer alongside the label. IE "TKO: _____________________" (pretend those are spaces)

    Now go into the code itself. At the top left there will be a drop down box with all the objects currently on your form. Pick the command button you created and named "Calculate".

    By default it will pick the Click event, which is the one you want (there are many others, but don't worry about them now). The code will appear as follows:

    Private Sub Calculate_Click()

    End Sub


    Between these two lines you will type the code for what you want to have happen when the button is clicked. In the case of your program, this is doing math on the items entered in the textboxes. I'll use TKO as an example because I found it's formula on google (heheh) "diameter x weight x velocity divided by 7000" (based on caliber for diameter, grains weight, fps for velocity... change to whatever formula you'd want).

    To do this math, you want your code to look in the 3 textboxes and draw their numeric values for the formula, then you want to put it in the Answer captions (eg "TKO: ")

    Private Sub Calculate_Click()

    If IsNull(Diameter) = True Or IsNull(Weight) = True Or IsNull(Velocity) = True Then
    MsgBox ("All textboxes must be filled in to calculate. Try Again")
    Exit Sub
    End If

    TKOanswer.Caption = "TKO: " & CStr( (CDbl(Diameter) * CDbl(Weight) * CDbl(Velocity) ) / 7000 )

    End Sub


    The first part of the code with the If IsNull statements looks at your 3 text boxes and makes sure none of them are blank, as this will cause an error. The Exit Sub just quits the Click event before it does anything else.

    You are probably wondering what all the CStr() and CDbl() functions do. Let me explain. Since textboxes contain text by default, and your math needs actual numbers, not text, CDbl converts the text values in the 3 textboxes to the type "Double" which is a decimal number (there are many differnt data types, eg CInt would be used to convert to an Integer and get rid of decimals). Be careful with the parenthesis, order of operations, etc. The outer CStr is to convert the double answer back into a String (Text) that the TKOanswer.Caption needs. (the .Caption is the property of a label that contains it's text, objects in VB have tons of properties, such as length, width, style, etc.)
    The "&" is to combine the Text "TKO: " with the CStr'd text of the answer.

    So for example if someone entered ".223" "72" and "2700" in the 3 respective textboxes and pushed calculate, this line would roughly translate into:
    TKOanswer's caption = the text "TKO: " combined with
    The string conversion of the answer to:
    (.223 * 72 * 2700) / 7000

    Just repeat that code for the other answer labels and change the math as appropriate. And like I said, watch your parethesis... e.g. The outer Cstr( ) should contain all your math.
    Let me know if you have any other questions.

    PS sorry the code I posted isn't nicely indented. The spaces seem to get chopped off in posting.
     
  11. Creeper1313

    Creeper1313
    Expand Collapse
    Aequitas

    Joined:
    Feb 3, 2004
    277
    0
    Location:
    Pittsburgh, PA
    I whipped up an example to show you some screens. Also, it seems the IsNull wasnt the correct approach for protecting agianst leaving fields blank, just make sure the 3 textboxes do not = "" (blank).

    [​IMG]

    Here's it in action (it will update the answer each time you change the values and re-click the "Calculate" button.

    [​IMG]
     
  12. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
    Thanks a lot Creeper.

    I am going to give it another shot right now.
     
  13. epsylum

    epsylum
    Expand Collapse
    Boolit Hoze

    Joined:
    Sep 4, 2004
    3,868
    0
    Location:
    Racing Capital, USA
    Okay, it's overwith.

    I turned it in today. I had some issues with file transfering (I need a dang USB flash drive BADLY) trying to get it on the school computer. I basically had my code, but everything else was missing. So I just copied and pasted my code and made the form again. There were some in the class who had fancy shmancy stuff, but most were along my level of work, so I think I am okay there. There was even a guy who had a lot less than what I had and he said the teacher said he would probably get a B on it, so I am even hopeful for a decent grade out of it.

    What I am getting at is,

    THANK YOU!!!

    to everyone who offered help.

    I completely forgot to compile it, but I will next week and post it on here if anyone wants it. It's nothing fancy by far, but could see myslef using it every now and then