Difficulties with constructing path to desired element?, Excel VBA - html

I'm new to VBA, trying to learn it. Facing a minor problem in extracting one data point from html.
Below is the html
{ div class="category">Category: Shopping
I just want to extract ( Shopping ) from this but what I'm getting is (Category:Shopping).
I'm using this code
html.querySelector(".category").innerText
Thanks in advance.

I would say the simplest is to use Replace$
data = Replace$(html.querySelector(".category").innerText,"Category:", vbNullString)
You could possibly use split
data = Trim$(Split(html.querySelector(".category").innerText,"Category:")(1))

Related

extract sub-headers in R or Python

desperate newbie here. I have a question for which I just cannot find the right solution. I received a dta file from which I want to extract the sub-headers of each column. Unfortunately, I am not versed in Stata or have access to it. I read my dta file into R and changed it to a data frame and also data table. It displays the column names and sub-headers well. However I cannot extract the sub-headers and they also disappear when I save the data frame or table as a csv or excel file locally. When I call colnames(df) or names(df), I only receive the column names and not the sub-headers. I also tried it with python without luck. Unfortunately, I am not allowed to share the data. So I hope my problem is understandable without an example. Thank you in advance!

Write Code in a Spreadsheet Using Visual Basic

I am new to Excel VBA and I am trying to achieve what is displayed in the Result column in the image. I need to develop a code in spreadheet which would create a json based on the occupation of an individual. Please advice how can I fill data in column H (Result) easily using visual basic.
As #ron rosenfeld mentioned you data is inconsistent from row to row. Is there some logic to decide what columns to use? You also don't need VBA to do this. You could use the concatenate function as below:
=CONCATENATE("{""",$A$1,""":""",A2,""",""",$B$1,""":""",B2,"""}")
The output for row two would be:
{"Occupation":"Doctor","FirstName":"Alex"}
If there are conditions you also use the IF function to only show certain columns. If it is more complex I would download the json.bas file from github and generate using that class.

How can I use Json patch document using VB.net

I'm struggling to use the Add method for Json Patch Document in vb.net? My goal is to create work items programmatically. I'm looking to add values to Title, Description and Priority field of a work item. Do I have to use the same code separately for all three fields?
Also, I'm new to all this development stuff so encouragement would be appreciated. Here is my mini code - just updated. Can anyone tell me if I'm doing it the right way.
Dim JPDocument As New JsonPatchDocument
With JPDocument
.Item(0).Operation = Operation.Add
.Item(0).Path = "/fields/System.Title"
.Item(0).Value = "Visual basic rocks"
End With
Thanks,
Omar

Isolate values in a comma delimited field using SSIS

I've been working in SSIS trying to parse a multi-valued excel spreadsheet field using VB.Net. My script works by searching for a comma, then using string functions (Left, Right) to whittle down the string until it's null.
Is there an SSIS toolbox function that will do that for me? If so, please tell me :)
Using Visual Studio 2019, Excel 2016.
I personally use c# script component for this.
string textToSplit = Row.[Your Column].Value;
string[] splits = textToSplit.Split(',');
//Now you can work with all sections
foreach(string split in splits)
{
//This is where you do something with each part
}
If the strings are quote wrapped or have commas inside the pieces then you have to use a more complicated splitter utilizing REGEX.
Well, I think I figured it out - it's to use the derived column transformation within the data flow task. With it I can use LEFT and RIGHT functions to parse. I appreciate the help with the C# code - my VB.Net code is very similar. Going to test on Monday!

Type conversion error in VB when accessing a HTML table

I have a HTML table where I am allowing dynamic adding/deleting rows (that contain text-input's in the cells) using some JavaScript. I am not using ASP.NET TextBox controls, just traditional HTML, as I don't think rows containing ASP.NET controls can be added/deleted without a postback.
When the user clicks an ASP:Button, I am using VB to loop through the table rows in server-code, and ultimately use LINQ to write to a database. I have "Imports System.Web.UI.HtmlControls" in the file.
The code where I am getting problems is:
Dim name As HtmlInputText
name = row.Cells(0).Controls(0)
The error is: "Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.HtmlControls.HtmlInputText'." On the 2nd line above.
There is only one input control in each cell, so I am assuming I can use "Controls(0)" to access it. I have read solutions that use "FindControl", but I don't think this works with standard HTML "inputs", but also, as the rows are dynamically added/deleted, it's near-impossible to know the "ID" to search for.
Any ideas? Cheers.
Figured out the problem. Just needed to add runat="server" to the input tags. Thanks every one for the replies.