Saving To A XML File From A Local Variable?
Mar 16, 2009I just need some sample code to save the blue values to an xml file as shown below:
textbox.size =48
textbox.font.colour = Blue
Saved to c:myfile.xml as
[Code]....
I just need some sample code to save the blue values to an xml file as shown below:
textbox.size =48
textbox.font.colour = Blue
Saved to c:myfile.xml as
[Code]....
how do i save data from a text file to different variable?i want to save each data from different rows and columns to different variable.[code]
View 1 RepliesCurrently, I've encountered a problem where I do not how I can store the variable of my battery level in a text file. I tried .xml and .txt file and it returns me text which can't be read.The code related:
vb.net
[code]Dim psBattery As PowerStatus = SystemInformation.PowerStatus
Dim perFull As Single = psBattery.BatteryLifePercent
[code]....
The place where I do not know what to insert is the "Insert Battery Percentage Here" part so I guess that's the problem.For your info, if you were to use a MsgBox to display, the code which displays that would be <MsgBox("Total battery power remaining: " & perFull * 100 & "%")>
I am trying to Save my data into Local Database (*.SDF or *.MDF) but i due to some reasons i can not do it. I have seen 100s of Video on it and tried all possiable ways, but still my data is not saving into Local Database. and i do not get any error messages. However i can save my data into SQLEXPRESS database. i am using Visual Stodio 2008.
View 2 RepliesI stumbled upon something i don't quite see the logic of. Let's ork with following piece of code:
For Each ds As DerivedScale In List
If ds.ScaleID = scaleId Then
ds.ScaleID = ds.ScaleID + scaleStep
[Code].....
This piece is written for 2 records to change place and change the sequence number (scaleid). The arrow indicates where the issue occurs. The item "ds" is replaced by the object 1 indexnumber higher/lower. This does however not effect that object in the List. So when i check, item ds isn't set.
However, when i look at ds.ScaleId = ds.ScaleID + scaleStep, this is reflected in the List.
So what I am wondering is: is "ds" acting like a local variable here, and can i only make changes to it's properties?
I'm writing a subneting calculator in VB.NET.I'm using the IDE SharpDevelop.Well my problem is I'm using a function to do some calculations and then to figure out the class of the IP addresses.Well I pass a variable from the subroutine, that is accessed when a button is clicked, to the function then the variable is passed back to the subroutine and then the variable is passed again to another function but when it reaches this second function it doesn't retain the value it was given in the first function.I'm not sure if I'm just passing the variable wrong or if this is how it works.I know I can make this work probably by using global variables but I'm not sure if this is proper. So my ultimate question is what is the difference between local and global variables besides just scope and should I try and use one more than the other.
View 4 RepliesI sort of understand why this is happening, but not entirely. I have a base class with a Shared (Static) variable, declared like so:
Public Shared myVar As New MyObject(arg1, arg2)
In a method of a derived class, I set a local variable like so:
Dim myLocalVar As MyObject = myVar
Now when I do something like myLocalVar.Property1 += value, the value in Property1 persists to the next call of that method! I suppose I get why it would be happening; myVar is being set by reference instead of by value, but I've never encountered anything like this before. Is there any way (other than my workaround which is to just create a new object using the property values of myVar) to create myLocalVar by value?
Does anyone know why a local variable cannot be declared WithEvents?T
View 3 RepliesI have a form in VB.NET that is used as a dialog in a mainform. Its instances are always locally defined, there's no field for it. When the user clicks the OK button in the dialog, it will fire an event with exactly one argument, an instance of one of my classes. Since it is always a local variable, how can I add an event handler for that event?
Code for the event, a field in MyDialog:
public Event ObjectCreated(ByRef newMyObject as MyObject)
Code for the main form to call dialog : (never mind the syntax)
Dim dialog As New MyDialog()
dialog.ShowDialog(Me)
AddHandler ObjectCreated, (what do I put here?) //Or how do I add a handler?
is this safe (I know it works, but is it safe)? Is it returning a reference to a local variable, wich falls out of scope as soon as the function returns?
Public
Function myfunc() As String
Dim strXml As String
[code]....
Sub WriteEOFData(ByRef FilePath As String, ByRef EOFData As String)
Dim sFileBuf As String
Dim RoPepfMiyYgyrTfLY7YxdpSoSOycKgR06b1oCptGcO As String
Dim lFF As Integer
Try
[code]....
say i have an auto property Public Property P As Integer and everytime I want to read this variable P in a function, i will declare a local variable as such: dim _p = P then read _p instead of P. I'm wondering does it make sense at all? will it actually make things slower (which of course isn't my intention).Btw if we change the question to Public Property P As Object is there any change in the answer?
View 7 RepliesI am getting 6 unused local variable error messages. If I comment out the variable, I get en error because it really is in use. I tried re-building project.
error
Warning 2 Unused local variable: 'sqlCustomerInsertTicketConn'. C:UsersJeffDocumentsVisual Studio 2008ProjectsJeffComputersPOS1JeffComputersPOS1Module1.vb 1741 17 JeffComputersPOS1
Public Function MethodOne(ByVal s As String) As String[code]...
I want to retain the value of i, but once it goes back into MethodOne, it loses its value. I tried making it static i As integer = 0, but this did not work.
I have 2 question, hope somebody give me an explanation: 1. Should a local variable call dispose method and set to nothing? 2. If some method have an arguments which it is a ByVal argument, it means a method create a new object? But If it is a ByRef argument, it means a method don't create a new object?
View 4 RepliesHow does one declare a readonly local variable in VB.Net? Java and C++ have final/const local variables so I'm sure VB.Net must have them, but I just can't find the syntax for it.
View 2 RepliesHow does the GC dispose objects created in the following 2 scenarios?
1)
Private Function DoSomething() As Boolean
Return New DatabaseManager().Insert()
End Function
2)
Private Function DoSomething() As Boolean
Dim mngr As New DatabaseManager()
Return mngr.Insert()
End Function
In Option 1, I don't create local variable to hold the reference of the object. In Option 2, I hold the reference in local variable.What option is better and why? (if any)
I am trying to write a visual studio addin. The following code is used to display the global variables or class names or function names of a selected text inside visual studio code window. However it do not display the variables defined inside a function. How can I modify this to display local variables?
'Call this function inside OnConnection event of the addin
Sub displayCodeElementName()
' Before running this example, open a code document from a project
[Code]....
Im making a site in Visual Studio using vb and I have a variable in page_load but need its value in the event handler of a button for passing on session.
View 5 Replies[Code]...
Notice the catch (Type) instead of catch (Type myVariable). Is this possible with VB.NET, or do you always have to declare a variable when you catch exception types, like so:
[Code]...
I have a button inside a one of my forms which contain a lot of coding and normally a lot of variables declaration.
Is there is a option/add-on that I can use/set that enable me to display all the variable used inside the sub or function I am currently working in?
All I can find is add-on to display the Properties/Methods and only Public variables inside the form or inside the class. but I need to list the local variables also.
Today I discovered that something I had assumed about VB.NET for many years was not true (worrying!). I assumed that a variable declared within a loop had a lifetime of the iteration it was declared in, but in fact it seems it has a lifetime of the whole procedure.[code]I had assumed an output of False, True, False, True but instead it is actually False, True, True, True..In C# the equivalent code would not compile as you would get a compile time error of Error "Use of unassigned local variable 'var1'".I realise there are many ways to fix this and that best practice would be to declare the variable outside of the loop and reset it at the beginning of every loop through.I find this behaviour so counter-intuitive to me that I would like at least a compile time warning in VB.NET when/if I do this. (I could also then set this on any projects I already have and get warning that would allow me to check that my assumptions aren't causing errors).Does anyone know how/if I can get this to generate a compile time warning in VB.NET? Am I the only one that finds this counter-intuitive?
View 1 RepliesWhat's best practice (in VB.Net):
Function GetSomething() as String
GetSomething = "Here's your string"
End Function
or
Function GetSomething() as String
Dim returnString as String = "Here's your string"
Return returnString
End Function
Obviously, neither of these implementations make any sense, but they're just meant to illustrate my point. Is there anything to be gained by using GetSomething itself to store the return value instead of declaring returnString locally and then returning that (does it avoid having an extra string allocated/instantiated - and if so, are there any performance/memory benefits)?
I am working on MVC3, i have a situation where i want to do something like this:
<Div>
@Code
Dim i = 1
[Code]....
but razor is throwing wrong syntax error message. how to do this properly in side razor code.
Will the list in this shared method keep its state throughout the life of the method? Or will a new list be created every time this method is called?
[Code]...
I've used this code before but only when I was serializing one array. Here I'm trying to serialize two and VB returns "local variable is already declared within the current block."Someone tell me how to do this correctly, pleases. I'm banging my head against a brick wall that I can't see.
[Code]...
Currently I am saving data from my applications by saving a text file via a stream reader as a string. I have come to a problem. In my current application, I have an array of the following structure:
[Code]...
I have written all that is required at this point and have published the program. I thought that global variables were saved when the program terminated but, as I found out, they aren't. If anyone has any way of making the variables keep their values between uses of the program I would be very grateful as if the program is being run for the first time some global variables need to be set straight away (I have done this code). The variable types are: one boolean and a few strings.
View 3 RepliesThis webservice is almost converted form VB to C#, except I get this error shown below on the DataRow arow object when I use it in the foreach statement below to populate the Results Class with a DataSet Object...
Error: A local variable named 'arow' cannot be declared in this scope because it would give a different meaning to 'arrow', which is already used in a 'parent or current' scope to denote something else
using System;
using System.Web;
using System.Collections;
[code]....
as the title suggests i am trying to save a randomly generated number to a variable.I have done:
Dim randomposition As Integer
randomposition = Rnd(1, 1000)
when i do this it gives me this error:
[code].....