one button with alternative action

  • Thread starter Thread starter Murt
  • Start date Start date
M

Murt

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
 
* "Murt said:
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.
 
Murt said:
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
 
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
 
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" )
 
Back
Top