Sorry i think this is pretty basic but I was wondering if somebody could tell me why only 1 of these IF statements seem to run. The 3rd IF statement for the "CASH" option works but the other 2 unfortunately don't.
Sub HideUnhide_Discount()
If Range("Payment_Option") = "Subscription" Then
Range("MnthD_Row").EntireRow.Hidden = False
Range("MnthD").Value = 0
Else
Range("MnthD_Row").EntireRow.Hidden = True
End If
If Range("Payment_Option") = "Lease" Then
Range("OOD_Row").EntireRow.Hidden = False
Range("Leasing_Info").EntireRow.Hidden = False
Range("OOD").Value = 0
Else
Range("OOD_Row").EntireRow.Hidden = True
Range("Leasing_Info").EntireRow.Hidden = True
End If
If Range("Payment_Option") = "Cash" Then
Range("OOD_Row").EntireRow.Hidden = False
Range("MnthD_Row").EntireRow.Hidden = False
Range("OOD").Value = 0
Else
Range("OOD_Row").EntireRow.Hidden = True
Range("MnthD_Row").EntireRow.Hidden = True
End If
End Sub
Try replacing your multiple If >> Else condition with the Select Case below:
Sub HideUnhide_Discount()
' first reset all rows to be visible , later according to the value, unhide specific rows
Range("MnthD_Row").EntireRow.Hidden = True
Range("OOD_Row").EntireRow.Hidden = True
Range("Leasing_Info").EntireRow.Hidden = True
Select Case Range("Payment_Option")
Case "Subscription"
Range("MnthD_Row").EntireRow.Hidden = False
Range("MnthD").Value = 0
Case "Lease"
Range("OOD_Row").EntireRow.Hidden = False
Range("Leasing_Info").EntireRow.Hidden = False
Range("OOD").Value = 0
Case "Cash"
Range("OOD_Row").EntireRow.Hidden = False
Range("MnthD_Row").EntireRow.Hidden = False
Range("OOD").Value = 0
End Select
End Sub
Related
I'm trying to do a program where the user can control the dimension of the input matrix and provide the necessary textboxes according to the desired dimension of the matrix. With my current lines of codes, this will probably reach a thousand lines despite the simplicity of the function. Is there a way to write this more efficiently? The boxes should show up every time "Load" is clicked.
If (RowDisplay.Text = "1" And ColumnDisplay.Text = "1") Then
Ta11.Visible = True
Ta21.Visible = False
Ta31.Visible = False
Ta41.Visible = False
Ta51.Visible = False
Ta12.Visible = False
Ta22.Visible = False
Ta32.Visible = False
Ta42.Visible = False
Ta52.Visible = False
Ta13.Visible = False
Ta23.Visible = False
Ta33.Visible = False
Ta43.Visible = False
Ta53.Visible = False
Ta14.Visible = False
Ta24.Visible = False
Ta34.Visible = False
Ta44.Visible = False
Ta54.Visible = False
Ta15.Visible = False
Ta25.Visible = False
Ta35.Visible = False
Ta45.Visible = False
Ta55.Visible = False
ElseIf (RowDisplay.Text = "2" And ColumnDisplay.Text = "1") Then
Ta11.Visible = True
Ta21.Visible = True
Ta31.Visible = False
Ta41.Visible = False
Ta51.Visible = False
Ta12.Visible = False
Ta22.Visible = False
Ta32.Visible = False
Ta42.Visible = False
Ta52.Visible = False
Ta13.Visible = False
Ta23.Visible = False
Ta33.Visible = False
Ta43.Visible = False
Ta53.Visible = False
Ta14.Visible = False
Ta24.Visible = False
Ta34.Visible = False
Ta44.Visible = False
Ta54.Visible = False
Ta15.Visible = False
Ta25.Visible = False
Ta35.Visible = False
Ta45.Visible = False
Ta55.Visible = False
End If
While I probably wouldn't recommend using all those TextBoxes in the first place. If you're going to do it that way, put them all in the same Panel, TableLayoutPanel or FlowLayoutPanel, then you can do this:
Private Sub DisplayTextBoxes(count As Integer)
For i = 0 To myContainer.Controls.Count - 1
myContainer.Controls(i).Visible = (i < count)
Next
End Sub
If, for instance, you call that with a count of 2, the controls at index 0 and 1 will have Visible set to True and the rest will have Visible set to False.
I'm trying to validate a postcode from a user input within a form. Using this class, i'm trying to search through every character and check it. Then to call in within the form I have used the latter code.
The problem i'm having is that an error pops up saying
"Conversion from string "True0" to type 'Double' is not valid."
Function VaidatePostCode(ByVal Post As String) As String
For C = 0 To Len(Post) - 1
If Char.IsLetter(Post(C)) & C = 0 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsLetter(Post(C)) & C = 1 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsNumber(Post(C)) & C = 2 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsWhiteSpace(Post(C)) & C = 3 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsNumber(Post(C)) & C = 4 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsLetter(Post(C)) & C = 5 Then
_boolvalid = True
Else
_boolvalid = False
End If
If Char.IsLetter(Post(C)) & C = 6 Then
_boolvalid = True
Else
_boolvalid = False
End If
Next C
Return _boolvalid
End Function
This is the code within the VB.NET form
Private Sub txtPost_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPost.Validated
If myVal.VaidatePostCode(txtPost.Text) = False Then
MsgBox("Please enter correct data format into postcode")
End If
End Sub
To check if the value is a number you can use Integer.TryParse like this:
If Not Integer.TryParse(txtPost.Text, intTemp) Then
MsgBox ...
I'm making a vba project with some userforms. I want the people to click the macro button, then need to choose their initials, then by togglebutton click the weeks they want to go on holiday and then click transfer. So far i've done, that if they click one their initials, the value will be printed to a cell. The next userform (userform2), will need to look for the value, to determin wich row the values will be printed in.
But i get an error, on my Select case code.
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "CTK"
result = Something
Case Is = "MogM"
result = Something1
Case Is = "KSJI"
result = Something2
Case Is = "TSLR"
result = Something3
Case Is = "JOHQ"
result = Something4
Case Is = "OLGJ"
result = Something5
Case Is = "CBJN"
result = Something6
Case Is = "JVLK"
result = Something7
Case Is = "JFP"
result = Something8
Case Is = "EVAD"
result = Something9
Case Is = "TKUP"
result = Something10
Case Else
MsgBox ("Didn't find anyone with these init")
Range("A20").Value = result
End Select
End Sub
Private Sub ToggleButton1_Click()
End Sub
I solved the coding, but now i got a new question. Is it possible to simplify it?
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "1"
result = "CTK"
Case Is = "2"
result = "MogM"
Case Is = "3"
result = "KSJI"
Case Is = "4"
result = "TSLR"
Case Is = "5"
result = "JOHQ"
Case Is = "6"
result = "OLGJ"
Case Is = "7"
result = "CBJN"
Case Is = "8"
result = "JVLK"
Case Is = "9"
result = "JFP"
Case Is = "10"
result = "EVAD"
Case Is = "11"
result = "TKUP"
Case Else
MsgBox ("Didn't find anyone with these init")
End Select
Range("A20").Value = result
'CTK opportunities
If result = "CTK" And ToggleButton1 = True Then Range("B4").Value = "X"
If result = "CTK" And ToggleButton2 = True Then Range("C4").Value = "X"
If result = "CTK" And ToggleButton3 = True Then Range("D4").Value = "X"
If result = "CTK" And ToggleButton4 = True Then Range("E4").Value = "X"
If result = "CTK" And ToggleButton5 = True Then Range("F4").Value = "X"
If result = "CTK" And ToggleButton6 = True Then Range("G4").Value = "X"
If result = "CTK" And ToggleButton7 = True Then Range("H4").Value = "X"
If result = "CTK" And ToggleButton8 = True Then Range("I4").Value = "X"
If result = "CTK" And ToggleButton9 = True Then Range("J4").Value = "X"
If result = "CTK" And ToggleButton10 = True Then Range("K4").Value = "X"
If result = "CTK" And ToggleButton11 = True Then Range("L4").Value = "X"
If result = "CTK" And ToggleButton12 = True Then Range("M4").Value = "X"
'Next person
Unload Me
End Sub
I am trying to add a property called NumDBsToDisplay that gives the option of selecting between 0 and 3 databases to be displayed on my custom control. I can't get the property to show up in the designer, am I missing something here?
Here's the code:
Public Property NumDBsToDisplay(ByVal i As Integer) As Integer
Get
Dim count As Integer = 0
If cboPridb.Visible = True Then
count += 1
End If
If cboSecdb.Visible = True Then
count += 1
End If
If cboTridb.Visible = True Then
count += 1
End If
Return count
End Get
Set(ByVal value As Integer)
If value = 0 Then
cboPridb.Visible = False
cboSecdb.Visible = False
cboTridb.Visible = False
ElseIf value = 1 Then
lblPridB.Text = "Primary Database"
cboPridb.Visible = True
cboSecdb.Visible = False
cboTridb.Visible = False
ElseIf value = 2 Then
lblPridB.Text = "Primary Database"
lblSecDB.Text = "Secondary Database"
cboPridb.Visible = True
cboSecdb.Visible = True
cboTridb.Visible = False
Else
lblPridB.Text = "Primary Database"
lblSecDB.Width = 131
lblSecDB.Text = "Secondary Database"
lblTriDB.Text = "Tertiary Database"
cboPridb.Visible = True
cboSecdb.Visible = True
cboTridb.Visible = True
End If
End Set
End Property
Thank you for the help.
I need your help. I would like to understand why when running ScriptManager.RegisterClientScriptBlock the controls of my page disappear and reappear only after confirmation of Ok?
Protected Sub ddlDeckFittingCategory_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlDeckFittingCategory.SelectedIndexChanged
If txbNumberofColumns.Text = "" Or Me.txbShellDiameter.Text = "" Then
ScriptManager.RegisterClientScriptBlock(Me.Page, Page.GetType, "alert", "alert('Informe o valor do Diâmetro do Casco (m)!');", True)
ddlDeckFittingCategory.SelectedValue = -1
Else
If Request("TipoTela") = 1 Then
If ddlDeckFittingCategory.SelectedValue = "Typical" Then
objFinttings_temp.IncluirFittingsTempTQIFLTTipico(Session("cod_usuario_usu"))
'objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(CType(txbNumberofColumns.Text, Double))
objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(txbNumberofColumns.Text)
tbFittingsFonte.Visible = True
tbFittingsFonte.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
Dim dvConsultarCodFonteEmFittingsTempPorUsuario As DataView = objFinttings_temp.ConsultarCodFonteEmFittingsTempPorUsuario(Session("cod_usuario_usu"))
Session("cod_fonte_fon") = dvConsultarCodFonteEmFittingsTempPorUsuario.Table.Rows(0)("cod_fonte_fon")
Session("ddlDeckFittingCategory") = ddlDeckFittingCategory.SelectedValue
Else
objFinttings_temp.IncluirFittingsTQIFLTDetalhado(0)
tbFittings.Visible = True
tbFittings.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
End If
GrvFittingsFonte.DataBind()
Else
If ddlDeckFittingCategory.SelectedValue = "Typical" Then
objFinttings_temp.IncluirFittingsTempTQIFLTTipico(Session("cod_usuario_usu"))
'objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(CType(txbNumberofColumns.Text, Double))
objFinttings_temp.AtualizaFittingsTempColumnWell_24_in_Diam(txbNumberofColumns.Text)
tbFittingsFonte.Visible = True
tbFittingsFonte.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
Else
objFinttings_temp.IncluirFittingsTQIFLTDetalhado(Session("cod_fonte_fon"))
tbFittings.Visible = True
tbFittings.HeaderText = ""
TcPrincipal.ActiveTabIndex = 6
End If
GrvFittingsFonte.DataBind()
If ddlSelfSupportingRoof.SelectedValue = 1 Or ddlSelfSupportingRoof.SelectedValue = "-1" Then
txbNumberofColumns.Enabled = False
rvNumColuna.Visible = False
ddlEffectiveColumnDiameter.Enabled = False
rvDiametroEfetivoColuna.Visible = False
Else
txbNumberofColumns.Enabled = True
rvNumColuna.Visible = True
ddlEffectiveColumnDiameter.Enabled = True
rvDiametroEfetivoColuna.Visible = True
End If
End If
End If
End Sub
enter code here
use Page.ClientScript.RegisterStartupScript()
it will run after the page loads.