looping. using for next..

i dont understand it really

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1594 Views - Last Post: 24 November 2008 - 04:53 AM Rate Topic: -----

#1 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

looping. using for next..

Post icon  Posted 20 November 2008 - 05:27 AM

hey.. can you help me to do codes of this.. if you put "4" on the textbox1 and "b". then when i click the cmdbutton. the output will be...

1
b
2
b
b
3
b
b
b
4
b
b
b
b



can you help me with this?..
i really dont know what codes to use in here.. my instructor said that i'll use For..Next.
i dont understand it when he discuss it.. i just know Do While and Do Until..
so can you please help me.. i'll edit my post when my instructor tells me some codes to do with it.. thnx in advance

This post has been edited by useletters: 20 November 2008 - 05:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: looping. using for next..

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,059
  • Joined: 04-January 08

Re: looping. using for next..

Posted 20 November 2008 - 06:03 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 109
  • View blog
  • Posts: 1,530
  • Joined: 25-January 07

Re: looping. using for next..

Posted 20 November 2008 - 06:15 AM

Well, it's not too difficult to get tutorials about how to use For loop in VB.
I tried that and I got millions of results. :)
For a start this can be one of them when you search it.
Was This Post Helpful? 0
  • +
  • -

#4 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 21 November 2008 - 01:16 AM

here.. but i think its so far!!!
Dim a, b As Variant
a = Val(txtletter.Text)
b = Val(txtnumber.Text)
For b = 1 To 10 Step 1
Print b
b = b + 1
Print a
Next


see attached thumbnail for output.. please help..

Attached image(s)

  • Attached Image

This post has been edited by born2c0de: 21 November 2008 - 03:01 AM

Was This Post Helpful? 0
  • +
  • -

#5 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: looping. using for next..

Posted 21 November 2008 - 03:15 AM

Quote

Dim a, b As Variant

Avoid using Variants in your programs as far as possible.
Change this to:
Dim a As String
Dim b As Integer


Quote

a = Val(txtletter.Text)

You don't need to convert this into a number because you are displaying a character on the Form. Simply remove the Val() function call:
a = txtletter.Text


For b = 1 To 10 Step 1
Print b
b = b + 1
Print aNext

You can add the extra increment in the loop definition itself like this:
For b = 1 to 10 Step 2


You will find it easier to write this code in a nested loop like this:
Dim i as Integer, j as Integer
For i = 1 to 10 Step 2
   Print i
   For j = 1 to i
      Print a ; a should contain the character from txtletter
   Next j
Next i


Hope this helps you :).
Was This Post Helpful? 0
  • +
  • -

#6 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 21 November 2008 - 03:38 AM

yes it apply but.. if you put 3 on txtnumber. it just print..

3
a
a
a
.. i need the code for..
1
a
2
a
a
3
a
a
a
the code that it counts from 1 to the given number in txtnumber.text..
and thnx for this.. this may help me..i'll modify the code you gave,,
thank you again..

EDIT:

here.. i modified the codes you gave..
Dim i As Integer, j As Integer
a = txtletter.Text
i = txtnumber.Text
	For i = 1 To 10 Step 1
	Print i
	For j = 1 To i
	Print a
	Next j
	Next i

but look at the output

Attached image(s)

  • Attached Image

This post has been edited by useletters: 21 November 2008 - 03:44 AM

Was This Post Helpful? 0
  • +
  • -

#7 Fhulu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 18-November 08

Re: looping. using for next..

Posted 21 November 2008 - 04:07 AM

Dim Lpnmb As Integer
Dim nLp As Integer
Dim Lplter As String

Private Sub Command1_Click()
	For Lpnmb = 1 To Val(Text1.Text) 'This will set the min and max limits for your looping number
		Print Lpnmb 'This will print the group number for each group of "b"s
		For nLp = 1 To Lpnmb 'Number of "b"s to be printed
			Print Text2.Text 'This prints a group of "b"s you entered from 1 to the group number
		Next 'Tells the "For...next" to print next group letter
	Next 'Tells the "For...next" to print next group number
End Sub



1.On your form: text1 is for a number and Text2 is for the letter you will enter.
2.Command1 is the one you click.
3.Run It It works the way you want!

4.Any way I did my Best and dream.In.Code
5.Enjoy Our Company! "Fhulu"
Was This Post Helpful? 0
  • +
  • -

#8 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 21 November 2008 - 07:19 AM

fhulu!!. THANK YOU VERY MUCH.. now my assignment is DONE. but

what code can i use to clear the form1??.
so i can remove the printed texts,,
Was This Post Helpful? 0
  • +
  • -

#9 Fhulu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 18-November 08

Re: looping. using for next..

Posted 21 November 2008 - 07:50 AM

Is my plesure useletters!

is here is the clear form code. I just added "me.cls" to the previous code and
it will clear the form's printed text.

Dim Lpnmb As Integer
Dim nLp As Integer
Dim Lplter As String

Private Sub Command1_Click()
   me.cls   'This code will clear the form evry time you click the btn.
   For Lpnmb = 1 To Val(Text1.Text) 'This will set the min and max limits for your looping number
		Print Lpnmb 'This will print the group number for each group of "b"s
		For nLp = 1 To Lpnmb 'Number of "b"s to be printed
			Print Text2.Text 'This prints a group of "b"s you entered from 1 to the group number
		Next 'Tells the "For...next" to print next group letter
	Next 'Tells the "For...next" to print next group number
