Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: Vba loop

  1. #21
    Board Regular
    Join Date
    Apr 2010
    Posts
    53
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Xoolmonster View Post
    Quote Originally Posted by Xoolmonster View Post
    Sub UntilHundred()
    Quote Originally Posted by Xoolmonster View Post

    Do Until x > 100

    x = x + userinput

    userinput = InputBox("Give a number ")

    Userinput = Val(Userinput)

    Loop

    MsgBox "Sum of the numbers is " & x

    End sub


    Something like this right?

    Code:
    Sub UntilHundred()
        Do Until x > 100    ' good
            x = x + Userinput ' move this below your userinput lines
                              ' this is causing the inputs to be added
                              ' on the next loop instead of the current
            Userinput = InputBox("Give a number ") ' good
            Userinput = Val(Userinput) ' good
        Loop
        MsgBox "Sum of the numbers is " & x ' good
    End Sub
    Last edited by Steve_; May 19th, 2019 at 02:54 PM.

  2. #22
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Sub UntilHundred()

    Do Until x > 100

    userinput = InputBox("Give a number ")

    Userinput = Val(Userinput)

    x = x + userinput

    Loop

    MsgBox "Sum of the numbers is " & x

    End sub

    like this?

  3. #23
    Board Regular
    Join Date
    Apr 2010
    Posts
    53
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Xoolmonster View Post
    Sub UntilHundred()

    Do Until x > 100

    userinput = InputBox("Give a number ")

    Userinput = Val(Userinput)

    x = x + userinput

    Loop

    MsgBox "Sum of the numbers is " & x

    End sub

    like this?
    This code will accomplish what you provided guidelines for. Well done.

  4. #24
    Board Regular
    Join Date
    Apr 2010
    Posts
    53
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    And just for fun, this is your code, condensed/simplified...


    Code:
    Sub UntilHundred()
        Do Until UserInput > 100
            UserInput = UserInput + Val(InputBox("Give a number ", "Current Total is: " & 0 + UserInput))
        Loop
        MsgBox "Sum of the numbers is " & UserInput, vbOKOnly + vbInformation, "Sum"
    End Sub
    If you look at it and dissect it, you should be able to see every line of code you wrote contained in there., minus the stuff using 'x'. The same things that you did with x were done in this code, but instead it was all done to the UserInput variable instead.
    Last edited by Steve_; May 19th, 2019 at 03:07 PM.

  5. #25
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Steve_ View Post
    This code will accomplish what you provided guidelines for. Well done.
    thank you Steve for your time and patience. have a good day!

  6. #26
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Steve_ View Post
    And just for fun, this is your code, condensed/simplified...


    Code:
    Sub UntilHundred()
        Do Until UserInput > 100
            UserInput = UserInput + Val(InputBox("Give a number ", "Current Total is: " & 0 + UserInput))
        Loop
        MsgBox "Sum of the numbers is " & UserInput, vbOKOnly + vbInformation, "Sum"
    End Sub
    If you look at it and dissect it, you should be able to see every line of code you wrote contained in there., minus the stuff using 'x'. The same things that you did with x were done in this code, but instead it was all done to the UserInput variable instead.
    Now i see what you mean, was a bit hard at first to dissect. sort of a more effective way of doing it. what industry are you in since your this familiar with VBA or code in general?

  7. #27
    Board Regular
    Join Date
    Apr 2010
    Posts
    53
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Xoolmonster View Post
    Now i see what you mean, was a bit hard at first to dissect. sort of a more effective way of doing it. what industry are you in since your this familiar with VBA or code in general?
    I am a 'Systems Engineer' in the IT field. My degree is in Network Administration. Most of my work experience is in Server support and Business Application Development. I use several languages (VBA, VBS, VB.Net, PERL, PS, C, C++, C#, T-SQL, and Python) to create integration solutions. My specialty is MS Office automation. It is my niche skill that sets me apart from most.

    Most of my VBA was learned as a hobby when I set out to create a NES/SNES style RPG. It was a blast! And so fun! I never thought I would get that thing working. Music, Backgrounds, Combat system, save game progress, quest system, user NPC dialogue, stat driven switches. It is actually WHOLE lot of fun to play. My friends love it.
    Last edited by Steve_; May 19th, 2019 at 03:17 PM.

  8. #28
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Steve_ View Post
    I am a 'Systems Engineer' in the IT field. My degree is in Network Administration. Most of my work experience is in Server support and Business Application Development. I use several languages (VBA, VBS, VB.Net, PERL, PS, C, C++, C#, T-SQL, and Python) to create integration solutions. My specialty is MS Office automation. It is my niche skill that sets me apart from most.

    Most of my VBA was learned as a hobby when I set out to create a NES/SNES style RPG. It was a blast! And so fun! I never thought I would get that thing working. Music, Backgrounds, Combat system, save game progress, quest system, user NPC dialogue, stat driven switches. It is actually WHOLE lot of fun to play. My friends love it.
    Thats interesting, lots of languages. But from my understanding all languages follow the same logic more or less. You’re a pretty smart guy, accomplished a lot... I do this for my bachelors in economics, Helsinki Finland. Programming is essential to know as an economist nowadays.

  9. #29
    Board Regular
    Join Date
    Apr 2010
    Posts
    53
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Xoolmonster View Post
    Thats interesting, lots of languages. But from my understanding all languages follow the same logic more or less. You’re a pretty smart guy, accomplished a lot... I do this for my bachelors in economics, Helsinki Finland. Programming is essential to know as an economist nowadays.
    The syntax can vary wildly. Especially when I get stuck working with ancient languages I learned in the 90s (COBOL, Fortran, Pascal, GW/Q/Basic , BasicA.

    But once a coder learns a good amount of VB, C, and maybe some Java or a .net langauge, most are able to bumble through most languages albeit slowly.
    The biggest exception to this i can think of is T-SQL. That one is its own animal.
    Last edited by Steve_; May 19th, 2019 at 03:31 PM.

  10. #30
    New Member
    Join Date
    May 2019
    Posts
    15
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Vba loop

    Quote Originally Posted by Steve_ View Post
    The syntax can vary wildly. Especially when I get stuck working with ancient languages I learned in the 90s (COBOL, Fortran, Pascal, GW/Q/Basic , BasicA.

    But once a coder learns a good amount of VB, C, and maybe some Java or a .net langauge, most are able to bumble through most languages albeit slowly.
    The biggest exception to this i can think of is T-SQL. That one is its own animal.
    I very much enjoyed talking to you Steve. I sent you a friendsrequest aswell. Hope to have future interesting discussions. I wish you good health for your upcoming new work projects what not!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •