#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Posts: 43Member
In a program I made, I have a few lines to show the square root sign, and then a number in a text box under that. I'm looking for a way to check for the greatest perfect square that is a factor of that number.

For example, if I had 80 under the square root sign, I would want it to tell me that the greatest perfect square is 16, so that I could put 4 in front of the square root sign and 5 under it.

Thanks

• Posts: 3,948Member
: In a program I made, I have a few lines to show the square root sign, and then a number in a text box under that. I'm looking for a way to check for the greatest perfect square that is a factor of that number.
:
: For example, if I had 80 under the square root sign, I would want it to tell me that the greatest perfect square is 16, so that I could put 4 in front of the square root sign and 5 under it.
:
: Thanks
:

By "perfect square", I'm guessing you mean 4, 16(4*4), 256(16*16), 65536 (256*256), etc., correct? Hate to tell you, but those four values are the only ones you can easily represent in VB (you could go one higher if you don't mind using FP math). That being the case, you could easily check to see which is the highest one that is still a factor by loading them into an array and looping highest to lowest until you find a factor.
• Posts: 43Member
: : In a program I made, I have a few lines to show the square root sign, and then a number in a text box under that. I'm looking for a way to check for the greatest perfect square that is a factor of that number.
: :
: : For example, if I had 80 under the square root sign, I would want it to tell me that the greatest perfect square is 16, so that I could put 4 in front of the square root sign and 5 under it.
: :
: : Thanks
: :
:
: By "perfect square", I'm guessing you mean 4, 16(4*4), 256(16*16), 65536 (256*256), etc., correct? Hate to tell you, but those four values are the only ones you can easily represent in VB (you could go one higher if you don't mind using FP math). That being the case, you could easily check to see which is the highest one that is still a factor by loading them into an array and looping highest to lowest until you find a factor.
:

I mean "perfect square" as in "perfect square," like 1, 4, 9, 16, 25, etc (1x1, 2x2, 3x3, 4x4, 5x5, etc)

• Posts: 3,948Member
: I mean "perfect square" as in "perfect square," like 1, 4, 9, 16, 25, etc (1x1, 2x2, 3x3, 4x4, 5x5, etc)
:

Funny, looks like a "normal square" to me. No need for an attitude...

[code]Dim I As Long
Dim LastGoodSquare As Long
For I = 1 To Text1.Text / 2
If Text1.Text Mod (I ^ 2) = 0 Then LastGoodSquare = I
Next
[/code]
LastGoodSquare should hold the value you're after or 0 if there isn't one.