Ashraf Eldawody Ashraf Eldawody - 3 months ago 29 Question

import variables and its values from file

i am working on a project to help me with my website
but i am stuck on this step
simply i want to save this file as variables and values in

the file i am talking about looks like

"SIM" = "Micro-SIM"
"Weight" = "168 g (5.93 oz)"
"Announced" = "2013 = September"
"Status" = "Available. Released 2013 = September"
"Dimensions" = "151.2 x 79.2 x 8.3 mm (5.95 x 3.12 x 0.33 in)"
"Weight" = "168 g (5.93 oz)"

so the variable would be SIM and it's value would be Micro-SIM
i can also make the file in xls


Use JSON files.
If you create a class which represent your data

Public Class Data
    Public Property SIM As String
End Class

You will be able to serialize

Dim data As New Data With { .SIM = "Micro-SIM" }
Dim stringData = JsonConvert.SerializeObject(data)
File.WriteAllText("laptop.json", stringData);

And deserialize it

Dim data As Data = JsonConvert.DeserializeObjec(Of Data)(File.ReadAllText("laptop.json"));

Then read and use values

Dim data As Data = JsonConvert.DeserializeObjec(Of Data)(File.ReadAllText("laptop.json"))

textBoxSIM.Text = data.SIM ' Will show "Micro-SIM" in textbox

Or save values

Dim data As New Data()
data.SIM = textBoxSIM.Text
File.WriteAllText("laptop.json", JsonConvert.SerializeObject(data));