Results 1 to 8 of 8

Thread: [RESOLVED] Block if without end if

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Resolved [RESOLVED] Block if without end if

    Hi friends,

    I receive the same error message which is "Block if without end if"

    If you tell the where the mistake is, it will be perfect for me.
    I have been dealing with this problem for hours
    vb Code:
    1. If kategori2 = "" And kategori3 = "" And kategori4 = "" Then
    2.         Open "D:\\test.txt" For Input As #1
    3.             Input #1, okunan
    4.                    If InStr(1, okunan, kategori1, 1) <= 0 Then
    5.                 MsgBox "Böyle bir kayıt yok."
    6.                 Exit Sub
    7.      ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 4, 1) Then
    8.         w = Left(okunan, M - 4)
    9.         w = Trim(w)
    10.         u = Len(w)
    11.    
    12.     ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 5, 1) = "" Then
    13.         w = Left(okunan, M - 5)
    14.         w = Trim(w)
    15.         u = Len(w)
    16.    
    17.     ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 6, 1) = "" Then
    18.         w = Left(okunan, M - 6)
    19.         w = Trim(w)
    20.         u = Len(w)
    21.    
    22.     ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 7, 1) = "" Then
    23.         w = Left(okunan, M - 7)
    24.         w = Trim(w)
    25.         u = Len(w)
    26.    
    27.     ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 8, 1) = "" Then
    28.         w = Left(okunan, M - 8)
    29.         w = Trim(w)
    30.         u = Len(w)
    31.     End If
    32.    
    33.     If Mid(w, u - 1, 1) = "" Then
    34.         c = Mid(w, u, 1)
    35.         c = stok_sayisi + c
    36.     ElseIf Mid(w, u - 2, 1) = "" Then
    37.         c = Mid(w, u - 1, 2)
    38.         c = stok_sayisi + c
    39.     ElseIf Mid(w, u - 3, 1) = "" Then
    40.         c = Mid(w, u - 2, 3)
    41.         c = stok_sayisi + c
    42.     ElseIf Mid(w, u - 4, 1) = "" Then
    43.         c = Mid(w, u - 3, 4)
    44.         c = stok_sayisi + c
    45.     ElseIf Mid(w, u - 5, 1) = "" Then
    46.         c = Mid(w, u - 4, 5)
    47.         c = stok_sayisi + c
    48.     ElseIf Mid(w, u - 6, 1) = "" Then
    49.         c = Mid(w, u - 5, 6)
    50.         c = stok_sayisi + c
    51.     End If
    52.     Text_stok_sayisi.Text = c
    53.    
    54.  
    55. End Sub
    Last edited by _MeRKeZ_; Dec 30th, 2011 at 12:14 PM.

  2. #2
    Addicted Member seditives's Avatar
    Join Date
    Jan 2011
    Location
    South of England
    Posts
    151

    Re: Block if without end if

    Quote Originally Posted by _MeRKeZ_ View Post
    If InStr(1, okunan, kategori1, 1) <= 0 Then
    MsgBox "Böyle bir kayıt yok."
    Exit Sub
    I think it may be here, its hard to remake thi as you have alot of varibles and other things going in and out of these if statements try this

    Code:
    If InStr(1, okunan, kategori1, 1) <= 0 Then
                    MsgBox "Böyle bir kayıt yok."
                    Exit Sub
    End If
    A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Block if without end if

    When posting code in VBForums, be sure to use [highlight=vb] Your code here [/highlight]. Also if you were to indent your code, you can see all the places where your if statement blocks are and more. Makes it 100 times easier to debug:

    vb Code:
    1. Public Function Test(Val1 As Long, Val2 As Long) As Long
    2.  
    3.     If Val1 >= 500 Then
    4.          If Val2 >= 500 Then
    5.                Exit Function
    6.          End If
    7.     Else
    8.          Test = Val1 + Val2
    9.     End If
    10.  
    11. End Sub

  4. #4
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: Block if without end if

    It just needs an End If before the End Sub.


    End IF
    End Sub.

    Steve.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Block if without end if

    Quote Originally Posted by Steve Grant View Post
    It just needs an End If before the End Sub.

    End IF
    End Sub.

    Steve.
    Nope, don't think so. His indenting may have thrown you off. seditives reply in #2 is the correct answer I believe

    There is another problem too. He isn't closing his file before exiting the routine; that'll raise an error next time the file is trying to be accessed with the hardcoded file number of #1
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Block if without end if

    might i suggest you look at the select statement

    to replace the long list of elseif s

    it is easier to use

    nicely structured

    and only has one "end" to worry about

    here to talk

  7. #7
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Block if without end if

    With proper indenting it is a little easier to spot the missing End If. Changes highlighted in red
    Code:
    Private Sub Form_Load()
        If kategori2 = "" And kategori3 = "" And kategori4 = "" Then
            Open "D:\\test.txt" For Input As #1
            Input #1, okunan
            Close #1      
             
            If InStr(1, okunan, kategori1, 1) <= 0 Then
                MsgBox "B&#246;yle bir kayit yok."
                Exit Sub
            ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 4, 1) Then
                w = Left(okunan, M - 4)
                w = Trim(w)
                u = Len(w)
            ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 5, 1) = "" Then
                w = Left(okunan, M - 5)
                w = Trim(w)
                u = Len(w)
            ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 6, 1) = "" Then
                w = Left(okunan, M - 6)
                w = Trim(w)
                u = Len(w)
            ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 7, 1) = "" Then
                w = Left(okunan, M - 7)
                w = Trim(w)
                u = Len(w)
            ElseIf InStr(1, okunan, kategori1, 1) > 0 And Mid(okunan, M - 8, 1) = "" Then
                w = Left(okunan, M - 8)
                w = Trim(w)
                u = Len(w)
            End If
    
            If Mid(w, u - 1, 1) = "" Then
                c = Mid(w, u, 1)
                c = stok_sayisi + c
            ElseIf Mid(w, u - 2, 1) = "" Then
                c = Mid(w, u - 1, 2)
                c = stok_sayisi + c
            ElseIf Mid(w, u - 3, 1) = "" Then
                c = Mid(w, u - 2, 3)
                c = stok_sayisi + c
            ElseIf Mid(w, u - 4, 1) = "" Then
                c = Mid(w, u - 3, 4)
                c = stok_sayisi + c
            ElseIf Mid(w, u - 5, 1) = "" Then
                c = Mid(w, u - 4, 5)
                c = stok_sayisi + c
            ElseIf Mid(w, u - 6, 1) = "" Then
                c = Mid(w, u - 5, 6)
                c = stok_sayisi + c
            End If
        End If   
     
        Text_stok_sayisi.Text = c
    End Sub

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Re: Block if without end if

    it's done thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width