Dynamically set varibable value?

  • Thread starter Thread starter jcr
  • Start date Start date
J

jcr

Hi:

I am having trouble dynamically setting a variable. The following
code does not work. Any ideas would greatly be appreciated.
Thanks,
Jim

Dim astr As String
Dim bstr As String
Dim myval As Double
Dim te As Double
Dim AAA As Object
astr = "test"
bstr = "test"


If astr = bstr Then
'want to set variable te (which is double) = 333.3
' AAA = CType(astr, ValueType)

AAA = Mid(bstr, 1, 2)
' Mid(bstr, 1, 2) = 333.3
AAA = 333.3
End If

te = te + 1
'variable te should now be set to 334.3
 
* (e-mail address removed) (jcr) scripsit:
I am having trouble dynamically setting a variable. The following
code does not work. Any ideas would greatly be appreciated.
Thanks,
Jim

Dim astr As String
Dim bstr As String
Dim myval As Double
Dim te As Double
Dim AAA As Object
astr = "test"
bstr = "test"


If astr = bstr Then
'want to set variable te (which is double) = 333.3
' AAA = CType(astr, ValueType)

AAA = Mid(bstr, 1, 2)
' Mid(bstr, 1, 2) = 333.3
AAA = 333.3
End If

te = te + 1
'variable te should now be set to 334.3

You never assign a value to 'te'. Why do you use the utility variable
'AAA'?

\\\
Dim astr, bstr As String
Dim te As Double
astr = "test"
bstr = "test"
If astr = bstr
If IsNumeric(astr) Then
te = Double.Parse(astr)
Else
...
End If
Else
te = 333.3
End If
te = te + 1
MsgBox(te.ToString())
///
 
Hi Thanks for the reply.

The text for variable bstr will be different for each time I enter
this portion of the code. The value of the text for bstr is the
variable that I want to set. For example, if bstr = "MO" I want to
set the variable MO to a unique value. I do this now by having alot
of "IF conditions". I would like to do it dynamically.

Thanks for your help,
Jim
 
* (e-mail address removed) (jcr) scripsit:
The text for variable bstr will be different for each time I enter
this portion of the code. The value of the text for bstr is the
variable that I want to set. For example, if bstr = "MO" I want to
set the variable MO to a unique value. I do this now by having alot
of "IF conditions". I would like to do it dynamically.

I would rething the design. You can use a 'Hashtable' to store (key,
value) pairs. Maybe this will fit your needs.
 
Hi Jim,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to set a variable by its
name, which is used to build a (key,value) pair.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

For a field or property, you can use the reflection to achieve your aim,
but the method did not work on variable. If the MO variable you refer to is
a field in a class you may try the reflection method below.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim o As New TestClass
Dim fd As String = "myfield"
o.GetType().InvokeMember(fd, Reflection.BindingFlags.SetField,
Nothing, o, New Object() {"set string value"})
Dim rtStr As String = CType(o.GetType.InvokeMember(fd,
Reflection.BindingFlags.GetField, Nothing, o, Nothing), String)
MsgBox(rtStr)
End Sub

Type.InvokeMember Method (String, BindingFlags, Binder, Object, Object[],
ParameterModifier[], CultureInfo, String[])
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemTypeClassInvokeMemberTopic3.asp

Also if you wants to build a (key,value), I agree with Herfried's
suggestion, you may try to use the HashTable.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemCollectionsHashtableClassTopic.asp


Please Apply My Suggestion Above And Let Me Know If It Helps Resolve Your
Problem.



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jim,

Thanks for posting in the community.

Did my answer help you?
If you have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Peter,

I wonder if you would take a moment to consider what happens if every one of
us who answers questions (all day long and some people "for years") followed
each reply with a "Did my answer help you?" message.

If you think it is important we could all start doing that.
 
This page may explain it

http://msdn.microsoft.com/newsgroups/managed

