-
November 3rd, 2004, 10:58 PM
#1
Visual Basic problem (very noob)
hi all,
i have decided to learn VB and the first program in the book already gives problems:
Code:
Private Sub Command1_Click()
Image1.Visible = False
Label1.Caption = Int(Rnd * 10)
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
If (Label1.Caption = 7) And (Label2.Caption = 7) And _
(Label3.Caption = 7) Then Image1.Visible = True
Beep
End If
End Sub
It is giving the error End If without block If
it should be about the same as:
Code:
if((Label1.Caption ==7)&&(Label2.Caption==7)&&(Label3.Caption))
{
Image1.Visible=TRUE;
Beep;
}
(nice huh? C and VB in one code ). this is what it should look like, but then in VB....
This is really bothering me, VB should be such an easy language, and i know C, but still i do not understand what i have done wrong!!!
ps i'm using VB 6.0 pro as compiler, and i did try the above code with and without the '_' underscore.
-
November 3rd, 2004, 11:22 PM
#2
Senior Member
Let me tell you first that I do not have the vb compiler installed on my machine at the moment but here goes my suggestion. Apologies in advance if it does not work.
If ( (Label1.Caption = 7) And (Label2.Caption = 7) And _
(Label3.Caption = 7)) Then
{
Image1.Visible = True
Beep
}
End If
* I hope it will work. Play with the brackets it seems that they are causing all the errors. Try enforcing one pair of brackets at a time. And if no success then jump to implementing both of them.
All the best. Do let me know when you finally figure out the cause of error. Its been a couple of years since I touched VB or programming for that matter
Beware Clarity! A person talking to you in clear language is clearly using obsolete ideas.
-
November 3rd, 2004, 11:23 PM
#3
After your 'Then' you need to put the rest of the code on another line. This should solve your problem.
Code:
Private Sub Command1_Click()
Image1.Visible = False
Label1.Caption = Int(Rnd * 10)
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
If (Label1.Caption = 7) And (Label2.Caption = 7) And _
(Label3.Caption = 7) Then
Image1.Visible = True
Beep
End If
End Sub
-
November 4th, 2004, 12:14 AM
#4
This is not directly pretaining to your question at all, but why in the hell would anyone learn VB?
That and Math, I am surprised that you know VB.
I thought you were a C person.
-
November 4th, 2004, 12:20 AM
#5
If Mathgirl solution doesn's solve your problem, try this
PHP Code:
Private Sub Command1_Click()
Image1.Visible = False
Label1.Caption = Int(Rnd * 10)
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
If (Label1.Caption = 7) And (Label2.Caption = 7) And (Label3.Caption = 7) Then
Image1.Visible = True
Beep
End If
End Sub
I do agree with whizkid2300, don't bother with VB6... If you want to learn VB, learn VB .Net at least!!
-
November 4th, 2004, 12:21 AM
#6
I am...I love C++. Unfortunately, to get a programming degree you have to learn more than one language.
-
November 4th, 2004, 01:37 AM
#7
Agh... That explains it. I unfortunately am being forced into taking VB next semester.
Math are you back in school, I thought you graduated with a Degree in Math. Working on getting your masters?
-
November 4th, 2004, 01:50 AM
#8
I was just taking random post-graduate classes in computer science (for the last two years) because I couldn't decide on a master's degree. However, I have finally just decided (this last semester) to, instead, get another bachelor's degree in computer science. All I really want is c++ and assembly classes....unfortunately there are no degrees like that.
-
November 4th, 2004, 11:09 AM
#9
Thanks for your help all, at least now i know that VB is space or line sensitive, another reason not to like VB
well i want to learn VB cause i am learning ASM and RE as well, and since i have found that when a program is written in C/C++ i can understand what happens when i disassemble it, but when it is written in VB, even the simple crackme's, i have a hard time following it. that's the reason i am learning it, and i will learn delphi like this too.
plus that i do believe it will make me a better coder if i know multiple languages...
thanks for your help all, i know know what i have done wrong!!
-
November 4th, 2004, 05:57 PM
#10
Member
learning VB !!
did'nt you hear that VB teaches you bad programming habbits !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|