|
-
Aug 24th, 2006, 06:39 AM
#1
Thread Starter
Lively Member
Beginners Luck !
Hi ! anyone knows about folding process .... because i can't do this process ..... i have one textbox where i type the key values ... Ex: 1234567890 <--- this is the key values ........ the next textbox where i type the folding process... Ex: 1st + 2nd + 3rd4th + 5th + 6th + 7th8th9th + 10th <---this is the folding process ..... the answer is ... "837" ...... there's to many possible proces that can be used ..... like: "1st2nd3rd4th + 5th + 6th + 7th8th9th + 10th" & "1st + 2nd + 3rd4th + 5th + 6th + 7th + 8th + 9th + 10th" & "1st2nd3rd4th5th6th + 7th8th9th10th" and so on and so fort .... what is the best code for this ....... Thank You !
-
Aug 24th, 2006, 06:50 AM
#2
Junior Member
Re: Beginners Luck !
The answer for Ex: 1st + 2nd + 3rd4th + 5th + 6th + 7th8th9th + 10th <---this is the folding process ..... the answer is ... "837" or 847?
-
Aug 24th, 2006, 07:11 AM
#3
Re: Beginners Luck !
You can use Replace and Split; not the fastest and most elegant way to do it, but will work.
VB Code:
Private Sub Command1_Click()
Dim strKeys As String, strFolding As String, strNumbers() As String
Dim lngAnswer As Long, lngA As Long
' store key values
strKeys = txtKeyValues.Text
' there must be ten values
If Len(strKeys) <> 10 Then MsgBox "Incorrect length for key values.": Exit Sub
' get the folding process
strFolding = txtFoldingProcess.Text
' remove spaces
strFolding = Replace(strFolding, " ", vbNullString)
' select each key value, replace the text with the key value
strFolding = Replace(strFolding, "1st", Left$(strKeys, 1))
strFolding = Replace(strFolding, "2nd", Mid$(strKeys, 2, 1))
strFolding = Replace(strFolding, "3rd", Mid$(strKeys, 3, 1))
strFolding = Replace(strFolding, "4th", Mid$(strKeys, 4, 1))
strFolding = Replace(strFolding, "5th", Mid$(strKeys, 5, 1))
strFolding = Replace(strFolding, "6th", Mid$(strKeys, 6, 1))
strFolding = Replace(strFolding, "7th", Mid$(strKeys, 7, 1))
strFolding = Replace(strFolding, "8th", Mid$(strKeys, 8, 1))
strFolding = Replace(strFolding, "9th", Mid$(strKeys, 9, 1))
strFolding = Replace(strFolding, "10th", Right$(strKeys, 1))
' now split by summing
strNumbers = Split(strFolding, "+")
' add up the values together
For lngA = 0 To UBound(strNumbers)
' add up the values together into the final answer
lngAnswer = lngAnswer + CLng(Val(strNumbers(lngA)))
Next lngA
' show the answer
MsgBox "The answer is " & CStr(lngAnswer)
End Sub
Have fun figuring out how to expand it to work with multiplication, division and so forth You don't probably want to use Split, but instead work with Mid$ and check character by character what you are getting.
-
Aug 24th, 2006, 07:15 AM
#4
PowerPoster
Re: Beginners Luck !
 Originally Posted by rrn78
The answer for Ex: 1st + 2nd + 3rd4th + 5th + 6th + 7th8th9th + 10th <---this is the folding process ..... the answer is ... "837" or 847?
1) His mathematics isn't the issue, he asked a question not for a maths lesson
2) 1 + 2 + 34 + 5 + 6 + 789 + 0 = 837 (789 + 5 + 6 = 800...1 + 2 + 34 = 37)
Getting back to the question asked, I would probably make a program that tried every possibility...this is a bit of a long-winded way of doing it but there are SO many possible ways to do it you could probably do it with loops and such...if variable(1) = 1 then use +, if variable(1) = 2 then use -, if variable(1) = 3 then use x... if variable(1) = 10 then add on to next number...y'see? You'd have one variable for each number in the sequence, and you would just add 1 to the highest variable number and when that goes past the highest possible return it to 1 and add 1 to the variable below that...then when that variable below goes past the highest possible do the same there...until all possibilities have been tried :-)
(edit) Additionally, you might have forgotten about nested calculations...things like 1 + (2x3) + (4 x 56) + 789...adding in support for nested calculations WILL be a pain...if you don't need nested, I could probably write you a prog to handle calculating it :-)
(edit 2) Just noticed that Merri wrote pretty much what you need...You already know the "calculation" you require and want to know the answer, I thought you knew the answer and wanted the calculation. Here in the UK we have a TV show called Countdown which has a numbers game where you get a set of numbers and the answer and have to give the calculation to get that number :-)
Last edited by smUX; Aug 24th, 2006 at 07:29 AM.
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Aug 24th, 2006, 07:23 AM
#5
Junior Member
Re: Beginners Luck !
 Originally Posted by smUX