End Sub


Was This Post Helpful? 0
  • +
  • -

#10 Fhulu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 18-November 08

Re: looping. using for next..

Posted 21 November 2008 - 08:00 AM

'useletters it is also possible to place the code on the click event of onther button(command2)
'Example:
Private sub command2_Click()
	me.cls
End sub



'Every time when you click this button the form's printed text will be cleared!
'Sharp! useletters
Was This Post Helpful? 0
  • +
  • -

#11 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 21 November 2008 - 06:05 PM

THNX again!.. now.. i need to design my assignment.. :D

i know that VB dont have the onmouseover() thingy.. what code can i use in place of it?.. can i use onmousedown()?
Was This Post Helpful? 0
  • +
  • -

#12 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 22 November 2008 - 02:05 AM

and btw.. how to make a box with Yes or No button.. like if yes.. = end.. else cancel or anything like that..
Private Sub Command2_Click()
MsgBox "Are You Sure?", vbYesNo, "Are You Sure?"
If response = yes Then
	End
	Else
	Cancel
End If
End Sub

i tried that but if i click yes or no.. it doesnt cancel..
the cancel thing doesnt work..
Was This Post Helpful? 0
  • +
  • -

#13 Fhulu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 18-November 08

Re: looping. using for next..

Posted 22 November 2008 - 08:48 AM

'===========================
'Hi useletters, I went out today for shopping i am sorry to be late for the class(Lessons)
'===========================

'You don't have to worry about this vb things it will come ok as you keep
'practising. Just keep going coding eploring books help files forums and other sources this will
'possible increase your understanding in VB
'One more other thing is that you need to give yourself a task say a project for designing
'a pary roll system this will lead you to a number of questions of how to... . and the how to...
'questions will lead to a good programer.
'Get more project to develop in vb as this is important for a fast growing knowledge and experiance.
'Good Luck!



'Question1
'------------------------------------------------------------------------
'Yes VB does have the "MouseMove(...)" thing not the "onmouseover() thing
'We only you this event with the intation of traping the mouse move over a specific object
' Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'codes here .....
' End Sub
'end sub
'-------------------------------------------------------------------------

'Question2
'-------------------------------------------------------------------------

Private Sub Command1_Click()
	Unload Me
	Set Form1 = Nothing
End Sub



'Here is your code below
'The code for the "vbYesNo" is simple you where just close to the solution, anyway you tried your best.

'Corrections
'1. It is better not to use the "End" command to close the form instead we use the following
'1.1 "Unload me" which will remove the form from the memory
'1.2 "Set Form1 = nothing this will destroy the form object
'1.3 the "End" command can somtimes lead your program to crush or continue running even you closed the form
'2. The code you gave need to be place on the form unload event
'3. This will help to control the form from closing even if the form is close from the top-right red button
'but if you place the code on the button click event the code will not work with the red close button of the form.
'4. The last thing you cannot use the cancel thing on the button event because is not even declared but in the form unload is declared as:Form_Unload(Cancel As Integer)
Private Sub Form_Unload(Cancel As Integer)  'the form unload event with a Cancel declaration
	If MsgBox("Are You Sure?", vbYesNo, "Are You Sure?") = vbNo Then
		Cancel = 1 'The action will be cancelled if you cliked on the no button else the form will close
	End If
	'Notice i never placed the "else" thing because the form is already on the action of closing
	'so why the "else" thing
	'We only have to be able to stop it from closing!
End Sub



'------------------------------------------------------------------------
Was This Post Helpful? 0
  • +
  • -

#14 Fhulu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 18-November 08

Re: looping. using for next..

Posted 22 November 2008 - 08:56 AM

'Let us now put some spicy on the obove codes
'You see for us to make the "vbYesNo" better we need to add: vbInformation; vbExclamation Or vbCritical...

'For example:
Private Sub Form_Unload(Cancel As Integer)  'the form unload event with a Cancel declaration
	If MsgBox("Are You Sure?", vbYesNo + vbExclamation, "Are You Sure?") = vbNo Then
		Cancel = 1 'The action will be cancelled if you cliked on the no button else the form will close
	End If
	'Notice i never placed the "else" thing because the form is already on the action of closing
	'so why the "else" thing
	'We only have to be able to stop it from closing!
End Sub



'I only added "vbYesNo + vbExclamation" to make a message with the Exclamation beep.
Was This Post Helpful? 0
  • +
  • -

#15 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: looping. using for next..

Posted 22 November 2008 - 11:25 PM

oh!.. thats why.. i didnt declare the cancel.. thats why it doesnt work.. and.. THANK YOU VERY MUCH for helping me!!..
now i need to design my assignment. :D

btw.. how can i put that code in Command1?

Private Sub Command2_Click(Cancel as Integer)
	If MsgBox("Are You Sure?", vbYesNo + vbExclamation, "Are You Sure?") = vbNo Then
		   Cancel = 1
	End If
End Sub


but it doesnt work..

and here's my program.. (that you helped me with.. :D)
http://h1.ripway.com...0/project/l.frm ]Program.. unfinished[/url]

and btw.. how can i prevent erroring when clicking print without number and letter on text1 and text2.. and try click end.. it doesnt work..
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2