I tried everything I know but it still gives me this error. Help please. Thank you in advance.
(Stack is not letting me post this with the following error with the message "It looks like your post is mostly code; please add some more details." So I'm repeating this message several times -- please ignore. "It looks like your post is mostly code; please add some more details.")
//#version=5
indicator(title='Hull MA Multi-Time Frame', shorttitle='HMA MTF', overlay=false)
PDS = input.int(7, title = "Periods (PDS)", minval=2)
SRC = input(close, title='Source')
HMA1_res = input.timeframe('15', title = "HMA1")
HMA2_res = input.timeframe('30', title = "HMA2")
HMA3_res = input.timeframe('60', title = "HMA3")
HMA4_res = input.timeframe('240', title = "HMA4")
f_HMA(_PDS, _SRC) =>
_xHMA = ta.wma(2 * ta.wma(_SRC, _PDS / 2) - ta.wma(_SRC, _PDS), math.round(math.sqrt(_PDS))))
_xHMA_is_up = _HMA >= _xHMA[1]
[_xHMA, _xHMA_is_up]
[xHMA1, _xHMA1_is_up] = request.security(syminfo.tickerid, HMA1_res, f_HMA(PDS, SRC))
HMA1_color = xHMA1_is_up ? color.green : color.red
HMA1_text = f_res_to_string(HMA1_res) + "=" + str.tostring(xHMA1, "#.00")
plot(xHMA1, color = HMA1_color, linewidth=1)
var label HMA1_label = label.new(x = na, y = na, color = #00000000, size = size.normal, style = label.style_label_left)
label.set_xy(HMA1_label, x = bar_index, y = xHMA1)
label.set_textcolor(HMA1_label, HMA1_color)
label.set_text(HMA1_label, HMA1_text)
[xHMA2, _xHMA2_is_up] = request.security(syminfo.tickerid, HMA2_res, f_HMA(PDS, SRC))
HMA2_color = xHMA2_is_up ? color.green : color.red
HMA2_text = f_res_to_string(HMA2_res) + "=" + str.tostring(xHMA2, "#.00")
plot(xHMA2, color = HMA2_color, linewidth=1)
var label HMA2_label = label.new(x = na, y = na, color = #00000000, size = size.normal, style = label.style_label_left)
label.set_xy(HMA2_label, x = bar_index, y = xHMA2)
label.set_textcolor(HMA2_label, HMA2_color)
label.set_text(HMA2_label, HMA2_text)
[xHMA3, _xHMA3_is_up] = request.security(syminfo.tickerid, HMA3_res, f_HMA(PDS, SRC))
HMA3_color = xHMA3_is_up ? color.green : color.red
HMA3_text = f_res_to_string(HMA3_res) + "=" + str.tostring(xHMA3, "#.00")
plot(xHMA3, color = HMA3_color, linewidth=1)
var label HMA3_label = label.new(x = na, y = na, color = #00000000, size = size.normal, style = label.style_label_left)
label.set_xy(HMA3_label, x = bar_index, y = xHMA3)
label.set_textcolor(HMA3_label, HMA3_color)
label.set_text(HMA3_label, HMA3_text)
[xHMA4, _xHMA4_is_up] = request.security(syminfo.tickerid, HMA4_res, f_HMA(PDS, SRC))
HMA4_color = xHMA4_is_up ? color.green : color.red
HMA4_text = f_res_to_string(HMA4_res) + "=" + str.tostring(xHMA4, "#.00")
plot(xHMA4, color = HMA4_color, linewidth=1)
var label HMA4_label = label.new(x = na, y = na, color = #00000000, size = size.normal, style = label.style_label_left)
label.set_xy(HMA4_label, x = bar_index, y = xHMA4)
label.set_textcolor(HMA4_label, HMA4_color)
label.set_text(HMA4_label, HMA4_text)
if you put your cursor to the right of the () it will highlight the other end if theres one to close it try removing the extra one
Picture
Code =D
I was in a good mood you were pretty close.. pretty sure its what you were trying to get.. only had to add a x to the _(x)HMA >= in the function
and remove the f_string function thing because the timeframes are already strings
and the extra )
Looks interesting whats the idea behind this if you dont mind me asking?
I need to import 'contacts' into my database from several external sources.
Some 'contacts' may already exist so I only need 'new' data.
I've written an update records code however it will overwrite all data therefore damaging the integrity of the table as the old data may contain some valid values.
I tried using an update/append query however this only OVERWROTE the values of the original field not UPDATED IF OLD VALUE WAS NULL/FALSE ONLY. The issue with this is it will apply/remove profile flags that result in correspondence and data usage (Incorrect update = potential breach of GDPR).
I can't program in SQL, I understand how the functions work and what they do but not how to compile/what order (yet) hence using VBA for now.
Dim myR As Recordset
Dim myR2 As Recordset
Set myR = CurrentDb.OpenRecordset("Staging - Import", dbOpenDynaset)
Set myR2 = CurrentDb.OpenRecordset("Contacts", dbOpenDynaset)
Do Until myR.EOF = True
myR2.FindFirst ("Email = '" & myR![Email] & "'")
If myR2.NoMatch = True Then
myR2.AddNew
myR2![Email] = myR![Email]
myR2![First Name] = myR![First Name]
myR2![Last Name] = myR![Last Name]
myR2![Position] = myR![Position]
myR2![Company] = myR![Company]
myR2![Industry] = myR![Industry]
myR2![Size] = myR![Size]
myR2![Website] = myR![Website]
myR2![Location] = myR![Location]
myR2![Office Number] = myR![Office Number]
myR2![Mobile Number] = myR![Mobile Number]
myR2![Source] = myR![Source]
myR2![CFO-DEL] = myR![CFO-DEL]
myR2![CFO-SPON] = myR![CFO-SPON]
myR2![DP-DEL] = myR![DP-DEL]
myR2![DP-SPON] = myR![DP-SPON]
myR2![HR-DEL] = myR![HR-DEL]
myR2![HR-SPON] = myR![HR-SPON]
myR2![CIO-DEL] = myR![CIO-DEL]
myR2![CIO-SPON] = myR![CIO-SPON]
myR2![CMO-DEL] = myR![CMO-DEL]
myR2![CMO-SPON] = myR![CMO-SPON]
myR2![CISO-DEL] = myR![CISO-DEL]
myR2![CISO-SPON] = myR![CISO-SPON]
myR2![NIS] = myR![NIS]
myR2![Supress] = myR![Surpress]
myR2.Update
Else
myR2.Edit
myR2![First Name] = myR![First Name]
myR2![Last Name] = myR![Last Name]
myR2![Position] = myR![Position]
myR2![Company] = myR![Company]
myR2![Industry] = myR![Industry]
myR2![Size] = myR![Size]
myR2![Website] = myR![Website]
myR2![Location] = myR![Location]
myR2![Office Number] = myR![Office Number]
myR2![Mobile Number] = myR![Mobile Number]
myR2![Source] = myR![Source]
myR2![CFO-DEL] = myR![CFO-DEL]
myR2![CFO-SPON] = myR![CFO-SPON]
myR2![DP-DEL] = myR![DP-DEL]
myR2![DP-SPON] = myR![DP-SPON]
myR2![HR-DEL] = myR![HR-DEL]
myR2![HR-SPON] = myR![HR-SPON]
myR2![CIO-DEL] = myR![CIO-DEL]
myR2![CIO-SPON] = myR![CIO-SPON]
myR2![CMO-DEL] = myR![CMO-DEL]
myR2![CMO-SPON] = myR![CMO-SPON]
myR2![CISO-DEL] = myR![CISO-DEL]
myR2![CISO-SPON] = myR![CISO-SPON]
myR2![NIS] = myR![NIS]
myR2![Supress] = myR![Surpress]
myR2.Update
End If
myR.MoveNext
Loop
Set myR = Nothing
End Sub
Is there a simpler way to write this or should I be utilising the code
myR2.FindFirst ("Email = '" & myR![Email] & "'")
If myR2.NoMatch = True Then
For each value, creating effectively 15-20 subs and a macro to run all together?
I tried several code variations attempting to include elseIf, isNull() and isFalse() however they always failed to compile or no update was completed/records changed.
I need the code to do the following:
Check the contact exists in contacts table
If contact does not exist, add all data
If contact does exist, add new data or update yes/no fields from no to yes
NOTE: Currently 'contacts' table is empty as we need to create new/merge duplicates before the data is imported to the 'contacts' table.
So Contacts is currently:
Email Name Surname
- - -
- - -
- - -
- - -
Staging - Import is currently:
Email Name Surname
b#b.c Brad
t#b.c Tony Tiger
b#b.c B Pitt
r#b.c Ryan Reynolds
Contacts should look like this after completed:
Email Name Surname
t#b.c Tony Tiger
b#b.c Brad Pitt
r#b.c Ryan Reynolds
Determining what to update or add when comparing string data can be quite complicated and often involves case-by-case review. What rule should be applied to program decision to take "Brad" from one record and "Pitt" from other? What if data for the same email were: Brad Pitt and Bradley Pitt? Which is correct and should be saved? Probably have to do a query that finds duplicate emails in Staging and make case-by-case decision on what to fix/delete for these duplicates. Then insert to Contacts. Insert code can test content of each field for Null or False and determine whether to accept new value.
For non-yes/no field, use Nz() function (assumes text field will not have empty string)
myR2![First Name] = Nz(myR2![First Name], myR![First Name])
or (to deal with possible empty string)
If myR2![First Name] & "" = "" Then myR2![First Name] = myR![First Name]
(advise not to allow empty string in text field nor zero default value for number field in table design).
For yes/no field, test for False (do not set DefaultValue property in table design):
myR2![Supress] = IIf(myR2![Supress] = False, myR![Supress], True)
or
If myR2![Supress] = False Then myR2![Supress] = myR![Supress]
Shorter code for import procedure. Modify with the above.
Do Until myR.EOF = True
myR2.FindFirst ("Email = '" & myR![Email] & "'")
If myR2.NoMatch = True Then
myR2.AddNew
myR2![Email] = myR![Email]
Else
myR2.Edit
End If
myR2![First Name] = myR![First Name]
myR2![Last Name] = myR![Last Name]
myR2![Position] = myR![Position]
myR2![Company] = myR![Company]
myR2![Industry] = myR![Industry]
myR2![Size] = myR![Size]
myR2![WebSite] = myR![WebSite]
myR2![Location] = myR![Location]
myR2![Office Number] = myR![Office Number]
myR2![Mobile Number] = myR![Mobile Number]
myR2![Source] = myR![Source]
myR2![CFO-DEL] = myR![CFO-DEL]
myR2![CFO-SPON] = myR![CFO-SPON]
myR2![DP-DEL] = myR![DP-DEL]
myR2![DP-SPON] = myR![DP-SPON]
myR2![HR-DEL] = myR![HR-DEL]
myR2![HR-SPON] = myR![HR-SPON]
myR2![CIO-DEL] = myR![CIO-DEL]
myR2![CIO-SPON] = myR![CIO-SPON]
myR2![CMO-DEL] = myR![CMO-DEL]
myR2![CMO-SPON] = myR![CMO-SPON]
myR2![CISO-DEL] = myR![CISO-DEL]
myR2![CISO-SPON] = myR![CISO-SPON]
myR2![NIS] = myR![NIS]
myR2![Supress] = myR![Supress]
myR2.Update
myR.MoveNext
Loop
Another, assuming recordsets have exactly same fields.
Dim myR As DAO.Recordset
Dim myR2 As DAO.Recordset
Dim fld As DAO.Field
Set myR = CurrentDb.OpenRecordset("Staging - Import", dbOpenDynaset)
Set myR2 = CurrentDb.OpenRecordset("Contacts", dbOpenDynaset)
Do Until myR.EOF = True
myR2.FindFirst "Email = '" & myR![Email] & "'"
If myR2.NoMatch = True Then
myR2.AddNew
myR2![Email] = myR![Email]
Else
myR2.Edit
End If
For Each fld In myR.Fields
If fld.Name <> "Email" And _
(myR2.Fields(fld.Name) & "" = "" Or myR2.Fields(fld.Name) = False) Then
myR2.Fields(fld.Name) = fld
End If
Next
myR2.Update
myR.MoveNext
Loop
Any help would be great. I cant seem to get the ELSEIF with the AND to work.
I am using a user-form. When they press the button the user form appears with check boxes. I am having trouble when both check boxes are checked. individually they work fine,
I am not sure what i am doing wrong. any help would be greatly appreciated
If Intact.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
End With
ElseIf Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storCompugen
End With
ElseIf Intact.Value And Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
storDate1 = Sheets("escalation").Cells(Selection.Row, 2)
storProject1 = Sheets("escalation").Cells(Selection.Row, 3)
StorBill1 = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
.formfields("text5").Result = storDate1
.formfields("Text6").Result = storProject1
.formfields("Text7").Result = StorBill1
.formfields("Text8").Result = storCompugen
End With
End If
Thanks in advance
Try changing the order. Otherwise as soon as one condition is met the If clause is exited.
If Intact.Value And Compugen.Value Then
'code
ElseIf Intact.Value Then
'code
ElseIf Compugen.Value Then
'code
End If
If Intact.Value = True is true then the first, not the third block will run.
Similarly if Intact.Value = True is not true and Compugen.Value = True is true, then the second block will run.
So you can see that the third block is not reachable.
The solution is to put the Intact.Value = True And Compugen.Value = True case first in the group.
Finally, Foo.Value = True is a tautology of the simpler Foo.Value. You can drop all the explicit = True comparisons.
I have this code to check if a user already exists, but it is not working.
For some reason system is skipping this function:
if Cadastrar_CodEmpresa = verificar("Usuario") Then
Response.Redirect("index.asp?pagina=login")
Here is the code:
if request.Form("commentForm") = "sim" Then
set verificar = conexao.execute ("select * from empresas")
Cadastrar_CodEmpresa = request.Form("CodEmpresa")
Cadastrar_Segmento = request.Form("Segmento")
Cadastrar_Endereco = request.Form("Endereco")
Cadastrar_Bairro = request.Form("Bairro")
Cadastrar_Cidade = request.Form("Cidade")
Cadastrar_CEP = request.Form("CEP")
Cadastrar_Pais = request.Form("Pais")
Cadastrar_Contato = request.Form("Contato")
Cadastrar_Telefone = request.Form("Telefone")
Cadastrar_Email = request.Form("email")
if Cadastrar_CodEmpresa = verificar("Usuario") Then
response.Redirect("index.asp?pagina=login")
Else
set cadastrar_cadastro = conexao.execute("insert into Empresas (Usuario) Values ('" & Cadastrar_CodEmpresa & "')")
End if
... some more stuff ...
End if
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