i'm trying to do next:
the program should go to the beginning when there is an error. but it just goes to the next form.....
x = Text1.Text
y = Text2.Text
z = Text3.Text
If Text1.Text = "" Then MsgBox ("Ostavili ste prazno polje x")
If Text2.Text = "" Then MsgBox ("Ostavili ste prazno polje y")
If Text3.Text = "" Then MsgBox ("Ostavili ste prazno polje z")
Form1.Hide
Form2.Show
what shold i type between?
Command if and else
Started by Dunja, Jul 15 2007 01:04 PM
5 replies to this topic
#1
Posted 15 July 2007 - 01:04 PM
|
|
|
#2
Posted 16 July 2007 - 08:00 AM
It looks like you need to use the if then elseif structure.
#3
Posted 18 September 2007 - 12:50 PM
Are you asking how to start it all over without showing the next form? If so, construct your if/then statements with one more line of code. The one-lined if/then statements are bad programming style. You should always have one line for "If..." and line(s) for statements, and finally a "End If" line. Like this:
If Text1.Text = "" Then
MsgBox "Ostavili ste prazno polje x"
Exit Sub
End If
Option Explicit
:cool:
:cool:
#4
Posted 26 September 2007 - 08:49 PM
yes. tnx.. it's just End sub, not Exit sub :p
:)
:)
#5
Posted 27 September 2007 - 09:43 AM
You could you "End Sub", but "Exit Sub" does the same thing. I think the theory behind which one to use is: "End Sub" should end the entire sub procedure block. The end to the "Private Sub...". The "Exit Sub" should be used within the sub procedure as an escape method to stop executing code from that line on, until the actual "End Sub" line. Does this make any sense? lol!
But, in most cases, either one will work just fine :D
But, in most cases, either one will work just fine :D
Option Explicit
:cool:
:cool:
#6
Posted 28 September 2007 - 12:50 AM
Well the actually the Exit Sub is mostly used for error reports, what I mean is when you have a piece of code and if it generates an error you make a 'tag' at the end so if this error happens during execution goto error1, if that error happens goto error2, so Exit Sub is used when you have for example this code:
This code will generate an error IF on form 1 there are no textboxes, but if there was a textbox the Error tag will not be executed (because there is Exit Sub before it) but if there was no Exit Sub, the Error tag will be executed as well, so it will generate an error message even when there were none! And you cannot make code after End Sub as it will give an error as wrong VB Code but you can after Exit Sub So that is one of the main purposes of Exit Sub.
Private Sub Command1_Click() On Error GoTo Error text1.Text = "hi" Exit Sub Error: MsgBox "Error" End Sub
This code will generate an error IF on form 1 there are no textboxes, but if there was a textbox the Error tag will not be executed (because there is Exit Sub before it) but if there was no Exit Sub, the Error tag will be executed as well, so it will generate an error message even when there were none! And you cannot make code after End Sub as it will give an error as wrong VB Code but you can after Exit Sub So that is one of the main purposes of Exit Sub.


Sign In
Create Account

Back to top









