Advertisement

05.08.2008 at 11:48AM PDT, ID: 23387211
[x]
Attachment Details

Is there a better way to do the same thing then all these on changes & If,then,and statements ?

Asked by DaMann in Visual Basic Programming, Microsoft Excel Spreadsheet Software

Tags: VBA

First this code work fine as is, but i know there are better ways to do things.

Is there a better or more standard way to do the same thing like with loops,  or a do while
or arrays ?

this code just checks if certain options & text boxes on a form are filled or chosen before it show the continue button.

Private Sub txtBlade_Change()
Call FillCells
End Sub
Private Sub txtLgthMinus_Change()
Call FillCells
End Sub
Private Sub txtLgthPlus_Change()
Call FillCells
End Sub
Private Sub txtSawDia_Change()
Call FillCells
End Sub
Private Sub txtSquareness_Change()
Call FillCells
End Sub
Private Sub txtTargetLgth_Change()
Call FillCells
End Sub
Private Sub txtTargetWt_Change()
FillCells
End Sub
Private Sub txtWtMinus_Change()
Call FillCells
End Sub
Private Sub txtWtPlus_Change()
Call FillCells
End Sub

Public Sub FillCells()
    Dim dataerror(6) As Boolean
    Dim a As Boolean
    Dim b As Boolean
    Dim c As Boolean
    Dim d As Boolean
If optWeight.Value = False And optLength.Value = False Then a = False Else dataerror(0) = True

If optPounds.Value = False And optMM.Value = False And optGrams.Value = False And _
optInches.Value = False Then b = False Else dataerror(1) = True

If txtTargetWt.Value <> "0" And txtWtPlus.Value <> "0" And txtWtMinus.Value <> "0" _
Or txtTargetLgth.Value <> "0" And txtLgthPlus.Value <> "0" And txtLgthMinus.Value <> "0" Then dataerror(2) = True

If txtSquareness.Value <> "" Then dataerror(3) = True
If txtBlade.Value <> "" Then dataerror(4) = True
If txtSawDia.Value <> "" Then dataerror(5) = True
If optDiameterMM.Value = False And optDiameterInch.Value = False Then GoTo endcheck Else dataerror(6) = True

If dataerror(0) = True And dataerror(1) = True And dataerror(2) = True And dataerror(3) = True _
And dataerror(4) = True And dataerror(5) = True And dataerror(6) = True Then btnCalculate.Visible = True


endcheck:

End Sub
Start Free Trial
 
Loading Advertisement...
 
[+][-]05.08.2008 at 12:03PM PDT, ID: 21527503

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic Programming, Microsoft Excel Spreadsheet Software
Tags: VBA
Sign Up Now!
Solution Provided By: AndrewVos
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628