
May 5th, 2021, 10:31 PM
#1
Thread Starter
Member
Combining method for math
Hi everyone!
I'm having a hard time trying to figure it out a new coding method for my new program using vb6. For example adding only three combination numbers to have = "9" using only numbers from 1 to 10 like for example 3+4+2=9,
2+6+1=9, 3+1+5=9. My point is using a textbox to put the number "9" that will find combinations using numbers from 1 to 10 with a command click and to show all possible combinations in a labelbox or anything that you think is easier. I would appreciate your help for this coding if it's possible. Thanks.

May 5th, 2021, 10:50 PM
#2
Re: Combining method for math
You're not having trouble figuring out the code. You're (supposedly) having trouble figuring out the logic. The code is simply an implementation of the logic. The logic would be the same no matter what language you were writing the code in or even if you weren't writing any code at all. You should be putting some thought and effort into figuring out the logic first, before even considering writing any code. One of the main reasons that so many people have trouble writing code is that they have no idea what that code is supposed to do, which is the case here. Spend some time figuring out what the code has to do first. That's nothing to do with VB6 or any other programming language. Once you have a handle on the logic, if and when you have trouble implementing that logic in VB6 is when it becomes a VB6 question, at which point you can explain what the code is actually supposed to do and where you're stuck doing it.

May 5th, 2021, 11:41 PM
#3
Re: Combining method for math
Originally Posted by jmcilhinney
You're not having trouble figuring out the code. You're (supposedly) having trouble figuring out the logic. The code is simply an implementation of the logic. The logic would be the same no matter what language you were writing the code in or even if you weren't writing any code at all. You should be putting some thought and effort into figuring out the logic first, before even considering writing any code. One of the main reasons that so many people have trouble writing code is that they have no idea what that code is supposed to do, which is the case here. Spend some time figuring out what the code has to do first. That's nothing to do with VB6 or any other programming language. Once you have a handle on the logic, if and when you have trouble implementing that logic in VB6 is when it becomes a VB6 question, at which point you can explain what the code is actually supposed to do and where you're stuck doing it.
Right on
I was a senior systems analyst for 20 years (Large bank then biggest world telecommunication Co).
Occasionally projects would arise, when there were not enough analysts available to run them.
Management sometimes allocated the new projects to programmers.
They all failed

May 6th, 2021, 12:51 AM
#4
Re: Combining method for math
What about the order?
1+2+6 would be considered the same than 2+1+6 or different?

May 6th, 2021, 05:58 AM
#5
Re: Combining method for math
Well, let's see....logic?
1you know the 'final' result.
2IF you are not including zeros as any of the 'three' numbers, then you know the largest number possible would be 3 less than your desired result.
3Are these whole numbers, or can you have decimals? (Whole numbers is relatively easy to figure the logic for, but decimals...well, depending upon how many digits after the period (or comma, depending upon your locale), would be much more difficult to calculate (well, maybe not more difficult, but would certainly take more loops when coding).
4So, start with 1 (or zero if you allow them), add to it the next number (2). Take that result and subtract from your desired result to find the third number.
Then, start with 2, add to IT the next number (3). Take THAT result and subtract from your desired result to determine the third number.
Do this until you have until the first two numbers equal one less than the desired result.
Now, if you do this, you will see some combinations you have saved along the way are the same, just some of the numbers will be reversed. Keep track of each 'set' and if they 'match' (that is, the same three numbers but not in the same order), then disregard that combination.
Obviously (to me, anyway), you would have loops within loops as you do this. Seems pretty basic.
(Eduardo...good question, but I'd wager that OP would consider the order to be relevant, IOW, 1+2+6 would be the SAME as 2+1+6.)
Sam I am (as well as Confused at times).

May 6th, 2021, 06:15 AM
#6
Re: Combining method for math
So, here's my result of a simple loop....note the third and fourth entry: they are the same numbers, but simply reversed. When that occurs, I would think you would not include it in the list.
(Now, this sounds like a homework assignment, so I am not going to post my code, but will offer assistance on YOUR code attempts.)
Sam I am (as well as Confused at times).

May 6th, 2021, 06:33 AM
#7
Re: Combining method for math
The explanation or better the requirements are unclear.
Are the following allowed?:
10 = 8 + 1 + 1
10 = 6 + 2 + 2
Or these, which also contain the same values
10 = 2 + 3 + 5
10 = 2 + 5 + 3
10 = 3 + 2 + 5
10 = 3 + 5 + 2
10 = 5 + 2 + 3
10 = 5 + 3 + 2

May 6th, 2021, 02:48 PM
#8
Re: Combining method for math
can you use the same number more than once?
Examples: (4 + 4 + 1 = 9) ??? or (3 + 3 + 3 = 9) ???
Sam I am (as well as Confused at times).

May 6th, 2021, 03:24 PM
#9
Thread Starter
Member
Re: Combining method for math
Originally Posted by SamOscarBrown
So, here's my result of a simple loop....note the third and fourth entry: they are the same numbers, but simply reversed. When that occurs, I would think you would not include it in the list.
(Now, this sounds like a homework assignment, so I am not going to post my code, but will offer assistance on YOUR code attempts.)
This is what I've been trying to code. Im new to VB friend so i have limited knowledge in my progress but that code can help me a lot to make it useful in my assignment for astronomical use. I don't even know how to start coding this is something new I'm working on, if you can help me i would appreciate your help.

May 6th, 2021, 03:29 PM
#10
Re: Combining method for math
Instead of starting with coding, start with describing what you need. In detail.
You have ignored all our questions and suggestions!

May 6th, 2021, 04:54 PM
#11
Re: Combining method for math
Get a book. Read it from start to finish. If there are examples in the book, DO them.
There are online books (for free, but forum rules prevent me from recommending one "I" used when I first started out). Read/order/learn.
And like Arnie says, use pseudocode first. Take a pen and paper (or pencil if you are prone to making errors) and 'sketch out' both in words and diagrams what you want to accomplish.
If you don't know what pseudocode is, you had better find the MOST BASIC of programming books and start there.
We are not trying to discourage you, but for us to DO your stuff (homework?) for you is just wrong on several levels. You don't learn. We waste time. You don't get your homework done.
Sammi
EDIT...well, you WOULD get your homework done, but it wouldn't be YOU doing it...you can't go through life copypasting everything that comes up!!!
Sam I am (as well as Confused at times).

May 6th, 2021, 06:54 PM
#12
Thread Starter
Member
Re: Combining method for math
Yes, it can be used more than once as long it makes all possible combinations using numbers from 1 to 10 to get the answer from top of textbox ( whatever number is entered in textbox).

May 6th, 2021, 06:59 PM
#13
Thread Starter
Member
Re: Combining method for math
Sam if you can only give me a piece of start code for this project i can always do the rest to finish it up and figure it out the rest and still learn as part of challenge but since i don't have nothing as evidence i can't even start homework.

May 6th, 2021, 09:34 PM
#14
Re: Combining method for math
But if it is some kind of homework (from the school?) we would not be doing any good giving it already cooked. You won't learn anything.
Define three variables and make three for/next for each one. Place one for/next inside the other.
Then, inside the inner for/next, sum the three numbers and compare if they match the desired result.
If they do, append them to a list of results.

May 6th, 2021, 09:39 PM
#15
Re: Combining method for math
Want some code?
Code:
Dim n1 As Long
Dim n2 As Long
Dim n3 As Long
For n1 = 1 To 10
Next n1
Do the rest.

May 6th, 2021, 09:50 PM
#16
Re: Combining method for math
Originally Posted by CoderVB
Sam if you can only give me a piece of start code for this project i can always do the rest to finish it up and figure it out the rest and still learn as part of challenge but since i don't have nothing as evidence i can't even start homework.
And still you're talking about others giving you code when you've made no attempt at all to determine the logic.
Originally Posted by CoderVB
Im new to VB friend so i have limited knowledge
You don't need any programming experience to determine the logic so that you have limited VB knowledge is not relevant to the problem. The problem is that you aren't prepared to make the effort to come up with the logic because it's hard. If you aren't prepared to make that effort to do your own homework then you don't deserve to get the marls for it. There are plenty of people who are willing to help you if you encounter specific issues along the way but if you're not even prepared to make a start then you haven't actually encountered any issues. This is not a code issue. It's a thinking and effort issue.

May 7th, 2021, 04:48 PM
#17
Re: Combining method for math
Originally Posted by SamOscarBrown
So, here's my result of a simple loop....note the third and fourth entry: they are the same numbers, but simply reversed. When that occurs, I would think you would not include it in the list.
(Now, this sounds like a homework assignment, so I am not going to post my code, but will offer assistance on YOUR code attempts.)
I Found this results:
input = 12
1 + 2 + 9
1 + 3 + 8 <
1 + 4 + 7 <
1 + 5 + 6
2 + 3 + 7
2 + 4 + 6 <
3 + 4 + 5
It seems you have missed a few ...
Anyway it depends on the "logic"/"rules" you use.
other examples:

9
1 + 2 + 6
1 + 3 + 5
2 + 3 + 4

10
1 + 2 + 7
1 + 3 + 6
1 + 4 + 5
2 + 3 + 5

14
1 + 2 + 11
1 + 3 + 10
1 + 4 + 9
1 + 5 + 8
1 + 6 + 7
2 + 3 + 9
2 + 4 + 8
2 + 5 + 7
3 + 4 + 7
3 + 5 + 6
Last edited by reexre; May 7th, 2021 at 04:55 PM.

May 8th, 2021, 07:20 PM
#18
Thread Starter
Member
Re: Combining method for math
Attachment 181378
This is what I have so far but need to filter those numbers from respecting in the listbox

May 10th, 2021, 03:16 PM
#19
Thread Starter
Member
Re: Combining method for math
Originally Posted by Eduardo
Want some code?
Code:
Dim n1 As Long
Dim n2 As Long
Dim n3 As Long
For n1 = 1 To 10
Next n1
Do the rest.
This my filtering but would be very long if i use this method. I'm trying get someone help me to do the short algorithm method which I'm not familiar with.

May 10th, 2021, 03:37 PM
#20
Re: Combining method for math
This is the code I used.
It does not do the repetition of the same number.
Code:
Private Sub Form_Load()
Dim N1%, N2%, N3%
Dim Sum%, R$
Sum = InputBox("Type Number", "Input", 12)
For N1 = 1 To Sum  1
For N2 = N1 + 1 To Sum  2
For N3 = N2 + 1 To Sum  3
If N1 + N2 + N3 = Sum Then
R = R & N1 & " + " & N2 & " + " & N3 & vbCrLf
End If
Next
Next
Next
Debug.Print ""
Debug.Print Sum
Debug.Print R
MsgBox R
End
End Sub

May 10th, 2021, 07:07 PM
#21
Thread Starter
Member
Re: Combining method for math
Originally Posted by reexre
This is the code I used.
It does not do the repetition of the same number.
Code:
Private Sub Form_Load()
Dim N1%, N2%, N3%
Dim Sum%, R$
Sum = InputBox("Type Number", "Input", 12)
For N1 = 1 To Sum  1
For N2 = N1 + 1 To Sum  2
For N3 = N2 + 1 To Sum  3
If N1 + N2 + N3 = Sum Then
R = R & N1 & " + " & N2 & " + " & N3 & vbCrLf
End If
Next
Next
Next
Debug.Print ""
Debug.Print Sum
Debug.Print R
MsgBox R
End
End Sub
Thanks! this works for me. Just uploaded just trying to limit the numbers now I'm using is 1 to 10, when I input "15" i shouldn't see 12 and 11 on the additions but thanks i see if find the solution.

May 10th, 2021, 07:58 PM
#22
Re: Combining method for math
Originally Posted by CoderVB
This my filtering but would be very long if i use this method. I'm trying get someone help me to do the short algorithm method which I'm not familiar with.
If this is homework, this seems like the kind of assignment that would be given for a chapter that deals with various types of loops (For loops, Do loops, etc.). Assuming that to be the case, your code above tells me that you need to thoroughly review this content. Your conclusion that this method would result in lengthy code is quite correct.

Jun 5th, 2021, 02:16 AM
#23
Registered User
Re: Combining method for math
Can you help me with numbers incrementing every 5 seconds say from 70 to 80 and then again decrementing every 5 seconds back to 70 and showing in a label these values each five seconds. I tried coding but had difficulty while decrementing only the end result shows up in the label that is 70 can you help me with the code?

Jun 5th, 2021, 07:11 AM
#24
Re: Combining method for math
1Welcome to the Forum, sachuc1.
2Please start your own thread with your questions (don't hijack another's, as in this case, the solutions WILL be different)
3In that new thread, post your code (you post code by using the pound sign (#) icon to encapsulate the code you paste into the thread).
4Looking forward to seeing your new Thread.
sammi
Sam I am (as well as Confused at times).
Tags for this Thread
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
