# Help

Check out the Floor and Round functions, also the Format function. No idea what GCD is.

Greatest Common Divisor

Light green on dark yellow makes me want to hit the web developer of that site.

Then write Xojo code to do the arithmetic.

[quote=314790:@Beatrix Willius]Have a look at https://www.codeproject.com/tips/161824/fast-integer-algorithms-greatest-common-divisor-an

Light green on dark yellow makes me want to hit the web developer of that site.[/quote]

Not too sure to handle that one.

Then write Xojo code to do the arithmetic.[/quote]

That link takes me to a blank page.

Copy the url from the forum and then do a paste into a new tab. This is a bug in the forum software.

The link to the code I posted can be translated pretty much straightforward to Xojo. Here is the beginning:

[code]Private Sub GCD(value1 as int64, value2 as int64)

dim a, b, result as int64

if value1 = 0 or value2 = 0 then Return 0

a = abs(value1)
b = abs(value2)

if a = b then
Return a
ElseIf a > b and a \ b = 0 then
Return b
ElseIf b > a and b \ a = 0 then
Return a
else

``````'now comes the Euclid algorithm
``````

end if

End Sub[/code]

Then write Xojo code to do the arithmetic.[/quote]

Simply paste into the forum, and it will do what’s needed.

Beatrix. Where it shows Private Sub GCD(value1; is this where i put my txtGCD at?

[quote=314797:@Beatrix Willius]
Private Sub GCD(value1 as int64, value2 as int64)

dim a, b, result as int64

if value1 = 0 or value2 = 0 then Return 0

a = abs(value1)
b = abs(value2)

if a = b then
Return a
ElseIf a > b and a \ b = 0 then
Return b
ElseIf b > a and b \ a = 0 then
Return a
else

``````'now comes the Euclid algorithm
``````

end if

End Sub[/quote]

would it be better to stick all the gcd code into a method and then call the method?

Yes, that’s what I did.

[code]
dim nHalfCycles as integer
dim nWraps as integer
dim nGCD as integer
dim nparts as integer
dim nbights as integer

dim A , B ,nRemainder as integer

nParts = val(txtPartsField.text) '8 in example
nBights = val(txtBightsField.text) '5 in example

nHalfCycles = nBights *2

//nGCD
if nBights > nParts then
A = nBights
B = nParts
else
A = nParts
B = nBights
end if

do
nRemainder =a mod b
a = b

``````b = nRemainder
``````

loop until B=0
nGCD = A
nWraps = nBights - nGCD

//now display the results by setting text fields .text property[/code]

Forgive me. But how do you mean by this?

When you add a TextField to your window, its name is TextField1. To access its contents, you will use:

TextField1.Text

Example 1: store the TextField contents in a variable
Dim MyVar As String

MyVar = TextField1.Text

Example 2: replace the TextField with some data:
Dim SomeData As String = “Vert useless data.”

TextField1.Text = SomeData

Of course, TextField1.Text awaits text data (not binary nor array nor). But instructions exists to convert these to string

[quote]Forgive me. But how do you mean by this?
//now display the results by setting text fields .text property
[/quote]

Did you write the original software or are you trying to reverse engineer some old code?

TextGCD.Text = str(GCD)

A text box has a .text property.
You get the value by looking at it
You change value using =

In VB , it lets you say TxtGCD = str(GCD)
That doesnt work in Xojo, you have to tell it that the text property is what you are changing.

What are you familar with?

There is a really old DOS program out there that was written in old basic. I’m trying to rebuild this in the more modern day software. I chose xojo for the cross platform capabilities and the ease that xojo can do this. I don’t have the original DOS program. So, this program is actually being built from scratch. I would like to make this project work. This would provide many braiders a way to record their knots and even catalog their work.

I’m more familiar with VB than xojo.

Would you please post the code where you show the errors ?

Chance are it is pretty simple.

Actually, I see already one error in the first line. You have used Java or C syntax.

```While (b!=0) { }```

Should be

```While b <> 0 Wend```

If you are accustomed to place condition between parentheses, this is OK :

```While (b <> 0) Wend```

We never use braces, or terminating semicolon. Comparisons are here http://documentation.xojo.com/index.php/Operator_Compare

You REALLY want to read Introduction to Programming Xojo: Learn Xojo Programming

It will give you the basis of the language.

I have everything else as far as the numbers working with the below code.

[code]
Dim txtTotal As String
Dim txtRemainder As String
Dim txtWraps As String
Dim txtGCD As String
Dim txtHalfCycles As String

’ Math
self.txtTotal.text = Str(Val(Self.txtPartsField.text) / Val(Self.txtBightsField.text))
self.txtRemainder.text = Str(Val(Self.txtPartsField.text) Mod Val(Self.txtBightsField.text))
'Wraps Math
self.txtWraps.text = Str(Val(self.txtBightsField.text) - Val(self.txtRemainder.text))

'GCD
'self.txtGCD.text = THIS IS WHERE I’M STUCK. MAKING THE GCD SHOW IT’S OUTPUT.

'Half Cycle Math
self.txtHalfCycles.text = Str(Val(self.txtBightsField.text) * (2))[/code]

Brian

Once again:

Dont have a textbox called txtGCD AND a string variable called txtGCD

Change the local variables to be strGCD and strTotal and strRemainder

Or better: Use my code above, and at the end of the code where you got confused, just add a few lines like this:

txtGCD.text = str(nGCD)
txtRemainder.text = str(nRemainder)

and so on.

(The only reason self.txtTotal.text = ?? works is because you prefixed the txtTotal with self.
That tells Xojo that you dont mean the local variable called txtTotal, but he control on the window instead
You didnt do that with txtGCD so you get an error.
)