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! -
-
Private Sub cmdResult_Click()
-
-
InputData
-
If IsNumeric(txtLength.Text) = True Then
-
sngLength = Val(txtLength.Text)
-
If IsNumeric(txtWidth.Text) = True Then
-
sngWidth = Val(txtWidth.Text)
-
If IsNumeric(txtHeight.Text) = True Then
-
sngHeight = Val(txtHeight.Text)
-
If sngLength > 6 * sngWidth Then
-
sngVolume = sngLength * sngWidth * sngHeight
-
-
Surface = area + areaback + arealeft + arearight + areafloor + areaceiling
-
-
If cboMaterial.Text <> "" And _
-
cboMaterialBack.Text <> "" And _
-
cboMaterialLeft.Text <> "" And _
-
cboMaterialRight.Text <> "" And _
-
cboMaterialCeiling.Text <> "" And _
-
cboMaterialFloor.Text <> "" And _
-
cboMaterialOthers.Text <> "" And _
-
cboMaterial.ListIndex <> 0 And _
-
cboMaterialBack.ListIndex <> 0 And _
-
cboMaterialLeft.ListIndex <> 0 And _
-
cboMaterialRight.ListIndex <> 0 And _
-
cboMaterialFloor.ListIndex <> 0 And _
-
cboMaterialOthers.ListIndex <> 0 And _
-
cboMaterialFloor.ListIndex <> 10 And _
-
cboMaterialCeiling.ListIndex <> 0 Then
-
-
-
If cboMaterial2.Text <> "" And txtSize2.Text <> "" Or _
-
cboMaterial2.ListIndex = 0 Or _
-
cboMaterial2.Text = "" And txtSize2.Text = "" Then
-
If cboMaterial3.Text <> "" And txtSize3.Text <> "" Or _
-
cboMaterial3.ListIndex = 0 Or _
-
cboMaterial3.Text = "" And txtSize3.Text = "" Then
-
If cboMaterialBack2.Text <> "" And txtSizeBack2.Text <> "" Or _
-
cboMaterialBack2.ListIndex = 0 Or _
-
cboMaterialBack2.Text = "" And txtSizeBack2.Text = "" Then
-
If cboMaterialBack3.Text <> "" And txtSizeBack3.Text <> "" Or _
-
cboMaterialBack3.ListIndex = 0 Or _
-
cboMaterialBack3.Text = "" And txtSizeBack3.Text = "" Then
-
If cboMaterialLeft2.Text <> "" And txtSizeLeft2.Text <> "" Or _
-
cboMaterialLeft2.ListIndex = 0 Or _
-
cboMaterialLeft2.Text = "" And txtSizeLeft2.Text = "" Then
-
If cboMaterialLeft3.Text <> "" And txtSizeLeft3.Text <> "" Or _
-
cboMaterialLeft3.ListIndex = 0 Or _
-
cboMaterialLeft3.Text = "" And txtSizeLeft3.Text = "" Then
-
If cboMaterialLeft2.Text <> "" And txtSizeLeft2.Text <> "" Or _
-
cboMaterialRight2.ListIndex = 0 Or _
-
cboMaterialLeft2.Text = "" And txtSizeLeft2.Text = "" Then
-
If cboMaterialRight3.Text <> "" And txtSizeRight3.Text <> "" Or _
-
cboMaterialRight3.ListIndex = 0 Or _
-
cboMaterialRight3.Text = "" And txtSizeRight3.Text = "" Then
-
-
If cboMaterialFloor2.Text <> "" And txtSizeFloor2.Text <> "" Or _
-
cboMaterialFloor2.ListIndex = 0 Or _
-
cboMaterialFloor2.ListIndex = 10 Or _
-
cboMaterialFloor2.Text = "" And txtSizeFloor2.Text = "" Then
-
If cboMaterialFloor3.Text <> "" And txtSizeFloor3.Text <> "" Or _
-
cboMaterialFloor3.ListIndex = 0 Or _
-
cboMaterialFloor3.ListIndex = 10 Or _
-
cboMaterialFloor3.Text = "" And txtSizeFloor3.Text = "" Then
-
If cboMaterialCeiling2.Text <> "" And txtSizeCeiling2.Text <> "" Or _
-
cboMaterialCeiling2.ListIndex = 0 Or _
-
cboMaterialCeiling2.Text = "" And txtSizeCeiling2.Text = "" Then
-
If cboMaterialCeiling3.Text <> "" And txtSizeCeiling3.Text <> "" Or _
-
cboMaterialCeiling3.ListIndex = 0 Or _
-
cboMaterialCeiling3.Text = "" And txtSizeCeiling3.Text = "" Then
-
-
If (IsNumeric(txtSize2.Text) = True Or txtSize2.Text = "") And _
-
(IsNumeric(txtSize3.Text) = True Or txtSize3.Text = "") And _
-
(IsNumeric(txtSizeBack2.Text) = True Or txtSizeBack2.Text = "") And _
-
(IsNumeric(txtSizeBack3.Text) = True Or txtSizeBack3.Text = "") And _
-
(IsNumeric(txtSizeLeft2.Text) = True Or txtSizeLeft2.Text = "") And _
-
(IsNumeric(txtSizeLeft3.Text) = True Or txtSizeLeft3.Text = "") And _
-
(IsNumeric(txtSizeRight2.Text) = True Or txtSizeRight2.Text = "") And _
-
(IsNumeric(txtSizeRight3.Text) = True Or txtSizeRight3.Text = "") And _
-
(IsNumeric(txtSizeFloor2.Text) = True Or txtSizeFloor2.Text = "") And _
-
(IsNumeric(txtSizeFloor3.Text) = True Or txtSizeFloor3.Text = "") And _
-
(IsNumeric(txtSizeCeiling2.Text) = True Or txtSizeCeiling2.Text = "") And _
-
(IsNumeric(txtSizeCeiling3.Text) = True Or txtSizeCeiling3.Text = "") Then
-
-
-
Me.Hide
-
outlong.Show
-
-
-
-
Else
-
MsgBox "Please enter numerical value for size.", vbOKOnly, "Invalid Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient data."
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient data."
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
Else
-
MsgBox "Insufficient size data.", vbOKOnly, "Insufficient Data"
-
End If
-
-
-
-
Else
-
MsgBox "Please select construction material for walls, floor and ceiling.", vbOKOnly + vbExclamation, "Invalid Data"
-
cboMaterial.SetFocus
-
End If
-
-
-
Else
-
MsgBox "Length should be 6 times larger than Width", vbOKOnly + vbCritical, "Invalid Data"
-
txtWidth.Text = ""
-
txtWidth.SetFocus
-
End If
-
-
-
-
Else
-
MsgBox "Please enter numerical value for height.", vbOKOnly + vbExclamation, "Invalid Data"
-
txtHeight.Text = ""
-
txtHeight.SetFocus
-
End If
-
-
-
-
Else
-
MsgBox "Please enter numerical value for Width1.", vbOKOnly + vbExclamation, "Invalid Data"
-
-
txtWidth.Text = ""
-
-
txtWidth.SetFocus
-
End If
-
-
-
Else
-
MsgBox "Please enter numerical value for length.", vbOKOnly + vbExclamation, "Invalid Data"
-
-
txtLength.Text = ""
-
-
txtLength.SetFocus
-
End If
3 3486
With the number of IF ...ELSE statement in your code , it is too much error prone.
Check again for any missing Key word.
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: - Private Sub cmdResult_Click()
-
-
InputData
-
If IsNumeric(txtLength.Text) = False Then
-
MsgBox "Please enter numerical value for length.", vbOKOnly + vbExclamation, "Invalid Data"
-
txtLength.Text = ""
-
txtLength.SetFocus
-
Exit Sub
-
Else
-
sngLength = Val(txtLength.Text)
-
End If
-
If IsNumeric(txtWidth.Text) = False Then
-
MsgBox "Please enter numerical value for Width1.", vbOKOnly + vbExclamation, "Invalid Data"
-
txtWidth.Text = ""
-
txtWidth.SetFocus
-
Exit Sub
-
Else
-
sngWidth = Val(txtWidth.Text)
-
End If
-
If IsNumeric(txtHeight.Text) = True Then
-
MsgBox "Please enter numerical value for height.", vbOKOnly + vbExclamation, "Invalid Data"
-
txtHeight.Text = ""
-
txtHeight.SetFocus
-
Exit Sub
-
Else
-
sngHeight = Val(txtHeight.Text)
-
End If
-
If sngLength <= 6 * sngWidth Then
-
MsgBox "Length should be 6 times larger than Width", vbOKOnly + vbCritical, "Invalid Data"
-
txtWidth.Text = ""
-
txtWidth.SetFocus
-
Exit Sub
-
Else
-
sngVolume = sngLength * sngWidth * sngHeight
-
Surface = area + areaback + arealeft + arearight + areafloor + areaceiling
-
End If
-
If cboMaterial.Text = "" And _
-
cboMaterialBack.Text = "" And _
-
cboMaterialLeft.Text = "" And _
-
cboMaterialRight.Text = "" And _
-
cboMaterialCeiling.Text = "" And _
-
cboMaterialFloor.Text = "" And _
-
cboMaterialOthers.Text = "" And _
-
cboMaterial.ListIndex = 0 And _
-
cboMaterialBack.ListIndex = 0 And _
-
cboMaterialLeft.ListIndex = 0 And _
-
cboMaterialRight.ListIndex = 0 And _
-
cboMaterialFloor.ListIndex = 0 And _
-
cboMaterialOthers.ListIndex = 0 And _
-
cboMaterialFloor.ListIndex = 10 And _
-
cboMaterialCeiling.ListIndex = 0 Then
-
MsgBox "Please select construction material for walls, floor and ceiling.", vbOKOnly + vbExclamation, "Invalid Data"
-
cboMaterial.SetFocus
-
Exit Sub
-
End If
-
If cboMaterial2.Text <> "" And txtSize2.Text <> "" Or cboMaterial2.ListIndex = 0 Or cboMaterial2.Text = "" And txtSize2.Text = "" Then
-
...
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: - If A Or B Then
-
If C Or D Then
-
If E Or F Then
-
'' do something
-
End If
-
End If
-
End If
Is actually a complex form of the expression - If (A Or B) And (C Or D) And (E of F) Then
-
'' do something
-
End If
Now, to be fair, there are a lot of cases that look like this: - If A Or B Then
-
If C Or D Then
-
If E Or F Then
-
'' do something on (A or B) and (C or D) and (E or F)
-
Else
-
'' do something on (A or B) and (C or D) and not (E or F)
-
End If
-
Else
-
'' do something on (A or B) and not (C or D)
-
End If
-
Else
-
'' do something on not (A or B)
-
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: - If A or B Then
-
'' do something on not (A or B)
-
ElseIf not (C Or D) Then
-
'' do something on (A or B) and not (C or D)
-
ElseIf not (E Or F) Then
-
'' do something on (A or B) and (C or D) and not (E or F)
-
Else
-
'' do something on (A or B) and (C or D) and (E or F)
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 )...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,
...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |