I am trying to get the value "aaG40a2f-53d3-8f74-3c200403223" from the json code below that's in json.
My vb.net code looks like this:
For Each Row In json("data")("records")("Form")
Try
For rowNum = 0 To result_RowNames.Length - 1
result_rowData(intX) = NullSafeSelect(Row, result_RowNames(rowNum))
Select Case result_RowProperTypes(rowNum)
Case "textField"
_tmpHtml += "<td>" & vbCrLf
_tmpHtml += "<input type=""text"" " & _
"data-first=""yes"" " & _
"data-uid=""" & NullSafeSelect(Row("#uid"), result_RowNames(rowNum)) & """ " & _
"onchange=""updateChange(this);"" " & _
"id=""textbox_" & rowNum & """ " & _
"class=""form-control small"" " & _
"value=""" & result_rowData(intX) & """>" & vbCrLf
......etc etc...
My json in ("data")("records")("Form") looks like this:
{
"#application_uid": "af74c279-4340-8441-2dR4e696gb1",
"#draft_ownerid": "",
"#flowState": "ST_NewName",
"#has_draft": "",
"#id": "63",
"#uid": "aaG40a2f-53d3-8f74-3c200403223",
"F_FName": "test1",
"F_LName": "test2"
}
The code above works - it just does not produce a value for uid as seen below in the output of HTML:
<input type="text" data-first="yes" data-uid="" onchange="updateChange(this);" id="textbox_0" class="form-control small" value="test1">
Looks like all I needed to do was just to use
Dim tmpUID = Row("#uid").ToString
in order to get the value I was looking for.
Related
I have extracted some data from a JSON Stream with one element being an array. The result of this is
"{" & vbCrLf & " ""2019-08-22"": 128.75," & vbCrLf & " ""2019-08-23"": 151.47," & vbCrLf & " ""2019-08-24"": 151.47" & vbCrLf & "}"
I am then trying to separate the 3 values and place them into a database using VB.
Tried parse, deserialize but going round in circles.
Dim uObject = Newtonsoft.Json.Linq.JObject.Parse("{" & vbCrLf & " ""2019-08-22"": 128.75," & vbCrLf & " ""2019-08-23"": 151.47," & vbCrLf & " ""2019-08-24"": 151.47" & vbCrLf & "}")
DEBUG.PRINT(uObject(1, 1)) - This fails
Trying to get the following output
Key1: 2019-08-22 Value1: 128.75
Key2: 2019-08-23 Value1: 151.47
Key3: 2019-08-24 Value1: 151.47
I did a quick test:
Dim JSON_Obj As JObject = JObject.Parse("{" & vbCrLf & " ""2019-08-22"": 128.75," & vbCrLf & " ""2019-08-23"": 151.47," & vbCrLf & " ""2019-08-24"": 151.47" & vbCrLf & "}")
For Each item In JSON_Obj
Debug.Print(String.Format("Key: {0} Value: {1}", item.key, item.value))
Next
'>Key: 2019-08-22 Value: 128.75
'>Key: 2019-08-23 Value: 151.47
'>Key: 2019-08-24 Value: 151.47
If you can't get it by key name, simply get them with array index or something, like JSON_Obj1 = JSON_Obj.Children.ToArray()(0)
With great help from CruelD; my final working code is
Dim JSON_Obj As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse("{" & vbCrLf & " ""2019-08-22"": 128.75," & vbCrLf & " ""2019-08-23"": 151.47," & vbCrLf & " ""2019-08-24"": 151.47" & vbCrLf & "}")
Dim JSON_Data As List(Of JToken) = JSON_Obj.Children().ToList
For Each uItem As JProperty In JSON_Data
Debug.Print(uItem.Name.ToString & " - " & uItem.Value.ToString)
Next
This works a treat.
I have scoured around for topics relating to the idea of changing a listbox recordsource using VBA and I have created my own piece.. but it only works 1/2 way.
I have a form for tracking attendance issues for associates.. We have 2 locations, 1 in Az and 1 in Tx.. Due to recent laws that changed in Az our policies were updated.. The difference is in Az an occurrence is held for 1 year (or 365 days) and in Tx the occurrence is held for 3 months (90 days).
The basic idea is this:
If the text box for "supervisor state" = Az, the HISTORYBOX should show/calculate out 365 days of records.. else if the "supervisor state" = Tx then the HISTORYBOX should show/calculate 90 days of records.
My issue is when selecting an AZ supervisor.. it is still pulling the 90 day version of the code.. not the 365 day version.
Here is the code I have been able to create so far:
Public Sub ChangeHistory()
Dim strSQL As String
If Me.txtsupervisorstate.Value = "AZ" Then
strSQL = "SELECT OccuTable.ValueOfOccurance, " & _
" OccuTable.Short_Code_Occurance, " & _
" OccuTable.OccuranceDate, " & _
" OccuTable.Roll_Off_Date, " & _
" OccuTable.Notes, " & _
" OccuTable.AssociatedIDNumber " & _
" FROM OccuTable GROUP BY OccuTable.ValueOfOccurance, " & _
" OccuTable.Short_Code_Occurance, " & _
" OccuTable.OccuranceDate, " & _
" OccuTable.Roll_Off_Date, " & _
" OccuTable.Notes, " & _
" OccuTable.AssociatedIDNumber " & _
" WHERE (((OccuTable.OccuranceDate) Between
Date() And Date()-365) And " & _
"
((OccuTable.AssociatedIDNumber)=Forms!OccuranceTracker!txtAssociateID))
ORDER BY OccuTable.OccuranceDate DESC;"
ElseIf Me.txtsupervisorstate.Value = "TX" Then
strSQL = " SELECT OccuTable.ValueOfOccurance, " & _
" OccuTable.Short_Code_Occurance, " & _
" OccuTable.OccuranceDate, " & _
" OccuTable.Roll_Off_Date, " & _
" OccuTable.Notes, " & _
" OccuTable.AssociatedIDNumber " & _
" FROM OccuTable GROUP BY OccuTable.ValueOfOccurance, " & _
" OccuTable.Short_Code_Occurance, " & _
" OccuTable.OccuranceDate, " & _
" OccuTable.Roll_Off_Date, " & _
" OccuTable.Notes, " & _
" OccuTable.AssociatedIDNumber " & _
" WHERE (((OccuTable.OccuranceDate) Between
Date() And Date()-90) And
((OccuTable.AssociatedIDNumber)=Forms!OccuranceTracker!txtAssociateID))
ORDER BY OccuTable.OccuranceDate DESC;"
Me.listBoxPastOccurances.RowSource = strSQL
End If
Call SumOfOccu
End Sub
Here is what the form looks like:
AttendanceForm
Oh my goodness I was WAYYY overthinking this issue. My newish self to VBA was trying to find the most convoluted and confusing way to make this work.. After ALOT of research around StackOverflow I found that I can write a query and save that query for future use.. So I wrote 2 individual queries (Occurrences365 and Occurrences90).. These duplicated the original query for the listbox (when I only needed the 90 day version), which was known to work; which made creating the 365 day version super simple.
Then I was able to reduce all my other convoluted code down to this:
Public Sub ClearHistory()
If Me![txtsupervisorstate] = "AZ" Then
Me![listBoxPastOccurances].RowSource = "Occurrences365"
ElseIf Me![txtsupervisorstate] = "TX" Then
Me![listBoxPastOccurances].RowSource = "Occurrences90"
End If
Call SumOfOccu
End Sub
Public Function SumOfOccu()
If Me![txtsupervisorstate] = "AZ" Then
Me.txtSumOfOccu = DSum("valueofoccurance", "occurrences365")
ElseIf Me![txtsupervisorstate] = "TX" Then
Me.txtSumOfOccu = DSum("valueofoccurance", "occurrences90")
End If
End Function
Now I can go back and start eliminating unnecessary subs/functions, clean up the naming conventions and make it overall 'cleaner'.
For anyone interested.. the queries look like this after I wrote them as a saved query.
SELECT OccuTable.ValueOfOccurance, OccuTable.ShortCodeOccurance,
OccuTable.OccuranceDate, OccuTable.RollOffDate, OccuTable.Notes,
OccuTable.AssociatedIDNumber
FROM OccuTable
GROUP BY OccuTable.ValueOfOccurance, OccuTable.ShortCodeOccurance,
OccuTable.OccuranceDate, OccuTable.RollOffDate, OccuTable.Notes,
OccuTable.AssociatedIDNumber
HAVING (((OccuTable.OccuranceDate) Between Date() And Date()-365) AND
((OccuTable.AssociatedIDNumber)=[Forms]![OccuranceTracker]![txtAssociateID]))
ORDER BY OccuTable.OccuranceDate DESC;
again.. the only difference between the 2 is this one piece.
And Date()-365)
And Date()-90)
But everything works!
Thank you so much for the suggestions and pushing me to keep looking!
I am having trouble with applying Bold on a part of a sentence for an automatically generated email.
In my VBA script:
Public strBody As String
.HtmlBody = strBody
Dim FormulaCell As Range
Dim FormulaRange As Range
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
I am able to Bold a whole sentence using "< b >" & "**Text Here**" & "< /b >" &
But it seems impossible to apply the same logic to a more complex sentence, or a referenced value.
strBody = "Hello, " & vbNewLine & vbNewLine & _
"Your task : " & Cells(FormulaCell.Row, "B").Value & " with the mention: " & Cells(FormulaCell.Row, "C").Value & " is nearing its Due Date: "
What I would like to Bold in the above sentence is the value of the FormulaCells.
strBody = "Hello, " & vbNewLine & vbNewLine & _
"Your task : " & **Cells(FormulaCell.Row, "B").Value** & " with the mention: " & **Cells(FormulaCell.Row, "C")**.Value & " is nearing its Due Date: "
So it would look something like that in my email:
Hello
Your task : Eat Potatoes with the mention: Potatoes are Delicious is nearing its Due Date:
Is this something that can be done?
edited
strBody = "<p>Hello</p>, " & vbNewLine & vbNewLine & _
"<p>Your task : <b>" & Cells(FormulaCell.Row, "B").Value & _
"</b> with the mention: <b>" & Cells(FormulaCell.Row, "C").Value & _
"</b> is nearing its Due Date: </p>"
I have the following ms access query. I want it to query with the gender (female or male) selected from the combo box. At the moment, when I select "female", the query results also includes all male persons.
How should I format this code:
WHERE (((Q_Gender_Statistics.Year) Like [cboYear] & "*") AND ((Q_Gender_Statistics.Gender) Like "*" & [cboGender] & "*"))
Don't use Like if not needed:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = '" & [cboGender] & "'"
If cboGender looks up "Male/Female" form an index value, try this:
" WHERE Q_Gender_Statistics.Year = " & [cboYear] & " AND Q_Gender_Statistics.Gender = " & [cboGender] & ""
I'm attempting to use the AXE library to parse some JSON data. In trying to make sure that everything is running correctly I have created a test page. I am getting an error:
Error Type:
Microsoft JScript compilation (0x800A03EA)
Syntax error
json2.asp Line 1
I'm using the code that is in the json2.asp file to test this out:
<script language="javascript" runat="server" src="json2.asp"></script>
<%
dim TestData : set TestData = JSON.parse(join(array( _
"{", _
" ""firstname"": ""Fabio"",", _
" ""lastname"": ""Nagao"",", _
" ""alive"": true,", _
" ""age"": 27,", _
" ""nickname"": ""nagaozen"",", _
" ""fruits"": [", _
" ""banana"",", _
" ""orange"",", _
" ""apple"",", _
" ""papaya"",", _
" ""pineapple""", _
" ],", _
" ""complex"": {", _
" ""real"": 1,", _
" ""imaginary"": 2", _
" }", _
"}" _
)))
Response.write(TestData.firstname & vbNewline) ' prints Fabio
Response.write(TestData.alive & vbNewline) ' prints True
Response.write(TestData.age & vbNewline) ' prints 27
Response.write(TestData.fruits.get(0) & vbNewline) ' prints banana
Response.write(TestData.fruits.get(1) & vbNewline) ' prints orange
Response.write(TestData.complex.real & vbNewline) ' prints 1
Response.write(TestData.complex.imaginary & vbNewline) ' prints 2
' You can also enumerate object properties ...
dim key : for each key in TestData.keys()
Response.write( key & vbNewline )
next
set TestData = nothing
Where am I going wrong?