1) His mathematics isn't the issue, he asked a question not for a maths lesson
2) 1 + 2 + 34 + 5 + 6 + 789 + 0 = 837 (789 + 5 + 6 = 800...1 + 2 + 34 = 37)
Getting back to the question asked, I would probably make a program that tried every possibility...this is a bit of a long-winded way of doing it but there are SO many possible ways to do it you could probably do it with loops and such...if variable(1) = 1 then use +, if variable(1) = 2 then use -, if variable(1) = 3 then use x... if variable(1) = 10 then add on to next number...y'see? You'd have one variable for each number in the sequence, and you would just add 1 to the highest variable number and when that goes past the highest possible return it to 1 and add 1 to the variable below that...then when that variable below goes past the highest possible do the same there...until all possibilities have been tried :-)
(edit) Additionally, you might have forgotten about nested calculations...things like 1 + (2x3) + (4 x 56) + 789...adding in support for nested calculations WILL be a pain...if you don't need nested, I could probably write you a prog to handle calculating it :-)
My query wasnt to question his Mathematics. I only wanted to know how it works. Probably I didnt understand the question correctly. Thanks for explaining!!!
-
Aug 24th, 2006, 07:40 AM
#6
Thread Starter
Lively Member
Re: Beginners Luck !
 Originally Posted by rrn78
The answer for Ex: 1st + 2nd + 3rd4th + 5th + 6th + 7th8th9th + 10th <---this is the folding process ..... the answer is ... "837" or 847?
Sorry "rrn" yah it's 847 ....
-
Aug 24th, 2006, 07:42 AM
#7
PowerPoster
Re: Beginners Luck !
 Originally Posted by LegoKid
Sorry "rrn" yah it's 847 ....
So the last number is considered to be 10 not 0?
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Aug 24th, 2006, 07:48 AM
#8
Thread Starter
Lively Member
Re: Beginners Luck !
Hi smux ... yah i dont need the nested if .... i just need that when the user inputed a number in my first textbox like "1234567890" and the the user should follow up inputed in my second textbox where the process must be done like " 1 +23 + 456 +789 + 0" and the answer must seen at my third textbox that would be "1269" .... and another problem that i have said there to many possible process that can be done like "123456 + 7890" or "12+ 34 + 56 + 78 +90" and so on and so fort .... so the program should be flexible ......
-
Aug 24th, 2006, 09:06 AM
#9
Thread Starter
Lively Member
Hi ! ^^
i just want to ask .... what code is the best for this ....
i have 3txtBoxes and 1 commandbutton
1st txtBox the user must input 10 or less than 10 Ex: 1234567890
2nd txtBox the user must input a folding process Ex: 1+2+345+6789+0
3rd txtBox where the answer appers Ex: 7137
And another
if i input "12345"
and the process that i want is "123+45"
the answer must be "51"
And another thing
there's too many possible process that can be done that depends on how many digits that inputed Ex: 6 digits the process that i want is 1+2+3+4+5+6
so please help me
-
Aug 24th, 2006, 09:18 AM
#10
Re: Hi ! ^^
Don't quite understand what you want... however, if you want to get 1+2+3+4+5+6 from 123456 you can do it with a loop:
VB Code:
Dim result As String
For i = 1 To Len(Text1.Text)
If i = 0 Or i = Len(Text1.Text) Then
result = result & Mid(Text1.Text, i, 1)
Else
result = result & Mid(Text1.Text, i, 1) & "+"
End If
Next i
MsgBox result
-
Aug 24th, 2006, 09:19 AM
#11
PowerPoster
Re: Hi ! ^^
You already have posted the same question in thishttp://www.vbforums.com/showthread.php?t=424312 Please stick to one thread only.
-
Aug 24th, 2006, 09:31 AM
#12
Thread Starter
Lively Member
Re: Hi ! ^^
 Originally Posted by gavio
Don't quite understand what you want... however, if you want to get 1+2+3+4+5+6 from 123456 you can do it with a loop:
VB Code:
Dim result As String
For i = 1 To Len(Text1.Text)
If i = 0 Or i = Len(Text1.Text) Then
result = result & Mid(Text1.Text, i, 1)
Else
result = result & Mid(Text1.Text, i, 1) & "+"
End If
Next i
MsgBox result
HI GAVIO ... this all i want to say ...
The user input Ex: 1234567890
And the user also input whatever process he want Ex: 1 + 234 + 567 + 890
and the answer must be "1692"
how should i do this ?
[ P.S ]
there's too many possible process it depends on how many digits did the user inputed
Ex:
3digits = 1+2+3 or 12+3 or 1+23
4digits = 1+2+3+4 or 12+34 or 123+4 and so on...
5digits = 1+2+345 or 123+45 and so on
6digits = 123+456 or 12+34+56 and so on
up to 10 digits
-
Aug 24th, 2006, 09:37 AM
#13
Re: Hi ! ^^
VB Code:
Dim i As Integer
Dim arr() As String
Dim result As Double
Text1.Text = Replace(Text1.Text, " ", "")
arr() = Split(Text1.Text, "+")
For i = 0 To UBound(arr)
result = result + CDbl(arr(i))
Next i
MsgBox result
However, this only works for addition (+).
-
Aug 24th, 2006, 09:50 AM
#14
Thread Starter
Lively Member
Re: Hi ! ^^
Thank you Gavio ... now i have an idea how to add the numbers that had been inputed ... all i have to do is to apply it in the number that inputed what i'd like to say is in the code that you given to me ... i try it Ex: i inputted "1234" and the process is "12+34" and the answer appears 46 ... but now if the user putted "6879" when i use the process 12+34 the answer the answer still appears 46 ....
-
Aug 24th, 2006, 09:52 AM
#15
Re: Hi ! ^^
 Originally Posted by Simply Me
Threads merged.
-
Aug 24th, 2006, 10:07 AM
#16
Re: Hi ! ^^
Everything you need is in my post #13. You can't just have ideas and people working for you.
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
|