"MSDN Subscriptions includes newsgroup support for all Universal, Enterprise, Professional and Operating System Subscribers. MSDN Subscribers can post .NET product and technology questions in over 220 managed newsgroups and receive a response from either another professional in the community or from a Microsoft Support Professional within two business days. The Managed Newsgroups are constantly being reviewed by Microsoft Professionals for quality responses. To make life even easier, we are able to notify you, via e-mail, when a post has been made to your issue. If you do not locate an appropriate newsgroup in the list to the left, you may want to browse the entire list of MSDN Newsgroups. Keep in mind that this entire list includes all developer newsgroups, whether or not they are eligible for this new support offering.
 
Tom Leylan said:
I wonder if you would take a moment to consider what happens if every
one of us who answers questions (all day long and some people "for
years") followed each reply with a "Did my answer help you?"
message.

If you think it is important we could all start doing that.

This is called "service". I wouldn't complain about.
 
Hi Tom,

I see not anything wrong in this kind of answering from Peter,

I think also if it is good if the OP gives a reply, see for that the thread
OHM started once.

And Peter is allowed in this newsgroup as everybody else to use his own
style.

Especialy because Peter always listen to complaints, I will advice him to do
that this time not.

Just my thoughts.

Cor
 
Hi Amin,

Thanks for posting to the community.

We appreciate your thoughts on the matter. However I only asked Peter to
consider it. If he (or you) think a vote is needed we could do that too.

Not that I'm keen on a thread about the definition of English words but I
wouldn't call it "service." I believe I understand your point... that if
any of us really cared about service we would all ask "Did my answer help
you" and then if we cared about being nice we would respond "Yes you did" or
"No you didn't" as was appropriate but I don't think that is practical.

Did my answer help you?
 
Tom Leylan said:
Hi Amin,

Thanks for posting to the community.

We appreciate your thoughts on the matter. However I only asked
Peter to consider it. If he (or you) think a vote is needed we could
do that too.

Maybe he simply wants to remove the item from his to-do list? In order to do
this, he first must ask if the problem is solved.
Not that I'm keen on a thread about the definition of English words
but I wouldn't call it "service." I believe I understand your
point... that if any of us really cared about service we would all
ask "Did my answer help you" and then if we cared about being nice we
would respond "Yes you did" or "No you didn't" as was appropriate but
I don't think that is practical.

Peter is from MSFT, most people are not. That is the difference and that's
why he asks but most people don't (and don't have to). He belongs to the
"Microsoft Online Partner Support" as you can read in his messages. I think
it belongs to a good "service" not leaving the thread open because it is not
obvious if the problem is solved.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi Tom,

Thanks for your quickly reply!

Since I also did send a message and did not see an answer on my message, I
take the freedom to answer you here.

There is no need to talk about the definition of the English word "service"
because it is not an English word. It is a word also used in the English
language, but not exclusively an English word.

You saw that Armin has placed it between quotes; I did understand that to
show that there was something special with that word.

"Service" is more original a French word and that is a country of the EU.
But "Service" is very internationally used.

I do not know where "Service" is standing for in the US, (I assume for the
same) however here in the EU it stands for more things (It also stands for
dinner set), but one of those this is giving the customer the feeling that
he gets your attention.

You know this is an international newsgroup, where we not native speakers
try to use the English language. When I look at the time of posting from
Peter, I assume he is not from the US, but I am not sure if he is not a
native English speaker.

When I see his postings, I think he will fulfil the meaning of the word
"Service" as we are used to it in the EU.

If you have any concern on this issue, please post here.

Best regards,

Cor
 
Tom,

* "Tom Leylan said:
Not that I'm keen on a thread about the definition of English words but I
wouldn't call it "service." I believe I understand your point... that if
any of us really cared about service we would all ask "Did my answer help
you" and then if we cared about being nice we would respond "Yes you did" or
"No you didn't" as was appropriate but I don't think that is practical.

Thank you for posting to the community!

