Changing a public string

  • Thread starter Thread starter ReidarT
  • Start date Start date
R

ReidarT

I have this line of code
Public Navn1 As String = "Per"

I want to change it to another 'text' by entering some text in a textbox
like

navn1 = 'Nils'

and then the line should look like

Public Navn1 As String = "Nils"

How do I do that?

regards

reidarT
 
I am not sure if I understand your question. But if you want to change the
value that is stored in the string, when you enter something in a textbox.
Write code in one of the Textboxe's events (Exit, TextChanged) to set the
value of the string as
navn1 =Textbox1.Text.
 
Yes I can see this, but I want the public string to change so that the next
time I open the form it contains the new value/text.
regards
reidarT
 
If you are writing a VS.NET Macro or addin, you can access the code and
replace it with the new text.

If you want to do it from some other app, then you can either do a string
search and replace (maybe regex) of the source code, or you can generate the
whole file via CodeDOM

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
 
Reidar,
Public Navn1 As String = "Per"
I want to change it to another 'text' by entering some text in a textbox
like
navn1 = 'Nils'
and then the line should look like
Public Navn1 As String = "Nils"
How do I do that?

If I would dot this as you ask, than I would use probably something as this
code in the leave or validating event of the textbox

If mytextbox.text = "navn1" then
navn1 = replace.mytextbox.text(navn1 = ',"")
navn1 = replace.mytextbox.text("'","")
end if

However I would never do things like this. It gives only misunderstandings
and not resolved errors.

I hope this helps,

Cor
 
ReidarT said:
Yes I can see this, but I want the public string to change so that the next
time I open the form it contains the new value/text.
regards
reidarT

You want to change the sourcecode when running the program? I think
you'd be better off saving things like these to a config file or
database. Then when opening the form you read the default value for that
variable from the config file/database.
 
Reidar,

As I understand now from Rinze, do you mean in your code?

Cor
 
I know I can use a config.file, but I thought it would be easier if I had a
form to change a public value.
If I wanted to change the default username, or something like that.
regards
reidarT
 
C-Services Holland b.v. said:
You want to change the sourcecode when running the program? I think you'd
be better off saving things like these to a config file or database. Then
when opening the form you read the default value for that variable from
the config file/database.

Why not save it in the registry? It sounds to me like you don't need
something that actually changes the code, but checks to see what the latest
value was the last time the form was opened.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top