473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

compile error: Else without if

I don't know why it pop up this error when I want to compile the program. ( the problem of the souce code that I'm facing in in the bolder style. Thanks for checking!

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdResult_Click()
  3.  
  4. InputData
  5. If IsNumeric(txtLength.Text) = True Then
  6. sngLength = Val(txtLength.Text)
  7.   If IsNumeric(txtWidth.Text) = True Then
  8.   sngWidth = Val(txtWidth.Text)
  9.         If IsNumeric(txtHeight.Text) = True Then
  10.         sngHeight = Val(txtHeight.Text)
  11.                    If sngLength > 6 * sngWidth Then
  12.         sngVolume = sngLength * sngWidth * sngHeight
  13.  
  14.         Surface = area + areaback + arealeft + arearight + areafloor + areaceiling
  15.  
  16.                 If cboMaterial.Text <> "" And _
  17.                    cboMaterialBack.Text <> "" And _
  18.                    cboMaterialLeft.Text <> "" And _
  19.                    cboMaterialRight.Text <> "" And _
  20.                    cboMaterialCeiling.Text <> "" And _
  21.                    cboMaterialFloor.Text <> "" And _
  22.                    cboMaterialOthers.Text <> "" And _
  23.                    cboMaterial.ListIndex <> 0 And _
  24.                    cboMaterialBack.ListIndex <> 0 And _
  25.                    cboMaterialLeft.ListIndex <> 0 And _
  26.                    cboMaterialRight.ListIndex <> 0 And _
  27.                    cboMaterialFloor.ListIndex <> 0 And _
  28.                    cboMaterialOthers.ListIndex <> 0 And _
  29.                    cboMaterialFloor.ListIndex <> 10 And _
  30.                    cboMaterialCeiling.ListIndex <> 0 Then
  31.  
  32.  
  33.                      If cboMaterial2.Text <> "" And txtSize2.Text <> "" Or _
  34.                         cboMaterial2.ListIndex = 0 Or _
  35.                         cboMaterial2.Text = "" And txtSize2.Text = "" Then
  36.                      If cboMaterial3.Text <> "" And txtSize3.Text <> "" Or _
  37.                         cboMaterial3.ListIndex = 0 Or _
  38.                         cboMaterial3.Text = "" And txtSize3.Text = "" Then
  39.                      If cboMaterialBack2.Text <> "" And txtSizeBack2.Text <> "" Or _
  40.                         cboMaterialBack2.ListIndex = 0 Or _
  41.                         cboMaterialBack2.Text = "" And txtSizeBack2.Text = "" Then
  42.                      If cboMaterialBack3.Text <> "" And txtSizeBack3.Text <> "" Or _
  43.                         cboMaterialBack3.ListIndex = 0 Or _
  44.                         cboMaterialBack3.Text = "" And txtSizeBack3.Text = "" Then
  45.                      If cboMaterialLeft2.Text <> "" And txtSizeLeft2.Text <> "" Or _
  46.                         cboMaterialLeft2.ListIndex = 0 Or _
  47.                         cboMaterialLeft2.Text = "" And txtSizeLeft2.Text = "" Then
  48.                      If cboMaterialLeft3.Text <> "" And txtSizeLeft3.Text <> "" Or _
  49.                         cboMaterialLeft3.ListIndex = 0 Or _
  50.                         cboMaterialLeft3.Text = "" And txtSizeLeft3.Text = "" Then
  51.                      If cboMaterialLeft2.Text <> "" And txtSizeLeft2.Text <> "" Or _
  52.                         cboMaterialRight2.ListIndex = 0 Or _
  53.                         cboMaterialLeft2.Text = "" And txtSizeLeft2.Text = "" Then
  54.                      If cboMaterialRight3.Text <> "" And txtSizeRight3.Text <> "" Or _
  55.                         cboMaterialRight3.ListIndex = 0 Or _
  56.                         cboMaterialRight3.Text = "" And txtSizeRight3.Text = "" Then
  57.  
  58.                      If cboMaterialFloor2.Text <> "" And txtSizeFloor2.Text <> "" Or _
  59.                         cboMaterialFloor2.ListIndex = 0 Or _
  60.                         cboMaterialFloor2.ListIndex = 10 Or _
  61.                         cboMaterialFloor2.Text = "" And txtSizeFloor2.Text = "" Then
  62.                      If cboMaterialFloor3.Text <> "" And txtSizeFloor3.Text <> "" Or _
  63.                         cboMaterialFloor3.ListIndex = 0 Or _
  64.                         cboMaterialFloor3.ListIndex = 10 Or _
  65.                         cboMaterialFloor3.Text = "" And txtSizeFloor3.Text = "" Then
  66.                      If cboMaterialCeiling2.Text <> "" And txtSizeCeiling2.Text <> "" Or _
  67.                         cboMaterialCeiling2.ListIndex = 0 Or _
  68.                         cboMaterialCeiling2.Text = "" And txtSizeCeiling2.Text = "" Then
  69.                      If cboMaterialCeiling3.Text <> "" And txtSizeCeiling3.Text <> "" Or _
  70.                         cboMaterialCeiling3.ListIndex = 0 Or _
  71.                         cboMaterialCeiling3.Text = "" And txtSizeCeiling3.Text = "" Then
  72.  
  73.                                   If (IsNumeric(txtSize2.Text) = True Or txtSize2.Text = "") And _
  74.                                      (IsNumeric(txtSize3.Text) = True Or txtSize3.Text = "") And _
  75.                                      (IsNumeric(txtSizeBack2.Text) = True Or txtSizeBack2.Text = "") And _
  76.                                      (IsNumeric(txtSizeBack3.Text) = True Or txtSizeBack3.Text = "") And _
  77.                                      (IsNumeric(txtSizeLeft2.Text) = True Or txtSizeLeft2.Text = "") And _
  78.                                      (IsNumeric(txtSizeLeft3.Text) = True Or txtSizeLeft3.Text = "") And _
  79.                                      (IsNumeric(txtSizeRight2.Text) = True Or txtSizeRight2.Text = "") And _
  80.                                      (IsNumeric(txtSizeRight3.Text) = True Or txtSizeRight3.Text = "") And _
  81.                                      (IsNumeric(txtSizeFloor2.Text) = True Or txtSizeFloor2.Text = "") And _
  82.                                      (IsNumeric(txtSizeFloor3.Text) = True Or txtSizeFloor3.Text = "") And _
  83.                                      (IsNumeric(txtSizeCeiling2.Text) = True Or txtSizeCeiling2.Text = "") And _
  84.                                      (IsNumeric(txtSizeCeiling3.Text) = True Or txtSizeCeiling3.Text = "") Then
  85.  
  86.  
  87.                                              Me.Hide
  88.                                              outlong.Show
  89.  
  90.  
  91.  
  92.                                      Else
  93.                                      MsgBox "Please enter numerical value for size.", vbOKOnly, "Invalid Data"
  94.                                      End If
  95.                     Else
  96.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient data."
  97.                     End If
  98.                     Else
  99.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient data."
  100.                     End If
  101.                     Else
  102.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  103.                     End If
  104.                     Else
  105.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  106.                     End If
  107.                     Else
  108.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  109.                     End If
  110.                     Else
  111.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  112.                     End If
  113.                     Else
  114.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  115.                     End If
  116.                     Else
  117.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  118.                     End If
  119.                     Else
  120.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  121.                     End If
  122.                     Else
  123.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  124.                     End If
  125.                     Else
  126.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  127.                     End If
  128.                     Else
  129.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  130.                     End If
  131.                     Else
  132.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  133.                     End If
  134.                     Else
  135.                     MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
  136.                     End If
  137.  
  138.  
  139.  
  140.                 Else
  141.                 MsgBox "Please select construction material for walls, floor and ceiling.", vbOKOnly + vbExclamation, "Invalid Data"
  142.                 cboMaterial.SetFocus
  143.                 End If
  144.  
  145.  
  146.         Else
  147.                 MsgBox "Length should be 6 times larger than Width", vbOKOnly + vbCritical, "Invalid Data"
  148.                 txtWidth.Text = ""
  149.                 txtWidth.SetFocus
  150.         End If
  151.  
  152.  
  153.  
  154.         Else
  155.             MsgBox "Please enter numerical value for height.", vbOKOnly + vbExclamation, "Invalid Data"
  156.             txtHeight.Text = ""
  157.             txtHeight.SetFocus
  158.         End If
  159.  
  160.  
  161.  
  162.        Else
  163.             MsgBox "Please enter numerical value for Width1.", vbOKOnly + vbExclamation, "Invalid Data"
  164.  
  165.             txtWidth.Text = ""
  166.  
  167.             txtWidth.SetFocus
  168.          End If
  169.  
  170.  
  171.         Else
  172.             MsgBox "Please enter numerical value for length.", vbOKOnly + vbExclamation, "Invalid Data"
  173.  
  174.             txtLength.Text = ""
  175.  
  176.             txtLength.SetFocus
  177.           End If
