Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Visual Basic problem (very noob)

  1. #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.

  2. #2
    Senior Member
    Join Date
    Aug 2002
    Posts
    113
    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.

  3. #3
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    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

    Go Finland!
    Deviant Gallery

  4. #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.

  5. #5
    AO French Antique News Whore
    Join Date
    Aug 2001
    Posts
    2,126
    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 7Then 
       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!!
    -Simon \"SDK\"

  6. #6
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    I am...I love C++. Unfortunately, to get a programming degree you have to learn more than one language.


    Go Finland!
    Deviant Gallery

  7. #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?

  8. #8
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    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.

    Go Finland!
    Deviant Gallery

  9. #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!!

  10. #10
    learning VB !!

    did'nt you hear that VB teaches you bad programming habbits !
    [gloworange][shadow]www.geocities.com/dia_byte0 [/shadow] [/gloworange]

    No To 1559 !

    Signature image is too tall!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •