Results 1 to 12 of 12

Thread: visual basic home assignment help?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    visual basic home assignment help?

    hey everyone,
    i have a visual basic assignment and im totally lost.
    im supposed to create a program in the form type. its supposed to ask the user for a number so i created a textbox for the entry for the number in the form and a button to execute the program. then the program prints a number of "$$$$$" dollar signs as the entered number. furthermore, only upto 5 "$$$$$" sings should be in a row. oh and i have to use the for-loop for this. i used to be do this when i did qbasic but i have completely forgotten the codes and syntax, etc. could anybody please write a program for this?
    thanks in advance

  2. #2
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: visual basic home assignment help?

    not understanding the requirement.
    if I type in the number 4, it will display "$$$$" in the textbox?
    and 5 is the highest number I can enter?

    assuming the above is correct,
    you could do:

    *disclaimer* As a homework assignment, there is no doubt in my mind you will assigned more difficult problems and you are doing yourself a disservice by not reading the textbook (unless you're like me and don't buy textbooks based on principle )

    vb Code:
    1. Dim usersNumber As Integer 'Class level variable at top of program
    2.  
    3. 'This goes in the button's Click Event
    4. Try
    5.      usersNumber = Integer.TryParse(Textbox1.Text)
    6. Catch ex as exception
    7.      msgbox("Please enter a number.")
    8. End Try
    9.  
    10. if usersNumber > 0 and usersNumber < 6 Then
    11.      Dim output as String
    12.      for i as Integer = 1 to usersNumber
    13.           output &= "$"
    14.      loop
    15. Else
    16.      Msgbox("Please enter a number greater than 0 and less than 6")
    17. End If

    That should get you started.
    It doesn't test for if they enter letters though, so if that is a requirement, it will need to be implemented.

  3. #3
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: visual basic home assignment help?

    Hey Alyssa... If we wrote the program for you then you wouldn't learn a thing . If you have to write $ depending on the number written by the user and using the for loop, you should create a loop that starts at number 1 and goes up to the number written and, with each count, it should write a $.

    Check out this msdn documentation to learn how to use the for...next loop and this is for the do...loop.

    Hope it helps

    @stateofidleness: I think it's just a simple loop assignment, shouldn't be THAT complicated.
    Last edited by tassa; Jul 3rd, 2009 at 12:28 AM.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: visual basic home assignment help?

    it eliminates the "copy & paste" attractiveness. it will require some thought and actually reading the code to understand it and "dumb it down" so the teacher knows it wasn't provided by a good-looking forum member hehe

  5. #5
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: visual basic home assignment help?

    Quote Originally Posted by stateofidleness View Post
    it eliminates the "copy & paste" attractiveness. it will require some thought and actually reading the code to understand it and "dumb it down" so the teacher knows it wasn't provided by a good-looking forum member hehe
    Aww, I'm trying to make her think too, so that makes me a good-looking member too lol... I just had the notion that she just started programming, that's why I said it. Either way, it helps her learn .

    And I think she mean the For...Next loop, because right there you just mixed the Do...Loop and the For...Next loop, lol .
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    Re: visual basic home assignment help?

    thanks ya'll. my bad, i meant the for-next loop.
    and btw i made a seperate label box to display the answer.
    and to sateofidleness. im gonna try to be more specific. for instance, the user enters the number 23.
    then the screen shows.
    $$$$$
    $$$$$
    $$$$$
    $$$$$
    $$$
    only 5 characters per row yeah?
    im farily new to this so im having a hard time understanding the questions and an even harder time explaining them.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: visual basic home assignment help?

    try this:

    vb Code:
    1. Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
    2.     Dim dollarString As String = ""
    3.     For x As Integer = 1 To 5 - TextBox3.Text.Replace("$", "").Length
    4.         dollarString &= "$"
    5.     Next
    6.     TextBox3.Text = dollarString & TextBox3.Text.Replace("$", "")
    7.     TextBox3.SelectionStart = 5
    8. End Sub

  8. #8
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: visual basic home assignment help?

    paul is amazing. i was toying with it and my code was about doubled that running a nested for loop.
    I need to learn that String manipulation stuff a bit better, but I never use it much.

  9. #9
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: visual basic home assignment help?

    Hey... I was bored and I came up with this code to do what she says... I know it's long, but it's the only way I could think of doing it...

    vb.net Code:
    1. Private Sub Button1_Click _
    2.     (ByVal sender As System.Object, ByVal e As System.EventArgs) _
    3.     Handles Button1.Click
    4.         ListBox1.Items.Clear()
    5.         Dim dollarString As String = ""
    6.         Dim limit As Integer = 0
    7.         Integer.TryParse(TextBox1.Text, limit)
    8.         For x As Integer = 1 To limit
    9.             dollarString &= "$"
    10.             If x Mod 5 = 0 Then
    11.                 ListBox1.Items.Add(dollarString)
    12.                 dollarString = String.Empty
    13.             End If
    14.         Next
    15.         Dim SplitChar As String
    16.         Dim dollar As String = ""
    17.         SplitChar = Mid(CStr(limit).Trim, limit.ToString.Length, 1)
    18.         If SplitChar >= 1 And SplitChar <= 4 Then
    19.             For i As Integer = 1 To SplitChar
    20.                 dollar &= "$"
    21.             Next
    22.             ListBox1.Items.Add(dollar)
    23.         ElseIf SplitChar >= 6 And SplitChar <= 9 Then
    24.             For i As Integer = 1 To SplitChar - 5
    25.                 dollar &= "$"
    26.             Next
    27.             ListBox1.Items.Add(dollar)
    28.         End If
    29.     End Sub
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: visual basic home assignment help?

    PLENTY of ways to do same thing.
    Code:
    dim cl#
    for cl = 1 to val(textbox1.text)
    textbox2.text = textbox2.text + "$"
    if cl / 5 = cl \ 5 then textbox2.text = textbox2.text + vbcrlf
    next cl
    i am actually surprised they are teaching this in .net
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    3

    Re: visual basic home assignment help?

    thanks a bunch everyone, lord orwell's solution seemed shorter though.
    and now i shall try and learn some syntax.

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: visual basic home assignment help?

    shorter isn't necessarily better. Paul's actually erases old entrys for you. And if you don't understand how the code works, you won't pass if the teacher asks you how it works, which they will, if you demonstrate coding you haven't in the past coupled with whether or not they've taught that particular way of doing something in class.

    for example, your teacher probably doesn't even know what the purpose of this is:
    if cl/5 = cl\5
    using division with \ rounds the answer off. This basically checks to see if cl is evenly dividable by 5 and if so, adds a carriage return.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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