Mar 7 '11 #1
3 3486
debasisdas
8,127 Expert 4TB
With the number of IF ...ELSE statement in your code , it is too much error prone.

Check again for any missing Key word.
Mar 7 '11 #2
Guido Geurs
767 Expert 512MB
If You want to use nested IFs, indent the code in a visible way like: see attached GIF
To check the IF...else...endif: put the conditions in 1 line.
Later you can split the line with " _"

But it's recommended not to use to much nested IFs: use simple If's like for your code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdResult_Click()
  2.  
  3. InputData
  4. If IsNumeric(txtLength.Text) = False Then
  5.    MsgBox "Please enter numerical value for length.", vbOKOnly + vbExclamation, "Invalid Data"
  6.    txtLength.Text = ""
  7.    txtLength.SetFocus
  8.    Exit Sub
  9. Else
  10.    sngLength = Val(txtLength.Text)
  11. End If
  12. If IsNumeric(txtWidth.Text) = False Then
  13.    MsgBox "Please enter numerical value for Width1.", vbOKOnly + vbExclamation, "Invalid Data"
  14.    txtWidth.Text = ""
  15.    txtWidth.SetFocus
  16.    Exit Sub
  17. Else
  18.    sngWidth = Val(txtWidth.Text)
  19. End If
  20. If IsNumeric(txtHeight.Text) = True Then
  21.    MsgBox "Please enter numerical value for height.", vbOKOnly + vbExclamation, "Invalid Data"
  22.    txtHeight.Text = ""
  23.    txtHeight.SetFocus
  24.    Exit Sub
  25. Else
  26.    sngHeight = Val(txtHeight.Text)
  27. End If
  28. If sngLength <= 6 * sngWidth Then
  29.    MsgBox "Length should be 6 times larger than Width", vbOKOnly + vbCritical, "Invalid Data"
  30.    txtWidth.Text = ""
  31.    txtWidth.SetFocus
  32.    Exit Sub
  33. Else
  34.    sngVolume = sngLength * sngWidth * sngHeight
  35.    Surface = area + areaback + arealeft + arearight + areafloor + areaceiling
  36. End If
  37. If cboMaterial.Text = "" And _
  38.       cboMaterialBack.Text = "" And _
  39.       cboMaterialLeft.Text = "" And _
  40.       cboMaterialRight.Text = "" And _
  41.       cboMaterialCeiling.Text = "" And _
  42.       cboMaterialFloor.Text = "" And _
  43.       cboMaterialOthers.Text = "" And _
  44.       cboMaterial.ListIndex = 0 And _
  45.       cboMaterialBack.ListIndex = 0 And _
  46.       cboMaterialLeft.ListIndex = 0 And _
  47.       cboMaterialRight.ListIndex = 0 And _
  48.       cboMaterialFloor.ListIndex = 0 And _
  49.       cboMaterialOthers.ListIndex = 0 And _
  50.       cboMaterialFloor.ListIndex = 10 And _
  51.       cboMaterialCeiling.ListIndex = 0 Then
  52.    MsgBox "Please select construction material for walls, floor and ceiling.", vbOKOnly + vbExclamation, "Invalid Data"
  53.    cboMaterial.SetFocus
  54.    Exit Sub
  55. End If
  56. If cboMaterial2.Text <> "" And txtSize2.Text <> "" Or cboMaterial2.ListIndex = 0 Or cboMaterial2.Text = "" And txtSize2.Text = "" Then
  57. ...
