|
-
Dec 30th, 2011, 11:09 AM
#1
Thread Starter
Member
[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:
If kategori2 = "" And kategori3 = "" And kategori4 = "" Then Open "D:\\test.txt" For Input As #1 Input #1, okunan If InStr(1, okunan, kategori1, 1) <= 0 Then MsgBox "Böyle bir kayıt 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 Text_stok_sayisi.Text = c End Sub
Last edited by _MeRKeZ_; Dec 30th, 2011 at 12:14 PM.
-
Dec 30th, 2011, 11:15 AM
#2
Addicted Member
Re: Block if without end if
 Originally Posted by _MeRKeZ_
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
-
Dec 30th, 2011, 11:55 AM
#3
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:
Public Function Test(Val1 As Long, Val2 As Long) As Long If Val1 >= 500 Then If Val2 >= 500 Then Exit Function End If Else Test = Val1 + Val2 End If End Sub
-
Dec 30th, 2011, 04:58 PM
#4
Re: Block if without end if
It just needs an End If before the End Sub.
End IF
End Sub.
Steve.
-
Dec 30th, 2011, 05:19 PM
#5
Re: Block if without end if
 Originally Posted by Steve Grant
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
-
Dec 31st, 2011, 06:13 AM
#6
Frenzied Member
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
-
Dec 31st, 2011, 09:10 AM
#7
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ö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
-
Dec 31st, 2011, 09:27 AM
#8
Thread Starter
Member
Re: Block if without end if
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
|
Click Here to Expand Forum to Full Width
|