This pseudo code will print out: 1, 1, 2, 3, 5, 8, 13, 21, ... as expected. But now how do we tell a Visual Basic program how to do this? The answer lies in using loops.
Loops provide the ability to repeatedly execute the same block of code, and to each time change values such that each run through the loop produces different results. Visual Basic provides four main kinds of loops: the classic Do-Loop, the Do-Until Loop, the Do-While Loop, and the For-Next Loop.
Do-Loops
The most basic form of loop in Visual Basic is the Do-Loop. Its construct is very simple:
Do
(Code to execute)
Loop
This, quite simply, executes the block of code, and when it reaches Loop, returns to the beginning of the Do Loop and executes the same block of code again. The same block of code will be repeatedly executed until it is told to stop executing. So let's try to apply this to our problem of generating the Fibonacci series:
Dim X As Integer Dim Y As Integer Do Debug.Print X X = Y + X Y = X - Y Loop
And, believe it or not, this code works! Well, sorta. If you try to run this code, it will indeed generate the Fibonacci series; however, it will continually generate and print out the next number infinitely--or, in this case, until it reaches an overflow error. This is known as the problem of the infinite do-loop, one that all programmers will experience, and some quite frequently.
Exit Do
So we clearly need some way to escape from the Do-Loop. You could, of course, simply End the program once you have calculated enough values, but what if you still need to perform tasks after you're done calculating? The answer is to use the Exit Do statement. Whenever your program reaches an Exit Do statement within a loop, it will exit the current loop.
So, let's try a somewhat different approach to the Fibonacci problem. We decide that we want to calculate only eight values of the Fibonacci series, so we'll keep a counter and increment it each time throughout the loop. Then, once the counter reaches eight, we'll exit the loop.
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Debug.Print X X = Y + X Y = X - Y If cnt >= 8 Then Exit Do Else cnt = cnt + 1 End If Loop End Sub
And now we're talking! This program successfully computes and prints out the first eight values of the Fibonacci series.
Do Until
As an alternative approach to nesting an If-Statement inside the loop, and invoking Exit Do once we're done looping, Visual Basic provides a Do Until statement. Its syntax is the following:
Do Until (Expression)
(Code to execute)
Loop
(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit the loop. Each time the program reaches Loop it will evaluate this expression. If the expression is True, it will exit the loop for us, but otherwise it will continue looping.. So let's try rewriting our Fibonacci program to use a Do-Until loop instead of Exit Do.
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Until cnt >= 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub
Here we've replaced the hideous If cnt >= 8 Then ... Else: Exit Do with a very simple Until cnt >= 8. We must, however, still be sure to increment our counter every time through the loop, or else the Until expression will never be True, resulting in an infinite Do Loop.
Do While
In the place of Do Until, you can also use Do While. Its syntax is the following:
Do While (Expression)
(Code to execute)
Loop
(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit the loop. Each time the program reaches Loop it will verify that this expression is True, and if it is False, it will exit the loop for us. Thus, instead of exiting when an expression is True, it now exits only once this expression is false. Let's try rewriting our Fibonacci program to use a Do-While loop instead of a Do-Until loop.
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do While cnt < 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub
For-Next Loops
In situations where you merely want to run the loop a predefined number of times, it can become quite tiresome to have to create and manage a counter for each loop, which is why we also have something called a For-Next Loop. This kind of loop allows you to specify a counter, to tell it to count from one number to another each time through the loop, and to exit once the counter has reached its upper limit. The syntax is as follow:
Dim I As IntegerWe used the variable name "I" above, as it is the most common name used for For-Loops; however, you can use any variable name you want, so long as the variable is of the type Integer. Now, let's improve our Fibonacci program even further:
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. For cnt = 1 To 8 Debug.Print X X = Y + X Y = X - Y Loop End Sub
In the example above, we first dimensioned cnt as an Integer, and then, in the declaration of the For-Next loop, set its value to 1. Each time through the loop, the value of cnt was incremented by 1 until it reached 8, at which point the loop was executed.
Exit For
As with Do Loops, there is a statement that can be used to exit a For-Next loop, and it is called Exit For. Simply invoke this statement anywhere within a For-Next loop and the current loop will be exited.
Step
By default, the variable used in the declaration of the For-Next loop is incremented by 1 each time through the loop; however, if you want to increment this value by a different amount each time through the loop, you can simply append Step (Integer) to the end of the For-Next loop declaration. If, for instance, we wanted to print out every even number counting backward from 20 to 0, we could do this using the following code:
Dim I As Integer For I = 20 To 0 Step -2 Debug.Print I Next I
So there you have it now you can use loops all over your Visaul Basic 6 programs. These are one of the most useful tools you have. You might want to bookmark this tutorial so that later you can reference back to this great VB6 loop examples. If you have any questions or comments please post them below.
Programming
Write a program in java to print the tables of numbers up till 10. Ask the user up till what number does he/she wants to print the tables for? Then print the tables starting from 1 until the user given number. One line should contain only one table
visual basic
i need help.
how do i code my program
with the required outputs:
1st)
123456789
12345678
1234567
123456
12345
1234
123
12
1
2nd)
1
12
123
1234
12345
123456
1234567
12345678
123456789
3rd)
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
and last)
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
pleas help
create a script that will determine a positive number, negative number, if the number is less than 100 and if the number is greater than 100 and will ask if you want to start again before terminating.
Help Please?
Write a VB.NET program that calculates the sum of all the numbers between 1 and 100 that are divisible by 5 or 6 but not both.
Numbers divisible by 5 between 1 and 100 are:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100
Numbers divisible by 6 between 1 and 100 are:
6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96
So numbers between 1 and 100 that are divisible by 5 or 6 but not both are:
5, 6, 10, 12, 15, 18, 20, 24, 25, 35,
36, 40, 42, 45, 48, 50, 54, 55, 65, 66,
70, 72, 75, 78, 80, 84, 85, 95, 96, 100
C++ language
i want help
solve for me
7 programs without errors
by taking help from control structures in C++
1. write a program that accepts input four numbers and get the summation of even numbers only
2. write a program to test a number for being odd or not
3. write a program to ask for a password, and it check it with a saved password, it will return “Authorized” if the password match or “Unauthorized” if the password does not match
4.write a program to find the factorial of a number
5.Write a program to find the minimum of three numbers.
6.Write a program that accepts entry only positive numbers, if you enter negative number it will give an error message (unaccepted), the program will stop when you enter 10 positive numbers.
7.Write a program that prints the number in revise order, for example if you enter 1456, the program will print 6541. (Hint: you are to use modulus % and division / operators)
you will need to use control structures to solve the questions
First Solution
#includeusing namespace std;
int main()
{
int sum = 0, temp = 0;
for (int i = 0; i < 4; i++)
{
cout<<"Please enter number "<>temp;
if (temp % 2 == 0)
sum += temp;
}
cout<
Didnt work too well because
Didnt work too well because of code tags... sorry.
Hmm
First Off, do your own homework.
That is all
c free
Write a program in C that will ask from the user to enter a number between 1 and 5. While
the user doesn’t enter a number within this range, the program should repeatedly ask for
the number until the number is within the valid range. Then the program should print the
corresponding output based on the following table. Use the switch statement.
can you help me pls
PRIME NUMBER!!!
Hey all :)
i want a program in vb.net gives a prime number and the (GCD) and (SCM) as soon as possible pleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaase :))
please solve this project by for loop including "if"
write a program that calculates the min ,max and average a set of numbers . the size of that set should be received from the user at the beginning of the execution .
Done!
Here you are:
Option Explicit
Dim C As Integer, I As Integer
Dim Num As Long, SumN As Long, MaxN As Long, MinN As Long
Private Sub Form_Activate()
C = InputBox("How many numbers?", "Numbers")
For I = 1 To C
Num = InputBox("Enter the " & I & " number:", "Numbers")
If I = 1 Then
MinN = Num
MaxN = Num
Else
If Num < MinN Then
MinN = Num
ElseIf Num > MaxN Then
MaxN = Num
End If
End If
SumN = SumN + Num
Print Num
Next
Print "The max number was: " & MaxN
Print "The min number was: " & MinN
Print "The average of the numbers was: " & SumN / C
End Sub
whileloop
which a except a number and to find it square except user input that is the user whileloop is continue it find the square of another numbers.please slove this program right now its very importan for me.
alghorithm c++ for prime numbers
hi i need help i have to make proghram c++ for prime numbers like this
enter starting value: 1
enter ending value:10
2,3,5,7
minimum:2
maximum:7
average:17/4
plz i need help for write program c++
C++
Plz help..........
Help me..........
Q # Write a program that reads numbers repeatedly until 0 (zero) is entered, find and display the smallest and largest number. Use while loop statement.
03365961262
C++
Plz help..........
Help me..........
Q # Write a program that reads numbers repeatedly until 0 (zero) is entered, find and display the smallest and largest number. Use while loop statement.
03365961262
request
please dont change the captions you fools
Program
I know this doesn't have to with VB 6.0, yet VB 2010. Not too much about understanding For, Do, and while Loops either, but it does a little bit. I need to enter a program using option Explicit and Strict,Do Loop, Use of the console (No input boxes or message boxes), Console Clear command, Use of sentinel value, Counter Accumulator, and If statement. The situation is that I have to create a program that prompts the user to enter a series of numbers. When the user want to stop, have them enter in a "-1" to end the input. Afterwards, the program should then display the largest number, smallest number, and the average of all the numbers. Please help me out with the code! I found out a way to do average with this code: Dim iCounter As Integer
Dim dGrade As Double
Dim dTotalGrade As Double
dGrade = 0
iCounter = 0
dTotalGrade = 0
Console.Write("Enter Grade or -1 to Exit")
dGrade = CDbl(Console.ReadLine())
Do Until (dGrade = -1)
dTotalGrade = dTotalGrade + dGrade
iCounter = iCounter + 1
Console.Write("Enter Grade or -1 to Exit")
dGrade = CDbl(Console.ReadLine())
Loop
Console.WriteLine("Your Average is : " & _
CStr(dTotalGrade / iCounter))
Not sure if that is right so I really need help guys and would really appreciate it!
visual basic 2010 for -next loop please help
i just need help in coding the for loop. here's the problem. a financier wishes to have a program that will calculate the amount of money in an interest bearing account after a given number of years. the program needs to be written so that the user can input the ff. four data: initial deposit, annual interest rate, number of years, number of compounds per year (including "c" for continuous). upon pressing the calculate button, the program should report the total in the account after each year up to the given number of years. this information should be shown in the list box. the interest rate may be given as a decimal or a percent. the program should handle both. use the following formula: pt = p0 (1+r/n)^nt for a countable number of compounds, pt=p0e^rt for continuous compounding. where p0 is the initial deposit, pt is the year, r is the interest rate, n annual number of compound. thanks so much for any help. i'm so confused on how to code the exponent .
helppp mee :'(
plllz I need it tomorrow before 11 pm :(:(
plz help =((
Writing Programs Problems:
a.write a program that reads N and prints the sum and average of all integers from 1 to N
Example:
Enter a number : 6
The sum from 1 to 6 = 21
The average from 1 to 6 = 3.5
b.Write a program that asks the user to enter 10 integers and writes the smallest value.
c.Write a program that reads in the side of a square and prints the square out of asterisks. Your program should work for square of all sizes between 1 and 20, when the user enter other sizes the program should display an error message.
for example: when the user enter 4
the output:
****
****
****
****
d.Write a program that prints an isosceles triangle on 5 lines.
*
***
*****
*******
*********
e.Write a program that reads a set of integers, and then finds and prints the sum of the even and odd integers.
Please help .... thanks =(
for the triangle: dim star as
for the triangle:
dim star as string="*"
for i as integer=1 to 5
listbox1.items.add(star)
star=star+"**"
next
for the square:
Dim size As Integer
size = InputBox("enter size of square between 1 and 20")
If size < 1 Or size > 20 Then
MsgBox("error")
size = InputBox("enter size of square between 1 and 20")
End If
Dim row As String = ""
Dim column As Integer = size
For j As Integer = 1 To size
row = row + "*"
Next
For k As Integer = 1 To column
ListBox2.Items.Add(row)
Next
for section A: Dim num As
for section A:
Dim num As Integer = 0
num = InputBox("enter a anumber")
Dim a(num) As Integer
Dim divby As Integer = num
Dim sum As Integer = 0
For i As Integer = 1 To num - 1
a(num) = i + 1
Next
For j As Integer = num To 0 Step -1
sum = sum + j
Next
ListBox3.Items.Add("sum is: " & sum)
Dim avg As Double
avg = sum / divby
ListBox3.Items.Add("avg is: " & avg)
#include int main() { int
#include
int main()
{
int i,j,n;
printf("\n raws");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
{
printf("\n);
return 0;
}
}
hw plllllllllllllz help
Write the Visual Basic language contains:
1 - student class contains:
• variable h in a matrix (The decision)
• a variable course in matrix (for the storage decisions)
• record function that allows the student to be registered and breathing
• branches of the student class studcomp contains a function record for the number of hours recorded by the student's courses and inform him if he passed the hours available for registration or not (the maximum recording hours 20 hours), if exceeded ask him to delete the extra hours and if not beyond achievement for the number of hours remaining recorded by him to
• When you press the button to add a decision to allow the student to be registered if it does not exceed the hours specified.
• In the Print function key materials and recorded hours and hours you lived to the selected or not
Max, min and avg of a list box
I could really use some help writing code for a program that takes the max, min and avg of numbers in a list box and sends them each to labels.
Any help would be greatly appreciated, Thanks!
hw vb
please i need ur help in my homework. am new in vb!
Problem 1:
Develop an application which accepts a positive integer value from the user and outputs the sum of all odd integers between 0 and the given integer.
Note: for problem 1, you might use a console application.
Problem 2:
Put two textboxes on your form. The first box asks users to enter a start position for a For Loop; the second textbox asks user to enter an end position for the For loop. When a button is clicked, the program will add up the numbers between the start position and the end position. Display the answer in a message box.
LOOPING
Good Day Sirs / Ma'ams,
I have this problem in looping in VB 6.. The process is I want to make a condition that would check a PC if it is vacant or not : If it is not, it will proceed to another PC (increment); If it is vacant, it will automatically display the first number or slot that it found. Can you help me with it ? I would very much appreciate it.. THANK YOU in advance.
help
i have to make a fortune teller program for an assignment i i need help i want to display different messages depending on if the user is male or female and i need to know if i can use two loops on one function. but i'm getting both messages displayed at the same time please help me this is what i have so far:
Private Sub btnFortune_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFortune.Click
Dim female As Boolean
Dim male As Boolean
Do
female = True And male = True
If (txtEntNum1.Text >= 6) Then
female = True And male = False
MsgBox("Your fortune is that you will have a good job earning lots of money within the next 10 years. Enjoy ")
End If
If (txtEntNum1.Text <= 5) Then
female = True And male = False
MsgBox("Your fortune is that you will win the lottery this time next week! ")
End If
Loop While female = False And male = True
Do
male = True And female = True
If (txtEntNum1.Text >= 6) Then
male = True And female = False
MsgBox("Your fortune is that you will be in trouble next week with your boss ")
End If
If (txtEntNum1.Text <= 5) Then
male = True And female = False
MsgBox("Your fortune is that you will eat a cake tommorow! ")
End If
Loop While male = False And female = True
End Sub
VISUAL BASIC 6
HELP! I made a program that allows me to input as much integers I have and then the teacher tells us to get the AVERAGE. how am i going to get the average? *Visual Basic* In C, i will use counter... Is there such thing as counter in VB6???
and!!
how do i make a program using do-while loop or do-loop-while that looks for the HIGHEST number i inputted and then counts how many times I clicked it and in the end display the results in the text box and msgbox?????? STILL VB6
finding max and min of gross pay
Im having problems to finding out the answer to this and I hope someone can help me along. Basically I want to find out the max and min of 6 peoples wages. I have already calculated the wages for each person from a streamreader txt file using a do while and some if statements. That was the easy part but now I need to find out what is the max wage and the min wage.
Any suggestions would be greatly appreciated.
Thank you
How to find student in a school n after that how to find his mks
Please write one program.
How to find student in a school and after that how to find his marks and after that how to find his attandance. so for this please draw a flow chart and write one program.
Kindly inform me while sending.
Nagraju.Sarla
08147870944.
a can't understand i want the
a can't understand i want the most simple code in coding a calculator...just use only the Declairing variables and expressions.
visual basic hw
hello,
i need help with my assignment in excel..we need to do the following:
1) color white all cells containing a negative value
2) color yellow all cells whose value is even and greater than zero
3) color red all cells whose value is divisible by 5 but not by 10 and is greater than zero
4) color blue all cells whose value is equal to 0
and we are given a list of numbers of course, and here is what i got
Sub manipulation()
'1) color white all cells containing a negative value
'2) color yellow all cells whose value is even and greater than zero
'3) color red all cells whose value is divisible by 5 but not by 10 and is greater than zero
'4) color blue all cells whose value is equal to 0
Dim curCell
For Each curCell In Selection
curCell.Value = Application.Round(curCell.Value, 0)
If curCell.Value Mod 2 = 0 And curCell.Value > 0 Then
curCell.Interior.Color = RGB(255, 255, 0)
End If
If curCell.Value Mod 5 = 0 And curCell.Value Mod 10 = 1 Then
curCell.Font.Color = RGB(355, 0, 0)
Else
curCell.Font.Color = RGB(0, 0, 255)
End If
Next curCell
End Sub
can anyone help me to finish the rest?!
looping
please help me this :
1.write a program that asks the user to input N integers and compute the ff:
-sum of all odd integers
-sum of all even integers
-average of all odd integers
-average of all even integers
2. input 10 scores and count how many scores are in the rage 1-25, 26-50, 51-75,76-100, and out of range . allow the user to repeat the operation as often as possible.
HELP
how do you write a program that would calculate and display the results for the multiplication table for values ranging from 1 to 100? using pseudo code and repetition statements
PLS. HELP ME !!!
Create a project that will allow the users to input numbers and be able to display all the numbers, smallest and largest numbers, the repeated number/s and total of all numbers.
loops
x^2 - x + 41 will find the prime numbers where x is 1 to 40. Write a program using this formula to display the prime numbers in that range of x. Display the results in a RichTextBox.
please help me to "create an
please help me to "create an application in vb to find the second biggest of the n number" and "coding to read the elements one by one and display the elements in the reverse format".........please tell me the CODING.....have to write my vb assignment...im new to visual basic and have no idea of the codings...please help to finish my assignments...please..:((
Reverse Number
textbox1
button1
button1.click event:
dim num,res,remi,res1 as integer
num=textbox1.text
res1=0
while num/10 <> 0
remi = num/10<>0
remi=num mod 10
res=math.truncate(num/10)
res1=(res1*10)+remi
num=res
end while
msgbox(res1)
end sub
end class
I want to do this in all loop
Create a program that reads
Create a program that reads the letter codes ‘A’ through ‘Z’ and prints the corresponding telephone digit. To stop the program, the user should enter ‘#’.
pls answer
pls answer
HELP PLEASE!
How do i construct a program that will accept the inputted name and will display it 5 times
using the For loop , Do while loop , While loop in C# ?
HELP PLEASE!
How do i construct a program that will accept the inputted name and will display it 5 times
using the For loop , Do while loop , While loop in C# ?
functions
how can i create a simple calculator that wil ask for two numbers. then displat a menue thatusers will choose whether they want to.
i.addition
ii.division.
iii.multiplication
iv.modulo.
v. subtraction.
it should also be nade up of
i.SUBROUTINE menue() that displays the menue.
ii.Function sumTwo() that accepts two numbers and returns the sum of the two numbers.
iii. should also apply for subtraction, division, modulo and division.
help please...
write a program to read in numbers of numbers to be inputted.read in the numbers. compute the sum,average,maximum and minimum values. print the sum, average, maximum and minimum values.the program will then ask the user if she/he wishes to continue, if yes then clear the screen and go back to the beginning of the program. if no, then end the program. if the input is less than 1,print a message containing the word error and perform and exit(0).
Done!
Here you are:
Option Explicit
Dim I As Long, Sum As Long, Num As Long, Max As Long, Min As Long
Private Sub Form_Activate()
Do
Me.Cls
For I = 1 To 10
Num = InputBox("Enter a number:", I & " Number")
If Num < 1 Then
MsgBox "E R R O R!"
End
End If
Print Num
If I = 1 Then
Sum = Num
Max = Num
Min = Num
Else
Sum = Sum + Num
If Num < Min Then
Min = Num
ElseIf Num > Max Then
Max = Num
End If
End If
Next
Print
Print "Sum = " & Sum
Print "Average = " & Sum / I - 1
Print "Max Number = " & Max
Print "Min Number = " & Min
Loop Until MsgBox("Do you wish to continue?", vbInformation + vbYesNo, "END") = vbNo
End
End Sub
HELP
pls, help me write simple VB.NET CODE SEGMENT to do the following;
1- x=5
y=2
x=x+5-y
z=y+X
2- what is the final answer for x, y, z
please, i need this before 8.00pm today.
thanks.
Visual basic.net
1 x=5,y=2.x=x+5-y, z=y+x.what is the final answer for x,y,z
do until
how can i solve this one , i have to get the output like this * *
** * *
*** *
or even any shapes of dots by using the do until loop
and when the user types a number in the input box it should show the numbers of dots that
the user has been type in the picture box...
please i need the codes of it immediately.... hope you can help me...
hell boss i think you need to
hell boss i think you need to display in your program like *** while running the program so just do it
select the text box which you want to insert ** and go to proparty window and set pasword char true (defalt value is false) i think it will help you other wise sorry .....
PasswordChar
On the textbox properties, look for PasswordChar. Then type *. That's it!
please help me creating a code
Please help me
1.Create a sequence where the next number is 1 higher than the previous.
2.Create a sequence where the next number is 10 higher than the previous.
3.Create a sequence where the next number is double the previous number.
4.Create a sequence where you show the first 5 odd numbers or even numbers.
all the answer must be shown in TextBox in the form of #,#,...,#
Done!
Option Explicit
Dim StartN As Long, EndN As Long, I As Long
Private Sub Form_Load()
Text1.Text = ""
While StartN < 1 Or StartN > 100
StartN = InputBox("Enter the start number for the sequence:", "0 - 100")
Wend
While EndN < 1 Or EndN > 100
EndN = InputBox("Enter the end number for the sequence:", "0 - 100 AND GREATER THAN START NUMBER")
Wend
For I = StartN To EndN 'answer 1.
Text1.Text = Text1.Text & Format(I, "#0") & ", "
Next
For I = StartN To EndN Step 10 'answer 2.
Text2.Text = Text2.Text & Format(I, "#0") & ", "
Next
For I = StartN To EndN 'answer 3.
If I = StartN Then
Text3.Text = Text3.Text & Format(I, "#0") & ", "
ElseIf I * 2 <= EndN Then
Text3.Text = Text3.Text & Format(I * 2, "#0") & ", "
End If
Next
For I = StartN To EndN 'answer 4.
If I Mod 2 = 0 Then
Text4.Text = Text4.Text & Format(I, "#0") & ", "
Else
Text5.Text = Text5.Text & Format(I, "#0") & ", "
End If
Next
End Sub
Create 5 text boxes to make it work right. I hope it will help you!
Thank you so much :-)
Thank you so much :-)
How to write From Right to left in Vb6
Can anyone help me to write From Right to left ( Like Arabic ) in vb6 with the default font, when changing the windows language from language bar.
Excel Macro
I need help using Visual Basic.
I am trying to add macros to a excel spreadsheet and one of the problems that i am facing right now is that i need to make lists every time I click a button. in other words, i want that every time I click on a button my number stores in the following row. I haven't been lucky with this so any help will be appreciated. thanks!
help plz..im new in VB
Public Class Form1
Private Sub mnuPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPoint.Click
Dim point As Integer
Dim book, reader As Integer
book = 0
reader = 0
If (TextBook.Text > 6) Then
point = 20
ElseIf (TextBook.Text > 3) Then
point = 15
Else
point = 10
End If
book = book + TextBook.Text
reader = reader + 1
LblEarn.Text = point
End Sub
Private Sub mnuClr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClr.Click
TextReader.Text = ""
TextBook.Text = ""
LblEarn.Text = ""
LblAverage.Text = ""
End Sub
Private Sub mnuSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSum.Click
Dim average As Double
Dim book As Integer
Dim reader As Integer
average = book / reader
LblAverage.Text = "books read " & book & " readers are " & reader
End Sub
End Class
"The problem is.....i want mnuSum_Click display the average number of book read for all readers.
the reader n book is variable....
mnuClr_Click is clear the name reader, the number of books read, and the bonus point and then reset the focus.
how to load the reader n book if 3 or 4 ppl read the book at the same time??
without load the reader n book, how to get average value...??
hope understand that situation...TQ"
Multiplication Table
How do I code an application so that it multiplies and displays any number I input by the numbers 1 to 9? Ex. Number: 25 Multiplication Table Displays: 25 * 1= 25, 25 * 2= 50, 25 * 3= 75, etc.
Done!
Here you are:
Private Sub Form_Activate()
Dim Num As Currency, I As Byte
Num = InputBox("Enter the number for multiplication:", "NUMBER")
For I = 1 To 9
Print Num & " * " & I & " = " & I * Num
Next
End Sub
Dim as ADODB.recordset do
Dim as ADODB.recordset
do while
loop
...rst.open
How do I convert a For...Next statement into a Do...Loop??
I still have not received an answer to my previous question below BUT how do I change this For... Next statement into a Do... Loop statement??
For intHours As Integer= 0 to 3
lblHours.Text=intHours.ToString
For intMinutes As Integer= 0 to 9
lblMinutes.Text= intMinutes.ToString
Next intMinutes
Next intHours
For...Next => Do...Loop
Here you are:
intHours = 0
Do While intHours < 4
lblHours.Text = intHours.ToString
intMinutes = 0
Do While intMinutes < 10
lblMinutes.Text = intMinutes.ToString
intMinutes = intMinutes +1
Loop
intHours = intHours +1
Loop
How do I convert a For...Next statement into a Do...Loop??
HELLLLPPPP!!!! I AM SO CONFUSED AS TO HOW TO CONVERT THIS STATEMENT INTO A DO... LOOP STATEMENT. :-(
For dblRate As Double = 0.05 To 0.1 Step 0.01
lblPayments.Text = lblPayments.Text _
& dblRate.ToString("P0") & " "
For intTerm As Integer = 3 To 5
dblPayment = _
-Financial.Pmt(dblRate / 12, _
intTerm * 12, dblPrincipal)
lblPayments.Text = lblPayments.Text _
& dblPayment.ToString("N2") & " "
Next intTerm
lblPayments.Text = lblPayments.Text & ControlChars.NewLine
Next dblRate
For...Next => Do...Loop
Here you are again:
dblRate = 0.05
Do While dblRate < 0.11
lblPayments.Text = lblPayments.Text & dblRate.ToString("P0") & " "
intTerm = 3
Do While intTerm < 6
dblPayment = -Financial.Pmt(dblRate / 12, intTerm * 12, dblPrincipal)
lblPayments.Text = lblPayments.Text & dblPayment.ToString("N2") & " "
intTerm = intTerm +1
Loop
lblPayments.Text = lblPayments.Text & ControlChars.NewLine
dblRate = dblRate + 0.01
Loop
How do I convert a For...Next statement into a Do...Loop??
Dim dblRate As DoubleDim intTerm As Integer
dblRate = 0.05
do until dblRate > 0.1
' stuff from outer for loop
lblPayments.Text = lblPayments.Text & dblRate.ToString("P0") & " "
intTerm = 3
do until intTerm > 5
' stuff from inner for loop
dblPayment = -Financial.Pmt(dblRate / 12, intTerm * 12, dblPrincipal)
lblPayments.Text = lblPayments.Text & dblPayment.ToString("N2") & " "
intTerm = intTerm + 1
loop
dblRate = dblRate + 0.01
loop
Need help, looping an Average of 10 numbers everytime
Need help to solving this question. Was given a row of numbers from B1 to B100. Every ten numbers must be averaged out , e.g B1 to B10 must be sum up then divided by 10 and placed it on E10. The looping contiunes, e.g B2 to B11 sumed up and divid by 10 and put in E11.
I came up with certain codes but it always seems to be stuck in the following loop. E.g When I do B2 to B11, B3 to B12 doesnt appear. Wondering what mistake I made as I keep getting an error message. Here is my code.
Dim stock2 As Double
Dim stock3 As Double
Dim stocke() As Double
Dim stockf() As Double
Dim stock As Integer
e = 1
f = 10
ReDim stocke(f, 1) As Double
For coltwo = 1 To 1
For rowtwo = e To f
stocke(rowtwo, coltwo) = Range("B5").Cells(rowtwo, coltwo)
stock2 = stock2 + stocke(rowtwo, coltwo)
If (rowtwo = 10) Then
Range("E14").Cells(1, 1) = stock2 / 10
e = 1
f = 10
End If
Next rowtwo
Next coltwo
test1 = 2
test2 = 11
ReDim stockf(test2, 1) As Double
For g = 1 To 90
For coltwo = 1 To 1
For rowtwo = test1 To test2
stockf(rowtwo, coltwo) = Range("B5").Cells(rowtwo, coltwo) ---> When I add the variable g, this code will get an error.
stock3 = stock3 + stockf(rowtwo, coltwo)
If (rowtwo = test2) Then
Range("E5").Cells(test2, 1) = stock3 / 10
test1 = test1 + g
test2 = test2 + g
rowtwo = test1
stock3 = 0
End If
Next rowtwo
Next coltwo
Next g
Please help .... thanks guys ...
Help needed about complicated while-if-for loop.
Hey there. Heres the question.
I am going to write a C++ program that asks user to enter a seres of integer in range of -100 and 100.
if user enters a number out of that range my code shouldnt consider it and ask a another number. Also when I type 0 code should be finished.
I need that program to screen
displaying max number entered,min number entered, average of positive and negative numbers. I can do most of that thing but How can I count the numbers i get in...:/
An extra variable....
I believe you should use one more variable that every time the user enters a new number, this variable should be the counter for all the numbers.
E.x.
Counter = 0
Do Until Number <> 0
{make the calculations}
Counter = Counter +1
Loop
If you need more explanations, please tell me!
help
1. Create a console application to print the sum of numbers from 1-100 which are divisible on 3 or 5
2. Create a console application to print of numbers from 1-100 each 5 numbers on a line. Each line must show the sum of numbers on the line too. Like the following sample:
1 2 3 4 5 15
6 7 8 9 10 40
11 12 13 14 15 65
….
3. write a console application that reads 10 marks (real numbers) then finds and prints the maximum mark. average.(use for loop).
Post new comment