Results 1 to 16 of 16

Thread: Hi ! ^^

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    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 !

  2. #2
    Junior Member
    Join Date
    Aug 2006
    Location
    India
    Posts
    19

    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?

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Beginners Luck !

    You can use Replace and Split; not the fastest and most elegant way to do it, but will work.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim strKeys As String, strFolding As String, strNumbers() As String
    3.     Dim lngAnswer As Long, lngA As Long
    4.     ' store key values
    5.     strKeys = txtKeyValues.Text
    6.     ' there must be ten values
    7.     If Len(strKeys) <> 10 Then MsgBox "Incorrect length for key values.": Exit Sub
    8.     ' get the folding process
    9.     strFolding = txtFoldingProcess.Text
    10.     ' remove spaces
    11.     strFolding = Replace(strFolding, " ", vbNullString)
    12.     ' select each key value, replace the text with the key value
    13.     strFolding = Replace(strFolding, "1st", Left$(strKeys, 1))
    14.     strFolding = Replace(strFolding, "2nd", Mid$(strKeys, 2, 1))
    15.     strFolding = Replace(strFolding, "3rd", Mid$(strKeys, 3, 1))
    16.     strFolding = Replace(strFolding, "4th", Mid$(strKeys, 4, 1))
    17.     strFolding = Replace(strFolding, "5th", Mid$(strKeys, 5, 1))
    18.     strFolding = Replace(strFolding, "6th", Mid$(strKeys, 6, 1))
    19.     strFolding = Replace(strFolding, "7th", Mid$(strKeys, 7, 1))
    20.     strFolding = Replace(strFolding, "8th", Mid$(strKeys, 8, 1))
    21.     strFolding = Replace(strFolding, "9th", Mid$(strKeys, 9, 1))
    22.     strFolding = Replace(strFolding, "10th", Right$(strKeys, 1))
    23.     ' now split by summing
    24.     strNumbers = Split(strFolding, "+")
    25.     ' add up the values together
    26.     For lngA = 0 To UBound(strNumbers)
    27.         ' add up the values together into the final answer
    28.         lngAnswer = lngAnswer + CLng(Val(strNumbers(lngA)))
    29.     Next lngA
    30.     ' show the answer
    31.     MsgBox "The answer is " & CStr(lngAnswer)
    32. 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.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Beginners Luck !

    Quote 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.

  5. #5
    Junior Member
    Join Date
    Aug 2006
    Location
    India
    Posts
    19

    Smile Re: Beginners Luck !

    Quote 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!!!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    Re: Beginners Luck !

    Quote 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 ....

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Beginners Luck !

    Quote 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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    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 ......

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    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

  10. #10
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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:
    1. Dim result As String
    2.     For i = 1 To Len(Text1.Text)
    3.         If i = 0 Or i = Len(Text1.Text) Then
    4.             result = result & Mid(Text1.Text, i, 1)
    5.         Else
    6.             result = result & Mid(Text1.Text, i, 1) & "+"
    7.         End If
    8.     Next i
    9.         MsgBox result

  11. #11
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Hi ! ^^

    You already have posted the same question in thishttp://www.vbforums.com/showthread.php?t=424312 Please stick to one thread only.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    Re: Hi ! ^^

    Quote 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:
    1. Dim result As String
    2.     For i = 1 To Len(Text1.Text)
    3.         If i = 0 Or i = Len(Text1.Text) Then
    4.             result = result & Mid(Text1.Text, i, 1)
    5.         Else
    6.             result = result & Mid(Text1.Text, i, 1) & "+"
    7.         End If
    8.     Next i
    9.         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

  13. #13
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Hi ! ^^

    VB Code:
    1. Dim i As Integer
    2. Dim arr() As String
    3. Dim result As Double
    4.     Text1.Text = Replace(Text1.Text, " ", "")
    5.     arr() = Split(Text1.Text, "+")
    6.         For i = 0 To UBound(arr)
    7.             result = result + CDbl(arr(i))
    8.         Next i
    9.             MsgBox result
    However, this only works for addition (+).

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    Beach Alley
    Posts
    86

    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 ....

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Hi ! ^^

    Quote Originally Posted by Simply Me
    You already have posted the same question in thishttp://www.vbforums.com/showthread.php?t=424312 Please stick to one thread only.
    Threads merged.

  16. #16
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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
  •  



Click Here to Expand Forum to Full Width