Sending Email within loop in a function - vb.net

code is building the email but it is only displaying one row when there is six. I got it correct on the text file but I need it to do the same in the email message. I think I got the for next statement in the wrong location. Here is the example of the code that I am having problem with. I do not know how to place the for next statement without interrupting the vbLine
For Each p In query
If p.Contract_No IsNot Nothing Then
ContractNo = p.Contract_No
Else
ContractNo = " "
End If
If p.Vendor_Name IsNot Nothing Then
VenderName = p.Vendor_Name
Else
VenderName = " "
End If
If p.Termination_Date IsNot Nothing Then
TerminationDate = p.Termination_Date
' ReportDateStr = ReportDate.ToString
TerminationDateStr = String.Format("{0:MM/dd/yyyy}", TerminationDate)
Else
TerminationDateStr = " "
End If
If p.Dept_Name IsNot Nothing Then
DeptName = p.Dept_Name
Else
DeptName = " "
End If
If p.Renewal_Option_Desc IsNot Nothing Then
RenewalOption = p.Renewal_Option_Desc
Else
RenewalOption = " "
End If
If p.Contract_Desc IsNot Nothing Then
ContractDesc = p.Contract_Desc
Else
ContractDesc = " "
End If
If p.Contact_Email IsNot Nothing Then
ContactEmail = p.Contact_Email
Else
ContactEmail = "** N/A ** "
End If
' sends email with attachment
EmailMsgBody = "-- TOTAL # OF CONTRACTS WITH FAILSAFE DATE ON " + DateStr + " IS: " + icnt.ToString + vbCrLf +
vbNewLine + " __________________ " +
vbNewLine +
vbNewLine + " *****Contracts**** " +
vbNewLine + " __________________ " +
vbNewLine +
vbNewLine + "Contract#" + " " + "Vender Name" + " " + "Termination Date" + " " + "Dept Name" + " " + "Renewal Option" + " " + "Contract Desc" + " " + "Email Address" +
vbNewLine + "------------" + " " + "-----------------" + " " + "---------------------" + " " + "--------------" + " " + "--------------------" + " " + "-----------------" + " " + "-----------------" +
vbNewLine + ContractNo.PadRight(18) + " " + _
VenderName.PadRight(38) + " " + _
TerminationDateStr.PadRight(26) + " " + _
DeptName.PadRight(27) + " " + _
RenewalOption.PadRight(45) + " " + _
ContractDesc.PadRight(32) + " " + _
ContactEmail.PadRight(11) + " "

Related

Sending object(json) using vba

Im trying to send json object in Outlook using vba. Here is my code:
Dim Msg As Outlook.MeetingItem
Set Msg = Item
Set recips = Msg.Recipients
Dim regEx As New RegExp
regEx.Pattern = "^\w+\s\w+,\sI351$"
Dim URL As String
URL = "https://webhook.site/55759d1a-7892-4c20-8d15-3b8b7f1bf3b3"
For Each recip In recips
If regEx.Test(recip.AddressEntry) And recip.AddressEntry <> "Application Management Linux1, I351" Then
Dim convertedJson As Object
Set convertedJson = JsonConverter.ParseJson("{""fields"": 123}")
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "POST", URL, False
xhr.setRequestHeader "Content-Type", "application/json"
xhr.Send (convertedJson)
End If
Next
If I send just plane text it works well but i can't send convertedJson. Is it possible to send an object?
UPDATE
I can't even do Debug.Print convertedJson
I was tormented by these libraries in the end I did a very terrible thing
Dim flds, prt, id, smry, descrp, issu, name, lfbrkt, rtbrkt, cma, dbdots, jsTest, issuName As String
flds = "'fields'"
prt = "'project'"
id = "'id'"
smry = "'summary'"
descrp = "'description'"
issu = "'issuetype'"
issuName = "'Improvement'"
name = "'name'"
lfbrkt = "{"
rtbrkt = "}"
cma = ","
dbdots = ":"
jsTest = lfbrkt + flds + dbdots + " " + lfbrkt + vbCrLf + vbTab + prt + dbdots + " " + lfbrkt + vbCrLf + vbTab + vbTab + id + dbdots + " " + "30611" + vbCrLf + vbTab + rtbrkt + cma + vbCrLf + vbTab + smry + dbdots + " " + "'" + CStr(Msg.Subject) + "'" + cma + vbCrLf + vbTab + descrp + dbdots + " " + "'" + CStr(Msg.Body) + "'" + cma + vbCrLf + vbTab + issu + dbdots + " " + lfbrkt + vbCrLf + vbTab + vbTab + name + dbdots + " " + issuName + vbCrLf + vbTab + rtbrkt + vbCrLf + rtbrkt + rtbrkt
And I got this

