d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I Need Your Help > Vba
Add Reply New Topic New Poll
Member
Posts: 471
Joined: Apr 27 2011
Gold: 0.00
Sep 16 2012 07:03pm
Hi everyone i just started a vba class, I have a work to finish before friday and i'm not able to do so.
Here you have the work that i shall to do:
Quote
In the same workbook, write a VBA subroutine to the next treatment.
• With InputBox, enter a value as it is not a number between 1 and 5.
• Suppose that the number is 3, then display in a MsgBox
1
1 2
1 2 3
• For any number i:
1
1 2
...
1 2 3 ... i
• After this display, ask, with a MsgBox if the user wants to start over with another number.
o If yes, repeat the treatment.
o If no, the subroutine ends.


So I start the code but i'm not able to do the last stage.

Code
Sub exercise2()
Dim number As String
Dim a As Single
Dim nb As Single


number = InputBox("Enter a number")
If Not IsNumeric(number) Then
MsgBox ("This is not a number")

End If
Select Case number
Case 1 To 5
MsgBox ("invalid number")
End Select

nb = CSng(number)
For nb = 1 To number Step 1
MsgBox ("" & nb)

Next nb

End Sub


Thank you for your help it's very appreciated.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 16 2012 07:49pm
roughly this idea. my syntax will be off.


sub driver()

do{
exercise2()
} while (inputbox("do you want to continue?").tolowercase.equals("yes"))

end sub
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll