I am wanting to create a simple program that solves equations in the form
A(x) + B(y) = C
Where A, B and C have already been inputted into text boxes.
Ideally the program would start with a y value of -500, and then try x = -500, -499, - 498 etc etc until it reached 500.
Then y would increase by 1 and try all the x values again, and so on. If anything matches the value of C, it would all be added to a List Box.
Here is the code I have put together (forgive me if the syntax is horrendous!)
**I have three input text boxes, a list box and a command button.**
Private Sub Command1_Click()
Dim a As Variant, b As Variant, c As Variant, x As Variant, y As Variant
a = Text1
b = Text2
c = Text3
For y = -500 To 500
For x = -500 To 500
If (a * x) + (b * y) = c Then
List1.AddItem Trim$(a) + Trim$(x) + "+" + Trim$(b) + Trim$(y) + "=" + Trim(c)
x = x + 1
y = y + 1
I am getting a lot of 'loop without do' errors. However If I place a 'do' at the top of each loop it seems to make no difference.
Is it an issue that I have a loop system within another loop? (i'm not really sure how else I would do this problem)
Re: Linear Diophantine Equation Solver (Loops Help)
Welcome to the forums!
Please use CODE TAGS in the future...
' Like This
As far as your code goes, you need to learn about TYPES. There are three main types. STRING, NUMERIC, and VARIANT. VB6 is all about using the right type. You cannot add two STRINGs without converting them to NUMBERIC.
If you are using math, you should have variables for the calculated values, and also string values for the output.
Also, to CONCATENATE two strings you use "&" rather than "+"