Jump to content
  • Advertisement
Sign in to follow this  

VB once again

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whats the standard way to compile in VB 6.0?? Is it Run _ Start with full compile?? I wanna make an .exe Anyhow I do that and I get a compile error on this line: Private Sub cmdPrint_Click() If Text1.Text <> "" Then Printer.Print Text1.Text Printer.EndDoc End If End Sub it says end if without block if Does anybody know what I did wrong??

Share this post


Link to post
Share on other sites
Advertisement
It should look like this:


Private Sub cmdPrint_Click()
If Text1.Text <> "" Then
Printer.Print Text1.Text
Printer.EndDoc
End If



Since you put the line "Printer.Print Text1.Text" on the same line as the If...Then statement, VB assumed that the entire If...Then block was on one line. When it reached the "End If," there was no If to End.

There is also an option File->Make EXE in the menu.

Share this post


Link to post
Share on other sites
Just press F5 to run, or ctrl-F5 if you want to be sure it all compiles first.

Also, you should never compare a string with an empty string in VB. It creates an instance of the empty string everywhere you write "", and it is far slower.
It is much more efficient to write:
Private Sub cmdPrint_Click()
If Len(Text1.Text) > 0 Then
Printer.Print Text1.Text
Printer.EndDoc
End If

though you could also have written this which is not as nice...

If Len(Text1.Text) > 0 Then Printer.Print Text1.Text : Printer.EndDoc


Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
Also, you should never compare a string with an empty string in VB. It creates an instance of the empty string everywhere you write "", and it is far slower.


Not true in this case. VB would know that Text1.Text is a property of the object Text1. If Text1 does not exist, VB will not create it. The program would die with an error.

Simple variables will get created on the fly if Option Explicit is not specified. The best practice is to use Option Explicit and dim all your variables.

Share this post


Link to post
Share on other sites
DaTroof, that really had nothing to do with the quote you responded to.

He's talking about writing in the literal "", as in:


If Text1.Text = "" Then
' Do some stuff
End If


as opposed to:


If Len(Text1.Text) = 0 Then
' Do Some stuff
End If

Share this post


Link to post
Share on other sites
Quote:
Original post by daerid
DaTroof, that really had nothing to do with the quote you responded to.

He's talking about writing in the literal "", as in:


Ugh. My mistake. From now on, coffee first, then forums.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!