help needed

harry5568

Member
hi everybody,
i'm an absolutely newbie in programming..
how do i change a label text using an if then statement...basically, the if statement should change label.text to "LEFT" if conditions met,otherwise "RIGHT".
Thx very much in advance...Harry
 

mjcoon

Well-Known Member
Licensed User
how do i change a label text using an if then statement...basically, the if statement should change label.text to "LEFT" if conditions met,otherwise "RIGHT".

You've very nearly written it! If using the desktop IDE then you can get hints as soon as you start typing.

I'd expect to use something like:
B4X:
If leftish Then labe1l.text = "LEFT" Else label1.text = "RIGHT"

(Where "leftish" is either a variable which is True for the "left" condition and False for "right", or is replaced by something like:
B4X:
If hand = "left" Then label1.text = "LEFT" Else label1.text = "RIGHT"
)

BTW If you expect to have several labels on your form it may be better to ignore the suggested names "Label1" etc and replace them with something more descriptive such as "LabHand" ...

HTH, Mike.
 

harry5568

Member
You've very nearly written it! If using the desktop IDE then you can get hints as soon as you start typing.

I'd expect to use something like:
B4X:
If leftish Then labe1l.text = "LEFT" Else label1.text = "RIGHT"

(Where "leftish" is either a variable which is True for the "left" condition and False for "right", or is replaced by something like:
B4X:
If hand = "left" Then label1.text = "LEFT" Else label1.text = "RIGHT"
)

BTW If you expect to have several labels on your form it may be better to ignore the suggested names "Label1" etc and replace them with something more descriptive such as "LabHand" ...

HTH, Mike.

Mike...Thx for the prompt reply. I'm using the following code:
If sin(((a*10)-b)*cPI/180)*c <0 Then Label3.text="RIGHT" Else Label3.text="LEFT"

But,the return is a dud..blank label!

If I use :
If sin(((a*10)-b)*cPI/180)*c <0 Then MsgBox("RIGHT") Else MsgBox("LEFT")

then I get the msgbox correctly ...but can u help me with the first one?
Thx..Harry
 

agraham

Expert
Licensed User
Longtime User
If sin(((a*10)-b)*cPI/180)*c <0 Then Label3.text="RIGHT" Else Label3.text="LEFT"
There's nothing I can see wrong with that statement,it works if I cut and paste it, so the problem is probably with Label3.

However I strongly recommend a structured style for If statements, and loops, as it makes it easier to see the code flow. Note that Ifs need a terminating End If with this structure and nothing should follow Then except maybe a comment.
B4X:
  If Sin(((a*10)-b)*cPI/180)*c = 0 Then
     Label3.text="RIGHT"
  Else
     Label3.text="LEFT"
  End If
 

harry5568

Member
i don't know..its not working out..i'm attaching the sbp
i know its some basic programming glitch..don't laugh when u c the sbp..
this is probably my first prog..thx in advance..harry
 

Attachments

  • 1.sbp
    2 KB · Views: 262

HARRY

Active Member
Licensed User
Longtime User
Hallo other Harry,

Your program won't work as LeftorRight does not retrun a value, so the text set in the sub LeftorRight is overwritten with empty data. There are two solutions:

Line 13:
Label3.text=LeftOrRight

Line 35/39:
If Sin(((a*10)-b)*cPI/180)*c <0 Then
Return "RIGHT"
Else
Return "LEFT"
End If

OR

Line 13 :
LeftOrRight

Line 35/39:
If Sin(((a*10)-b)*cPI/180)*c <0 Then
Label3.text= "RIGHT"
Else
Label3.Text= "LEFT"
End If

Success,

Harry
 

harry5568

Member
Hello...Can anybody tell me whether it's possible to add hours and minutes together,
For e.g Add 1800 hrs 55 min 'shud appear as 1800:55
and 2500 hrs 40 min 'shud appear as 2500:40
Result 4301 hrs 35 min 'shud appear as 4301:35
Thanx fr yr efforts...Harry
 

mjcoon

Well-Known Member
Licensed User
For e.g Add 1800 hrs 55 min 'shud appear as 1800:55
and 2500 hrs 40 min 'shud appear as 2500:40

For a moment, there, I thought that you were referring to the military use of "eighteen hundred hours" as meaning 6p.m. It's unusual to refer to 104 days as ca. 2500 hours so I don't think there's anything in the Basic4PPC keywords under the "Time" heading that is immediately appropriate. (Although there are some for time arithmetic.)

But you could use decimal hours and convert the fractional part to or from minutes by multiplying or dividing by 60.

HTH, Mike.
 
Top