Ordering subsections of case statement

So I have a query with the following sort order:
String sortOrder = "CASE " + ICCGoal.COLUMNS.category
+ " WHEN '" + GoalCategory.PHYSICAL_ACTIVITY.getEncodedValue() + "' THEN 1"
+ " WHEN '" + GoalCategory.SLEEP.getEncodedValue() + "' THEN 2"
+ " WHEN '" + GoalCategory.SOCIAL.getEncodedValue() + "' THEN 3"
+ " WHEN '" + GoalCategory.MOOD.getEncodedValue() + "' THEN 4"
+ " WHEN '" + GoalCategory.ENERGY.getEncodedValue() + "' THEN 5"
+ " END";
is there anyway to order the sections of the returned values?
Currently, I have all goals of "SLEEP" type returned after the "PHYSICAL_ACTIVITY" and before "SOCIAL" goals, in whatever order they are stored.
Would it be possible to return them ordered by date created? Or just ordered in another way than default?
Just add a secondary sorting criteria:
String sortOrder = "CASE " + ICCGoal.COLUMNS.category
+ " WHEN '" + GoalCategory.PHYSICAL_ACTIVITY.getEncodedValue() + "' THEN 1"
+ " WHEN '" + GoalCategory.SLEEP.getEncodedValue() + "' THEN 2"
+ " WHEN '" + GoalCategory.SOCIAL.getEncodedValue() + "' THEN 3"
+ " WHEN '" + GoalCategory.MOOD.getEncodedValue() + "' THEN 4"
+ " WHEN '" + GoalCategory.ENERGY.getEncodedValue() + "' THEN 5"
+ " END" // Original ordering from the OP
+ ", date_created"; // Secondary term

Reduce line continuation in excel