Attached Images
File Type: jpg screen1.jpg (79.6 KB, 1904 views)
Mar 7 '11 #3
Oralloy
988 Expert 512MB
winson,

You need to control the nesting of your "if" statements, as Guido observed; it will help tremendously when developing your code.

Also, your use of nested "if" statements to accomplish what is a "and" condition is not smart. For example, this code:
Expand|Select|Wrap|Line Numbers
  1. If A Or B Then
  2.   If C Or D Then
  3.     If E Or F Then
  4.       '' do something
  5.     End If
  6.   End If
  7. End If
Is actually a complex form of the expression
Expand|Select|Wrap|Line Numbers
  1. If (A Or B) And (C Or D) And (E of F) Then
  2.   '' do something
  3. End If
Now, to be fair, there are a lot of cases that look like this:
Expand|Select|Wrap|Line Numbers
  1. If A Or B Then
  2.   If C Or D Then
  3.     If E Or F Then
  4.       '' do something on (A or B) and (C or D) and (E or F)
  5.     Else
  6.       '' do something on (A or B) and (C or D) and not (E or F)
  7.     End If
  8.   Else
  9.     '' do something on (A or B) and not (C or D)
  10.   End If
  11. Else
  12.   '' do something on not (A or B)
  13. End If
Which is common when dealing with a series of gateing conditions to get to a highly guarded section of code. However, a (in my view) better way of writing such a structure is usually accomplished by inverting the conditions and keeping a single level of nesting:
Expand|Select|Wrap|Line Numbers
  1. If A or B Then
  2.   '' do something on not (A or B)
  3. ElseIf not (C Or D) Then
  4.   '' do something on (A or B) and not (C or D)
  5. ElseIf not (E Or F) Then
  6.   '' do something on (A or B) and (C or D) and not (E or F)
  7. Else
  8.   '' do something on (A or B) and (C or D) and (E or F)
  9. End If
