Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LOOPING

Status
Not open for further replies.

icecr3amc4k3

Programmer
Apr 25, 2023
7
0
0
ID
hello everyone i have a little problem i want to output like in the picture but i don't know how
Screenshot_63_nfii2l.png

1.Limit the number of "+" loops
2. and making loops also appear in text 3 and 4 as in list box and combo box


i have a copy of the code i made


a = VAL(thisform.text1.value)
b = VAL(thisform.text2.value)
DO WHILE a <= b
IF a % 2 = 0 then
thisform.combo1.AddItem(ALLTRIM(STR(a)))
thisform.combo1.AddItem(ALLTRIM("+"))
thisform.list1.AddItem (ALLTRIM(STR(a)))
thisform.list1.AddItem(ALLTRIM("+"))
thisform.text3.Value = (ALLTRIM(STR(a)))
a = a + 2
ELSE
thisform.combo1.AddItem(ALLTRIM(STR(a)))
thisform.combo1.AddItem(ALLTRIM("+"))
thisform.list1.AddItem (ALLTRIM(STR(a)))
thisform.list1.AddItem(ALLTRIM("+"))
a = a - 1 + 2
thisform.list1.RemoveItem(1)
thisform.combo1.RemoveItem(1)
ENDIF
ENDDO
 
To add something to a textbox you don't have an AddItem() method, so you add to the Value property. How do you extend a string with something new? You take the current string and add the new part to it: string = string + newstring. Not string = newstring. That won't extend it, that will replace the old string with the new part. So what do you have to do with the value?

Code:
thisform.text3.Value = thisform.text3.Value + ALLTRIM(STR(a))

I can't help you with the rest, as I don't really understand what's you want to do here. What I would suggest is to simplify this: a = a-1+2, what is a-1+2? You're knowing modulus, but you can't simplify a simple addition?

I sense you're not really having fun with this, relax and you'll see your barrier is not the computer, it's really just simple flaws that have neither to do with hard math or the difficulty of programming. I mean,, to encourage you, you have already done a good chunk, you're just stuck with a few details. Just tackle the little errors in your understanding and you can complete this.

Chriss
 
An alternative to the expression:

Code:
thisform.text3.Value = thisform.text3.Value + ALLTRIM(STR(a))

You can create your own class based on the Textbox. I have my own classes defined in a class library with an underscore '_' character such as _textbox. I have defined my own class for all the VFP controls.

In your custom textbox class, you can define a new method called "Append"; then add the following code:

Code:
LPARAMETERS tcValue
this.Value = ALLTRIM(this.Value) + ALLTRIM(tcValue)

Then you can call it by the following:

Code:
thisform.MyTextBox.Append("Appended Text")


Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top