Any VB2010 programmers here?

Discussion in 'Technical' started by TheyCall MeBruce, Mar 12, 2012.

  1. I'm trying to make a math program to help my daughter with her home schooling, but I've run into a snag... anyone have a good coding background in VB2010?
  2. UGRev

    UGRev Get on with it!

    what's the question?
  3. Quigley_Sharps

    Quigley_Sharps The Badministrator Administrator Founding Member

    Visual Basic 2010
    VisuTrac likes this.
  4. UGRev

    UGRev Get on with it!

    That's not a question.. that's a programming language. I'm looking for what, in particular, is the question... where is he stuck in programming the app?
  5. CATO

    CATO Monkey+++

    post what you're trying to do (want) and the code you have written (have) and I'll take a look.
  6. Here is how it works (and/or how I would like it to work)
    It will produce simple math problems add, subtract, multiply, and divide. (My daughter is still young) I want the problems to be random but only numbers between 0-12
    example 0x2, 1+12, 12+12 and so on. I have the adding subtracting and multiplying down, but I can't figure out how to make the division work properly.
    Then I also what to make a counter that tells right and wrong answers but also splits them up in to sub categories as well (add, subtract, multiply, divide) I can do a single counter but multiple counters confuse me.

    I have some background in programming I'm currently in school going for a AS in programming, but i'm still wet behind the ears so to speak :/

    I'll post the code that i have

    I don't want a written program just some suggestions
  7. first and foremost I honestly did this in a matter of 10 minutes or so. I know I shouldn't have used the values of a textbox property for this but I was kinda being rushed at the time. In the next day or so I'm going to redo it using variables then change them to string.

    My main plan is to use this for testing purposes on my daughter until we start buying the Saxon math books. After that I mayl add some graphic and color to make a game out of it for her. :D

    Public Class Form1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ' If solution is right show picture if wrong beep

    If solution1.Text = Val(topNbr.Text) + Val(bottomNbr.Text) Then
    R.Text = R.Text + 1
    Correct.Text = "GOOD JOB!"
    Timer1.Enabled = True
    W.Text = W.Text + 1
    Correct.Text = "Nope try again"
    Timer1.Enabled = True
    End If
    solution1.Text = ""
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Button2.Visible = False
    End Sub
    Private Sub rndnmbrs()
    topNbr.Text = CStr(Int(Rnd() * 10)) ' Pick number
    bottomNbr.Text = CStr(Int(Rnd() * 10))
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Correct.Text = ""
    End Sub

    End Class

    Another thing... I had to put the timer in to erase the text " Good Job" and " Try again" because it would delete it to fast for the eye to see. does anyone know another way I could do this? I'm thinking it would be a matter of placement of the text but I'm not sure.
  8. kckndrgn

    kckndrgn Monkey+++ Moderator Emeritus Founding Member

    can't spend much time delving into this, but a couple of thoughts, programming wise. Change the name of your buttons to describe what they do. "Button1", "Button2", are hard to make sense when showing code to others.

    Do you have a button for "Next Problem"? One button should be able to handle the check answer, next problem or re-do problem. key the text "good job", etc. off of that event.
    So you have your form, she enters the solution and clicks "Check Answer" If it's correct you show "GOOD JOB" and change the text of the button to "NEXT". If she's wrong display "Try Again" and change the button text to "Try Again".

    if the numbers to be calculated and the operation are a all generated use label fields to prevent anyone from entering their own.
    label - operand1 --left number
    label - operand2 -- right number
    label - operation -- +,-,/,*

    I like the idea, an my need to do this for my daughter and son.
  9. I know :( My Programming teacher would give me crap too for this lol but I was in a bit of a hurry while it was still fresh in my mind.

    Now that you made me feel guilty, I'm going to sit down and do it right :D

    Here is what is on the form designer:
    topNbr is the top number of the math problem
    BottomNmr is the bottom number
    Sgn is the Sign (add sub multiply divide)
    Eql is the equal sign
    Solution1 is the answer textbox

    the forum has 3 buttons Exit, Answer, and Start
    Exit = Button3
    Answer = Button1
    Start = Button2

    4 labels on the form for my counters
    Label1 = Right answers
    Label2 = Wrong answers
    R = Right (value changes)
    W = Wrong (value changes)

    With out taking a Screen shot of the form it looks like this.

    Label1 ----> Right Wrong <--- Label2
    0 0

    Sgn BottomNbr


    Button3<---Exit Button1<---Answer Button2<----Start

    I am rather ashamed of this program. I know it is rather crude looking and I know I can do a lot better, but I guess you could call it a rough draft... It's a bad habit I have to make a quick program and then redo it later once my idea is working.
    I like to see these little programs as gaining more programming time for me, instead of just building the final product. (they help me get used to using the software by repetition)
  10. I'm not sure if it's O.K. to do so but am I a loud to post the actual program files here? Maybe someone else might want to build off these ideas... then again if they did they could just copy and paste to VB or another language for that matter. Still, I wouldn't mind in the least to post the finish program here for others to use for the same purpose I am.
  11. CATO

    CATO Monkey+++

  12. UGRev

    UGRev Get on with it!

    I personally prefer the more OOP approach.
    I would build a class that handles the generation of the math question.
    1. randomize 2 numbers in a range from 0-12
    3. store those numbers in a dictionary
    4. Randomly select one of the operand chars
    5. store that in a public property
    6. evaluate the expression using a case statement.
    if operand is X do multiply of both numbers, store result so you can compare answer given.

    This way, every time you say "new question", you create a new MathQuestionGenerator object with all the stuff you need and you just compare the answers entered to the answer calculated.
    TheyCall MeBruce likes this.
  13. CATO

    CATO Monkey+++

    Oooooh, requirements....I love requirements.

    I agree with UGRev conceptually on creating a class.

    I would have a few changes:

    1) Allow user to choose which branch of arithmetic they can work on (e.g., addition) but also allow them to choose 'random' which will randomly select for them.
    2) Keep track of correct answers and after 3, give them a gold star.
    3) Have a difficulty level (e.g., easy, medium, hard) that would take the first random number into account when selecting the second. Perhaps 'hard' would limit the numbers to >5.
    TheyCall MeBruce likes this.
  14. kckndrgn

    kckndrgn Monkey+++ Moderator Emeritus Founding Member

    WOW, as this "simple" question on coding has quickly spun into a full fledged OOP program that can be easily upgraded, but has increased the complexety. Such is life as a coder :)
  15. ghrit

    ghrit Bad company Administrator Founding Member

    Yes, you can post work that is yours, not copyrighted elsewhere. I strongly suggest doing it as an attachment in preference to filling the thread directly. Those that are helping you out with changes can post snippets in the thread without problems, or simply copy paste and work on it off line, then change the file name and repost as an attachment.
    Good project.

  16. UGRev

    UGRev Get on with it!

    Hey, if you're going to program OOP, program OOP prOOPerly :)
    TheyCall MeBruce likes this.
  17. O.k.... I'm know where near done but I would like some input. should I or wouldn't it be easier to make separate subs for adding, subtracting, ect..?
    Example Private Sub Addition Private Sub Subtraction

    That being said here is what I have so far (only addition next subtraction)

    ' Program Name: Math Test 101
    ' Programmer: Bruce
    ' Program Help: Survival Monkeys
    ' Date: 3/13/2012
    ' Description: This program tests the users math skills with addition, subtraction
    ' multiplacation, and division.

    Public Class Form1
    Private SolutionTotalInteger, TopNumberInteger, BottomNumberInteger, RightInteger, WrongInteger As Integer

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
    ' Initialize the program.
    StartButton.Enabled = False ' Disable Start button.
    End Sub
    Private Sub RoundNumbers()
    ' Randomizes TopNumber and BottomNumber.
    TopNumberInteger = Int(Rnd() * 12)
    BottomNumberInteger = Int(Rnd() * 12)
    TopNumberLabel.Text = TopNumberInteger.ToString("N0")
    BottomNumberLabel.Text = BottomNumberInteger.ToString("N0")

    End Sub
    Private Sub AnswerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnswerButton.Click
    ' Calulate values

    SolutionTotalInteger = Integer.Parse(SolutionTextBox.Text)
    If SolutionTotalInteger = TopNumberInteger + BottomNumberInteger Then
    RightInteger += 1
    AnswerLabel.Text = "Good Job!"
    WrongInteger += 1
    AnswerLabel.Text = "Sorry Wrong Answer"
    End If
    RightAnswerLabel.Text = RightInteger.ToString("N0")
    WrongAnswerLabel.Text = WrongInteger.ToString("N0")
    AnswerLabelTimer.Enabled = True
    Catch ex As Exception

    End Try
    End Sub

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
    ' Clears Solution TexBox.

    With SolutionTextBox
    End With
    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
    ' Terminates the program

    End Sub

    Private Sub AnswerLabelTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnswerLabelTimer.Tick
    ' Clear AnswerLabel.

    AnswerLabel.Text = ""
    End Sub

    Still need to finish the catch statement and delete the ClearButton_Click method other than that it works good counter and all ^^
    Feel free to pick it apart and tell me a better way to do something.
  18. UGRev

    UGRev Get on with it!

    Command Pattern: Command Design Pattern in C# and VB.NET.
    Take a look at the sample calc code on that site. It's at the bottom in the sample code section.

    This demonstrates how to execute an operation based on the operand given.
  19. If you click the "Show Code" for VB.Net it brings up a program to buy or download :/
  20. UGRev

    UGRev Get on with it!

    click the one above that ;) Real world example is what it's labeled ;)
survivalmonkey SSL seal warrant canary