Notice that the code structure is very simple and flat in the final example. What I did was put the failure actions first, and the guarded action last.

Luck!
Oralloy
Mar 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tony Johansson | last post by:
Hello Experts! I have been playing around a bit with this multiple inheritance and I wonder why do I get a compile error if I remove the virtual keyvord from the declaration of the Student class...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
2
by: Kathy Houtami | last post by:
Hi there I've been encountered with weird compile error using Access 97. The error message is "Member or data member is not found" and it highlighted a line of code that has not be changed and...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
3
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I get a strange compile error when compile such simple program. Any ideas? foo.c: In function `main': foo.c:5: error: storage size of 'var' isn't known foo.c
5
by: TonyJ | last post by:
Hello! I get compile when using VS2005 but not in VS2003. The compile error is the following "Error 1 error C3867: 'MeltPracCommon::ReasonDialog::tbReason_TextChanged': function call missing...
7
by: Stu120 | last post by:
Hi, I'm trying to code a button to hide and show data in cells H5:I9 (MS Excel 2002) Here's the code: Sub Button21_Click() If Range("H5:H9").NumberFormat = "General" And...
8
by: pelicanstuff | last post by:
Hi - Was wondering if anybody could tell me why this rather crappy code is giving me an 'Else without If' error on compile? All the Elses and Ifs look ok to me but there's a few. Private Sub...
1
by: jayjayplane | last post by:
I have two combo boxes on my form, let's say box1(s1_individual_session) and box2(s1_nationality1), initially I disable box2(gray-out). I want to select box1 value is "true" then enable the box2, ...
7
by: Arjuna | last post by:
I have a class template (ExclusiveMap) which takes two type parameters C1 and C2 and declares two private members map<C1, C2> and map<C2, C1> (both STL maps). In test code I instantiate this class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.