Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

What Is/are The Code(s) For These?


  • Please log in to reply
6 replies to this topic

#1 f1f2

f1f2

  • Members
  • 14 posts
  • OFFLINE
  •  
  • Local time:06:42 AM

Posted 06 January 2007 - 11:23 PM

A program that contains a text box and a command button.
Put a label above the text box that tells the user to type a number from 1 to 10.
When the user clicks the command button, check the text box for a valid number and issue an error message box if the number isn't inside the expected range.
If the user entered a valid number, use a For loop to print asterisk(s) (*) in the form equal to the number entered in the text box.

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:42 AM

Posted 07 January 2007 - 11:28 PM

Sounds an awful lot like a homework assignment. Which part are you having trouble with?

#3 projectfocus

projectfocus

  • Members
  • 474 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Brighton
  • Local time:12:42 PM

Posted 08 January 2007 - 06:41 AM

If you need some specific help I have no problem in helping if you provide the sample code you have. Please also advise what language you are looking to do this in. I gather it is a object related language. Please advise the program in which you aredoing this within.
Posted Image

#4 f1f2

f1f2
  • Topic Starter

  • Members
  • 14 posts
  • OFFLINE
  •  
  • Local time:06:42 AM

Posted 08 January 2007 - 08:08 AM

Oooppsss, sorry for the late reply.. I'm using VB :thumbsup:

And for the code, I think this is right: (it's what I've come up with)

Private Sub Command1_Click()
Dim x As Integer, y As Integer
x = CInt(Text1.Text)
If (x >= 1) And (x <= 10) Then
For y = 1 To x
Form1.Print "*"
Next
Else
MsgBox "WRONG"
End If
End Sub

Please, correct me if I'm wrong.

#5 projectfocus

projectfocus

  • Members
  • 474 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Brighton
  • Local time:12:42 PM

Posted 08 January 2007 - 08:58 AM

I personally would do it like this

Private Sub Command1_Click()
Dim x,y As Integer
y=0
x = CInt(Text1.value)
If (x >= 1) And (x <= 10) Then
Do
Form1.Print "*"
y=y+1
Loop Until y=x
Else
MsgBox ("Invalid Entry, Please enter a Number Between 1 & 10")
End If
End Sub


I would also add a object in form1 so that you can change the value of a text box to match the amount of *'s. This would look better that using the print function.

I hope this helps.

Edited by projectfocus, 08 January 2007 - 09:03 AM.

Posted Image

#6 projectfocus

projectfocus

  • Members
  • 474 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Brighton
  • Local time:12:42 PM

Posted 08 January 2007 - 09:05 AM

Or even simpler option would be only use 1 variable. Like this

Private Sub Command1_Click()
Dim x As Integer
x = CInt(Text1.value)
If (x >= 1) And (x <= 10) Then
Do
Form1.Print "*"
x=x-1
Loop Until x=0
Else
MsgBox ("Invalid Entry, Please enter a Number Between 1 & 10")
End If
End Sub
Posted Image

#7 f1f2

f1f2
  • Topic Starter

  • Members
  • 14 posts
  • OFFLINE
  •  
  • Local time:06:42 AM

Posted 15 January 2007 - 05:29 AM

okay, thanks... i have another :thumbsup:

A program that prints these stuff:

1
12
123
1234
12345
123456
1234567
12345678
123456789




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users