By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,624 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,624 IT Pros & Developers. It's quick & easy.

one button with alternative action

P: n/a
Hi all,

I am using visual studio, VB .net

i have a form with a "Support" button which may be pushed as often as
wished. If the current name is "result 1", then "result 2" should be
displayed in the text box. If the current name is "result 2", then
"result 1" will appear again.
I have tried the following

thanks in advance,
Static iStatus as integer
iStatus = abs(iStatus -1)
if iStatus=1 then
Field1.txt="result 2"
else
Field1.txt="result 1"
end if

the problem is the I get the error
name 'abs' is not declared

can anybody help, is above the right method at all?

greetings

Murt
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
* "Murt" <Mu**********@ATyahoo.DOTcom> scripsit:
I am using visual studio, VB .net

i have a form with a "Support" button which may be pushed as often as
wished. If the current name is "result 1", then "result 2" should be
displayed in the text box. If the current name is "result 2", then
"result 1" will appear again.
I have tried the following

thanks in advance,
Static iStatus as integer
iStatus = abs(iStatus -1)
if iStatus=1 then
Field1.txt="result 2"
else
Field1.txt="result 1"
end if

the problem is the I get the error
name 'abs' is not declared


Use 'Math.Abs' instead. Make sure the 'System' namespace is imported.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
"Murt" <Mu**********@ATyahoo.DOTcom> schrieb
Hi all,

I am using visual studio, VB .net

i have a form with a "Support" button which may be pushed as often
as wished. If the current name is "result 1", then "result 2" should
be displayed in the text box. If the current name is "result 2",
then "result 1" will appear again.
I have tried the following

thanks in advance,
Static iStatus as integer
iStatus = abs(iStatus -1)
if iStatus=1 then
Field1.txt="result 2"
else
Field1.txt="result 1"
end if

the problem is the I get the error
name 'abs' is not declared
Probably "abs" is neither a local variable, nor a member of the class, nor a
member of the same or enclosing namespaces, nor a member of imported
namespaces/classes.

Use Math.Abs or System.Math.Abs

can anybody help, is above the right method at all?


Seems to be right. Alternatives:

istatus = (istatus+1) mod 2

- or -

static iStatus as boolean
iStatus = not iStatus
if iStatus then
field1.text = "result2"
else
field1.text = "result1"
end if
--
Armin
Nov 20 '05 #3

P: n/a
thanks Herfried,

that did the trick

Murt

Herfried K. Wagner [MVP] wrote:
* "Murt" <Mu**********@ATyahoo.DOTcom> scripsit:
I am using visual studio, VB .net

i have a form with a "Support" button which may be pushed as often as
wished. If the current name is "result 1", then "result 2" should be
displayed in the text box. If the current name is "result 2", then
"result 1" will appear again.
I have tried the following

thanks in advance,
Static iStatus as integer
iStatus = abs(iStatus -1)
if iStatus=1 then
Field1.txt="result 2"
else
Field1.txt="result 1"
end if

the problem is the I get the error
name 'abs' is not declared

Use 'Math.Abs' instead. Make sure the 'System' namespace is imported.


Nov 20 '05 #4

P: n/a
Hi Murt,

In cases where you <are> dealing with numbers, you can often look at
things the 'other way round'
iStatus = 1 - iStatus '0 then 1, then 0

I would use Armin's Boolean method myself - it's the clearest.

Regards,
Fergus

Nov 20 '05 #5

P: n/a
"Murt" <Mu**********@ATyahoo.DOTcom> wrote...

I see others have answered your first question and an alternative was
presented... I'll offer one more based on the idea that keeping track of a
boolean state to change a boolean state is probably not necessary. By that
I mean, if you happen to have a static boolean sitting around to indicate
the state of more than just the button text I'd probably use it (it really
is the "indicator" at that point) but if all it does is keep track of what
the text should look like there is a little point.

So you get:

if ( field1.text = "result1" ) then
field1.text = "result2"
else
field1.text = "result1"
end if

or my personal preference:

field1.text = iif(field1.text = "result1", "result2", "result1" )


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.