If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Compile Error: Block IF without END IF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Aug 2004
Posts: 1
Compile Error: Block IF without END IF

I am fairly new to VB. My code keeps breaking and displaying this message:

Compile Error: Block IF without END IF

I think I have found that this is a bug in VB6 and I don't know how to fix my code so it will run.

Any help out there?
Reply With Quote
  #2 (permalink)  
Old
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 14,774
Can you post the smallest sample of code that you can create that demonstrates the problem?

-PatP
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Apr 2004
Location: LA, CA
Posts: 125
Without looking at your code and as the error code indicates, you are missing an End IF. make sure that for every IF statement that includes more that one instruction you have an End IF.

eg:
'here you need End IF
If a = b then
instruction 1
intruction 2
end if

'this is fine too. you don't need end if here.
if a= b then instruction

Hope this helps. As Pat said, a sample of your code would help diagnose the problem.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Sep 2004
Posts: 1
I have the exact opposite of this problem. My form says, "End If without Block If", and it has completely confused me because I do not have an extra End If.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Feb 2005
Posts: 1
What you have to do is change ur if statements
for example
if text1.text = "lol" then
end
elseif text1.text = "it works" then
text1.text = "hoorah"
pretty simple to fix
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
another thing to quickly check is to make sure you dont have anything like this

if test then
with something
end if
end with

or any loops built such etc.

Change them to open and close sequentially i.e.

if test
with something
end with
end if
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Jan 2010
Location: Fiji
Posts: 4
Please help, I am really new to vb I got a compile error saying "Block If Without End If"
and everytime I try correcting it, it still gives me the same error and End Sub is highlighted...I am working with Option buttons which I am new to. Here's the code:

If optRateA.Value = True Then
intGross = intHours * optRateA
Else
If optRateB.Value = True Then
intGross = intHours * optRateB
Else: optRateC.Value = True
intGross = intHours * optRateC
End If

Please help me!
Reply With Quote
  #8 (permalink)  
Old
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 14,774
Code:
If optRateA.Value = True Then
  intGross = intHours * optRateA
Else
  If optRateB.Value = True Then
    intGross = intHours * optRateB
  Else: optRateC.Value = True
    intGross = intHours * optRateC
  End If
Does this help? Code formatting can be a wonderful thing!

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #9 (permalink)  
Old
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,102
Quote:
Originally Posted by Pat Phelan View Post
Code:
If optRateA.Value = True Then
  intGross = intHours * optRateA
Else
  If optRateB.Value = True Then
    intGross = intHours * optRateB
  Else: optRateC.Value = True
    intGross = intHours * optRateC
  End If
Does this help? Code formatting can be a wonderful thing!

-PatP
Indeed.


In visual studio, hold down Ctrl, then press "K", then WITHOUT LETTING GO OF CTRL, press "D".

Tends to cut down on time needed to hunt down issues with control structure formatting...


Also, look in to using a RadioButtonList. You could condense that to a single line by hitting up the SelectedValue/SelectedIndex properties:

intGross = intHours * yourRadioButtonList.SelectedValue
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***

Last edited by Teddy; 01-29-10 at 15:54.
Reply With Quote
  #10 (permalink)  
Old
Registered User
 
Join Date: Jan 2010
Location: Fiji
Posts: 4
I am also doing a database for a company using vb6 and I'm just a beginner...I've already connected the database but then I have to make reports which I have already done but then I have to make a report which shows stocks that are less than 100...are there any codes to make reports show that without creating them?

help please!
Reply With Quote
  #11 (permalink)  
Old
Registered User
 
Join Date: Jan 2010
Location: Fiji
Posts: 4
Thanx alot for the help!!!
Reply With Quote
  #12 (permalink)  
Old
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 14,774
Do you have an answer for your reporting question?

If so, you're welcome. If not, I'll split this out as a separate message thread.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #13 (permalink)  
Old
Registered User
 
Join Date: Jan 2010
Location: Fiji
Posts: 4
well actually I didnt use any code but I just created the data report..drag and drop the controls onto the report..but I just don't really know how to make a report show stocks that are less than 100.
well this is what I did, I went back to Access where the data came from and I made another column, naming it Stocks <100 and putting a checkbox next to every item and checking those items that have less than 100....or is there another way to do this????
Reply With Quote
  #14 (permalink)  
Old
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,102
Depends on how your database is layed out.

How did you decide which stocks should get a checkbox?
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #15 (permalink)  
Old
Registered User
 
Join Date: Aug 2011
Posts: 3
you need an additional End If

Quote:
Originally Posted by CathyMe View Post
Please help, I am really new to vb I got a compile error saying "Block If Without End If"
and everytime I try correcting it, it still gives me the same error and End Sub is highlighted...I am working with Option buttons which I am new to. Here's the code:

If optRateA.Value = True Then
intGross = intHours * optRateA
Else
If optRateB.Value = True Then
intGross = intHours * optRateB
Else: optRateC.Value = True
intGross = intHours * optRateC
End If

Please help me!

this is an older post so maybe you have already figured it out but you have two IF statements - so you need two End IF statements - logically the nested IF statemtent is part of the same process so you ay have been thinking you are doing End If on the whole block - but the code requires an End If to match each one.

I am trying to solve my own compile error - but have about 5 nested IF statements - It looks like I have enough end ifs - unless I am looiking in the wrong place - keep in mind that you only need an End If after a block IF in other words a single like such as:

if true = true then msgbox ("True")

does NOT need an End If

whereas

if true = true then
msgbox ("True")
truth = true
End If

DOES need an End If

thing that annoys me on my issue is that I coudl have sworn I solved it earlier today and saved it - but it came back - so somewhere along the way I did not get some of my work earlier today saved.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On