|
-
Jul 3rd, 2009, 12:05 AM
#1
Thread Starter
New Member
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
-
Jul 3rd, 2009, 12:22 AM
#2
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:
Dim usersNumber As Integer 'Class level variable at top of program 'This goes in the button's Click Event Try usersNumber = Integer.TryParse(Textbox1.Text) Catch ex as exception msgbox("Please enter a number.") End Try if usersNumber > 0 and usersNumber < 6 Then Dim output as String for i as Integer = 1 to usersNumber output &= "$" loop Else Msgbox("Please enter a number greater than 0 and less than 6") 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.
Last edited by stateofidleness; Jul 3rd, 2009 at 12:27 AM.
-
Jul 3rd, 2009, 12:24 AM
#3
Fanatic Member
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.
-
Jul 3rd, 2009, 12:29 AM
#4
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
-
Jul 3rd, 2009, 12:36 AM
#5
Fanatic Member
Re: visual basic home assignment help?
 Originally Posted by stateofidleness
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 .
-
Jul 3rd, 2009, 10:59 AM
#6
Thread Starter
New Member
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.
-
Jul 3rd, 2009, 11:18 AM
#7
Re: visual basic home assignment help?
try this:
vb Code:
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
Dim dollarString As String = ""
For x As Integer = 1 To 5 - TextBox3.Text.Replace("$", "").Length
dollarString &= "$"
Next
TextBox3.Text = dollarString & TextBox3.Text.Replace("$", "")
TextBox3.SelectionStart = 5
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 3rd, 2009, 11:38 AM
#8
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.
-
Jul 3rd, 2009, 02:56 PM
#9
Fanatic Member
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:
Private Sub Button1_Click _ (ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click ListBox1.Items.Clear() Dim dollarString As String = "" Dim limit As Integer = 0 Integer.TryParse(TextBox1.Text, limit) For x As Integer = 1 To limit dollarString &= "$" If x Mod 5 = 0 Then ListBox1.Items.Add(dollarString) dollarString = String.Empty End If Next Dim SplitChar As String Dim dollar As String = "" SplitChar = Mid(CStr(limit).Trim, limit.ToString.Length, 1) If SplitChar >= 1 And SplitChar <= 4 Then For i As Integer = 1 To SplitChar dollar &= "$" Next ListBox1.Items.Add(dollar) ElseIf SplitChar >= 6 And SplitChar <= 9 Then For i As Integer = 1 To SplitChar - 5 dollar &= "$" Next ListBox1.Items.Add(dollar) End If End Sub
-
Jul 3rd, 2009, 07:11 PM
#10
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
-
Jul 4th, 2009, 12:12 AM
#11
Thread Starter
New Member
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.
-
Jul 4th, 2009, 07:31 AM
#12
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|