Public Class Form1
Dim playername As String
Dim level As String
Dim country As String
Dim alliance As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
playername = InputBox("What is your Player Name?")
level = InputBox("What is your level?")
If Char.IsLetter(level) Then
'**************************************************************************************************
'I want to know how to go back to the "level" input box instruction if the input contains letters.
'**************************************************************************************************
ElseIf Char.IsNumber(level) Then
End If
country = InputBox("What is your country?")
alliance = InputBox("What is the size of your alliance?")
End Sub
End Class
12 Replies - 386 Views - Last Post: 18 February 2012 - 09:43 PM
Topic Sponsor:
#1
I need to make my program "repeat" a line of code.
Posted 01 February 2012 - 03:56 PM
This is the code i have thus far, using Visual Basic 2010 Express:
Replies To: I need to make my program "repeat" a line of code.
#2
Re: I need to make my program "repeat" a line of code.
Posted 01 February 2012 - 04:10 PM
What does that suggest to you need?
To me some for conditional loop. Do ... While / Do ... Until
To me some for conditional loop. Do ... While / Do ... Until
#3
Re: I need to make my program "repeat" a line of code.
Posted 02 February 2012 - 08:08 AM
Wouldn't something like this work?
If Char.IsLetter(CChar(level)) Then
Do Until Char.IsNumber(CChar(level))
level = InputBox("What is your level?")
Loop
ElseIf Char.IsNumber(CChar(level)) Then
#4
Re: I need to make my program "repeat" a line of code.
Posted 02 February 2012 - 03:52 PM
or the simplest way
1:
level = InputBox("What is your level?")
If Char.IsLetter(level) Then goto 1
#5
Re: I need to make my program "repeat" a line of code.
Posted 02 February 2012 - 06:21 PM
Did you really just suggest goto?
#6
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 01:47 AM
#7
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 04:14 AM
#8
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 04:22 AM
sela007, on 03 February 2012 - 08:47 AM, said:
it's just another way. Whats wrong with that?
The goto statement makes it very very easy to create spaghetti code (which is easy enough as it is), and it makes your code unpredictable. - If you place a label, especially one that vague, in a routine, you can call that at a any point in the routine. You'll have to waste time trying to figure out why the label was placed there and at what points in the routine it is called. There is no structure to it.
Meanwhile, these versions of your code are 100% obvious:
Do
level = InputBox("What is your level")
Loop While Char.IsLetter(level)
While !CharIsNumber(level)
level = InputBox("What is your level")
End While
They even read like plain English. As far as simplicity goes, where exactly does the goto get simpler than this?
There is never any reason to use a goto in a language like VB.NET. It has structured control statements, like the DO loop, that can be used to produce any result, without the use of a goto.
#9
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 06:45 AM
Atli, on 03 February 2012 - 04:22 AM, said:
There is never any reason to use a goto in a language like VB.NET. It has structured control statements, like the DO loop, that can be used to produce any result, without the use of a goto.
I don't agree with you. If you know how to use it and when, then there is no problem. Sometimes it's useful to avoid spaghetti code , especially when you have a complex code with bunch of select case statements ,and loops.
#10
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 06:55 AM
At best it's rarely useful. One of the only places it's acceptable to use is to escape from a deeply nested series of conditionals or loops, but I'd say that it's bad practice to write code that needs it in the first place. It can always be refactored to reduce nesting, at the very least by extracting methods.
The point is, suggesting goto as a replacement for a basic loop is bad advice, no matter how you want to spin it.
The point is, suggesting goto as a replacement for a basic loop is bad advice, no matter how you want to spin it.
#11
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 07:11 AM
Curtis Rutland, on 03 February 2012 - 06:55 AM, said:
The point is, suggesting goto as a replacement for a basic loop is bad advice, no matter how you want to spin it.
i agree with that. I just wanted to dbaliki918 knows that there are many ways to repeat the line of code.
first is Do ... While / Do ... Until.. like AdamSpeight2008 said... goto is last alternative,it's bad but it can do the job ...
#12
Re: I need to make my program "repeat" a line of code.
Posted 03 February 2012 - 07:53 AM
sela007, on 03 February 2012 - 07:56 PM, said:
... goto is last alternative,it's bad but it can do the job ...
And we do not advice bad practices here, if there is a best practice, always use it. That is all previous replies were saying. And we already have a topic about GOTO in
This post has been edited by smohd: 03 February 2012 - 08:08 AM
#13
Re: I need to make my program "repeat" a line of code.
Posted 18 February 2012 - 09:43 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|