Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 14, 2018 11:17 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: While loop and NOT
PostPosted: Sat Aug 25, 2012 4:21 am 
Offline

Joined: Tue Aug 21, 2012 6:35 am
Posts: 9
Hello everybody, I have a task here I am struggling with. I want to put a number or series of numbers into an edit field. The cumulative total will be shown in a 'Total' edit field when the user puts in the figure 999. My attempt is below, but would like to know how to initialise and how to express NOT 999.

Thanks for any help

Dim Total As Integer = 0
Dim Number As Integer

Total.text= Input.text

While Not Str(CDbl(Input.text =999)

Total = Total + Input.text

Total.text = Total

Not Str(CDBl(Input.text =999)

wend

Total.text = Total


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 4:31 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Missing a ")" in that code

CDbl(Input.text) <> 999

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 6:02 am 
Offline

Joined: Tue Aug 21, 2012 6:35 am
Posts: 9
Thank you shaosean, for your help. I have now got this programme to run, so if I were to put 999 to start with the answer.text will show 0. However if I any other number in the input text and press calculate the programme will freeze, instead of allowing me to put in another number. What is missing or what am I doing wrong

Dim Total As Integer = 0

Input.text = Str(CDbl(input.text))

While CDbl(Input.text) <>999

Total = Total + (CDbl(input.text))

Input.text = Str(CDbl(input.text))

wend

answer.text = Str(Total)


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 8:59 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
More homework questions, by the look of it.

The 'algorithm' you are trying to replicate here sounds very much like old old old old examples used when the only form of input was an INPUT followed by pressing the return key.

Object oriented languages like RB using a GUI front end dont work that way.

In RB, you should have a text edit box, probably a 'total so far' label and a 'calculate now' button.

You do not need a while ..wend button at all.
If you want to stop adding numbers up, just dont press the calc button.
You dont need a magic number to tell the app you're done.

When the button is pressed, add the value of the input box to the value of the totalsofar label.


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 9:17 am 
Offline

Joined: Tue Aug 21, 2012 6:35 am
Posts: 9
Thank you kermit, much appreciated. Have got this exercise working by doing what you said. Showed the answer using a text.edit box. As shown below. How would you get the answer to be shown in a label. Thanks

TotalSoFar.text = Str(CDbl(TotalSoFar.text) + CDbl(input.text))


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 11:00 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Off hand I dont recall if a label has a .text property or a .caption property
I seem to recall that static text (the old label) had caption
and maybe label has .text

delete TotalSoFar
Add a label, call that TotalSoFar

If it runs, hurrah.
If it doesnt like .text, change it to .caption and it will be fine


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 11:22 am 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
Instead of guessing why not go to the Language Reference and see what the property is:

http://docs.realsoftware.com/index.php/Label

Then you will know for sure if it has a "Text" property ... or not.


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 11:59 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Quote:
Instead of guessing why not go to the Language Reference and see what the property is:


What a pointless reply.


Top
 Profile  
Reply with quote  
 Post subject: Re: While loop and NOT
PostPosted: Sat Aug 25, 2012 7:46 pm 
Offline

Joined: Tue Aug 21, 2012 6:35 am
Posts: 9
Thanks kermit and harriew, l learnt a lot from this little exercise, the caption works very well and the Language Reference is a very useful.

I am sure it will not be long before my next question!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group