What would be the right term if "service" isn't appropriate in this
situation?
 
Armin Zingler said:
Maybe he simply wants to remove the item from his to-do list? In order to do
this, he first must ask if the problem is solved.

Perhaps he gets paid a bonus for the number of messages he sends :-) Can we
at least agree that you are just picking things out of the air?
Peter is from MSFT, most people are not. That is the difference and that's
why he asks but most people don't (and don't have to). He belongs to the
"Microsoft Online Partner Support" as you can read in his messages. I think
it belongs to a good "service" not leaving the thread open because it is not
obvious if the problem is solved.

So people from MSFT have to post the follow up question? And you are saying
the other people from MSFT didn't follow the rules and didn't offer good
service since they didn't?

And what is it about people that they find it necessary to "figure out" what
"might" be happening? Why don't you just ask the guy?

I understand what you "think" is good service but I am explaining to you the
fact that it isn't. The thread isn't "open" it isn't a case the Department
of Software is working on. People aren't responding "Yes" so you think MSFT
considers the thread still open?

Armin... let me make it easy "gee yeah I never thought of that, you're
right."


Did this answer your question?
If you have any concern on this issue, please post here.

Oh and thanks for posting to the community,
Tom
 
Hi Cor,

Thanks for sharing with the community.

Let me see if I understand your question correctly. You believe the word
"service" isn't an English word?

I will have to study this and get back to you.

Did I answer your question?

If you have any concern on this issue, please post here.
 
Thank you for posting to the community.

I'll post "I agree with Herfried" after every message you post... that will
be a "service" right?

Did I answer your question?

If you have any concerns on this issue, please post here.

Tom
 
Hi Tom,

Thanks for your quickly reply!
-----------------------------------
Your answer was,
Let me see if I understand your question correctly. You believe the word
"service" isn't an English word?
------------------------------------
My opinion about it is that because Bush is a president of the US, therefore
is not every president in the world automaticly president of the US.

"Service" is a word in the English language. But not only in the English
language and as far as I know not originaly "an" English word.

If you have any concern on this issue, please post here.

Best regards,

Cor
 
Thanks for sharing with the community.

Let me see if I understand your question correctly. We may not actually be
writing in English because all English words were derived from words that
were not originally English? As a result people who speak German, French,
etc. aren't actually speaking those languages because naturally they were
similarly derived from earlier languages. Is that right?

Did I answer your question?

If you have any concern on this issue, please post here.
 
Tom Leylan said:
Perhaps he gets paid a bonus for the number of messages he sends :-)

Maybe he gets paid for his work not for each message? Apart from this, if I
were an MVP and don't get paid, maybe I'd also ask because the support
quality also decides whether one becomes/stays an MVP or not.
Can we at least agree that you are just picking things out of the
air?
No.


So people from MSFT have to post the follow up question?

Yes, people who's job it is to help their customers should post it. It probably
belongs to the support policies because it makes the customers feel and show
them that the support deparment is taken care of them.
And you are
saying the other people from MSFT didn't follow the rules and didn't
offer good service since they didn't?

Why do you think other people should follow company internal rules?

[ ] you know the manufacturer of VB.NET
[ ] you know the difference between the manufacturer offering services and
other people

And what is it about people that they find it necessary to "figure
out" what "might" be happening? Why don't you just ask the guy?

I understand what you "think" is good service but I am explaining to
you the fact that it isn't.

If you simply leave your customers alone, it's up to you. If I send support
answers to my customers and don't get a response, I'll send a follow message
to ask if it helped. Yes, I call this good service.
The thread isn't "open" it isn't a case
the Department of Software is working on.

It is a question the support deparment is working on. As long as they don't
know whether the problem has been solved, the issue is still "open".
People aren't responding
"Yes" so you think MSFT considers the thread still open?

Right!

You're a really funny guy: People sometimes complain about the lack of
support, and if the support takes care of the customers you start to
complain. Doesn't make sense to me.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top