I'm trying to make excel create XML files using VBA (that my first time), so I managed to create a code but I keep getting the message that there are too many line continuations
Here is my code
Sub testXLStoXML()
sTemplateXML = _
"<?xml version='1.0'?>" + vbNewLine + _
"<offers>" + vbNewLine + _
" <offer>" + vbNewLine + _
" <offer_identifier>" + vbNewLine + _
" </offer_identifier>" + vbNewLine + _
" <offer_title>" + vbNewLine + _
" </offer_title>" + vbNewLine + _
" <offer_description>" + vbNewLine + _
" </offer_description>" + vbNewLine + _
" <offer_featured_image>" + vbNewLine + _
" </offer_featured_image>" + vbNewLine + _
" <offer_cat>" + vbNewLine + _
" </offer_cat>" + vbNewLine + _
" <offer_location>" + vbNewLine + _
" </offer_location>" + vbNewLine + _
" <offer_tags>" + vbNewLine + _
" </offer_tags>" + vbNewLine + _
" <offer_type>" + vbNewLine + _
" </offer_type>" + vbNewLine + _
" <offer_start>" + vbNewLine + _
" </offer_start>" + vbNewLine + _
" <offer_expire>" + vbNewLine + _
" </offer_expire>" + vbNewLine + _
" <offer_store>" + vbNewLine + _
" </offer_store>" + vbNewLine + _
" <!-- store -->" + vbNewLine + _
" <store_title>" + vbNewLine + _
" </store_title>" + vbNewLine + _
" <store_letter>" + vbNewLine + _
" </store_letter>" + vbNewLine + _
" <store_description>" + vbNewLine + _
" </store_description>" + vbNewLine + _
" <store_logo>" + vbNewLine + _
" </store_logo>" + vbNewLine + _
" <store_link>" + vbNewLine + _
" </store_link>" + vbNewLine + _
" <store_facebook>" + vbNewLine + _
" </store_facebook>" + vbNewLine + _
" <store_twitter>" + vbNewLine + _
" </store_twitter>" + vbNewLine + _
" <store_google>" + vbNewLine + _
" </store_google>" + vbNewLine + _
" <!-- store -->" + vbNewLine + _
" <!-- DEAL RELATED -->" + vbNewLine + _
" <deal_items>" + vbNewLine + _
" </deal_items>" + vbNewLine + _
" <deal_item_vouchers>" + vbNewLine + _
" </deal_item_vouchers>" + vbNewLine + _
" <deal_price>" + vbNewLine + _
" </deal_price>" + vbNewLine + _
" <deal_sale_price>" + vbNewLine + _
" </deal_sale_price>" + vbNewLine + _
" <deal_discount>" + vbNewLine + _
" </deal_discount>" + vbNewLine + _
" <deal_voucher_expire>" + vbNewLine + _
" </deal_voucher_expire>" + vbNewLine + _
" <deal_in_short>" + vbNewLine + _
" </deal_in_short>" + vbNewLine + _
" <deal_type>" + vbNewLine + _
" </deal_type>" + vbNewLine + _
" <deal_link>" + vbNewLine + _
" </deal_link>" + vbNewLine + _
" </offer>" + vbNewLine + _
"</offers>" + vbNewLine +
Is there a way to bypass the limit or make this work?
Per Microsoft, "There is a limit to the number of lines you can join with line-continuation characters. This error has the following cause and solution:
Your code has more than 25 physical lines lines joined with line-continuation characters, or more than 24 consecutive line-continuation characters in a single line. Make some of the constituent lines physically longer to reduce the number of line-continuation characters needed, or break the construct into more than one statement."
The line continuations are merely for ease of reading the code and are necessary to have after each tag the way you have it now

How to use Group By with AND in java codes

Trying to get values from my table but having problem with my snytaxes
there is wrong type with "Group By" usage with "AND"
any help will be apriciated
"SELECT " + C_CINSIYET + " FROM " + TABLE_COMPANYS + " WHERE "
+ C_MARKA + " = '" + companyMarka.getComp_marka() + "'"
+ " AND " + C_FIRMA + " = '"
+ companyMarka.getComp_name() + "' GROUP BY "
+ C_CINSIYET + "AND"+C_FIRMA;

How To Make A File Be Named From A Texbox in VB

Im trying to get a file to be created and named when a button is pressed. But I need the file name to contain text from a textbox.
Code:
My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text + ".txt", "[" + TimeOfDay + "]" + "Email: " + txtEmail.Text + vbNewLine + "Username: " + txtUser.Text + vbNewLine + "Password: " + txtPass.Text + vbNewLine + "Secuirty: " + txtSecuirty.Text + vbNewLine + vbNewLine, True)
Simple Code:
My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text + ".txt", {loads of stuff}, True)
I have loads of if functions, to stop the disallowed characters.
The error I am getting is:
Expression does not produce a value
Try to see if this will work for you.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text.ToString() + ".txt", "test message", True)
End Sub
Or you can change your code to
Dim strFileText As String = ""
strFileText =
"[" & TimeOfDay.ToString() & "] " & vbCrLf &
"Email: " & txtEmail.Text.ToString() & vbCrLf &
"Username: " & txtUser.Text.ToString() & vbCrLf &
"Password: " & txtPass.Text.ToString() & vbCrLf &
"Security: " & txtSecurity.Text.ToString() & vbCrLf & vbCrLf
My.Computer.FileSystem.WriteAllText("c:\temp\" + txtUser.Text.ToString() + ".txt", strFileText, True)