Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VBS for next loop

VBS for next loop

Scheduled Pinned Locked Moved Visual Basic
help
19 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U User 11883281

    I'm new in VBs.. i've got this code:

    For i = 0 To 20 Step 1.0
    MsgBox "Blubb"& i &"bla"
    Next i

    and this error: 800A0401 "Statement completion expected" "Compile error in Microsoft VBScript"

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    See For...Next Statement[^] and MsgBox Function[^].

    U 1 Reply Last reply
    0
    • L Lost User

      See For...Next Statement[^] and MsgBox Function[^].

      U Offline
      U Offline
      User 11883281
      wrote on last edited by
      #7

      i just looked at this, but i do not find a mistake in my code

      L 1 Reply Last reply
      0
      • U User 11883281

        okay, thank you but the error is still comming it have to be the loop, cause i now only have

        For i = 0 To 20 Step 1.0

        Next i

        and the error is still comming

        W Offline
        W Offline
        Wombaticus
        wrote on last edited by
        #8

        Well try setting the "step" to just 1 rather than 1.0 Presumably you have defined that as an Integer? And you can remove the final i after Next.

        U 1 Reply Last reply
        0
        • W Wombaticus

          Well try setting the "step" to just 1 rather than 1.0 Presumably you have defined that as an Integer? And you can remove the final i after Next.

          U Offline
          U Offline
          User 11883281
          wrote on last edited by
          #9

          i just ignor the step, it doesnt matter if it says "step 1" or nothing, 1 is the default value

          W 1 Reply Last reply
          0
          • U User 11883281

            i just ignor the step, it doesnt matter if it says "step 1" or nothing, 1 is the default value

            W Offline
            W Offline
            Wombaticus
            wrote on last edited by
            #10

            So now you're saying

            For i = 0 To 20

            Next i

            is giving you an error? I don't think so... unless you have not defined the variable i at all.

            U 1 Reply Last reply
            0
            • U User 11883281

              i just looked at this, but i do not find a mistake in my code

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #11

              Look at the Next statement, it does not use the variable name.

              U 1 Reply Last reply
              0
              • W Wombaticus

                So now you're saying

                For i = 0 To 20

                Next i

                is giving you an error? I don't think so... unless you have not defined the variable i at all.

                U Offline
                U Offline
                User 11883281
                wrote on last edited by
                #12

                This:

                Dim i as Integer
                for i = 0 To 20
                ' MsgBox "Blubb" & i & "bla"
                ' ticketno = Replace(ticketno,"("& i & ")","")
                Next

                or this

                Dim i
                for i = 0 To 20
                ' MsgBox "Blubb" & i & "bla"
                ' ticketno = Replace(ticketno,"("& i & ")","")
                Next

                is showing the error

                W C 2 Replies Last reply
                0
                • L Lost User

                  Look at the Next statement, it does not use the variable name.

                  U Offline
                  U Offline
                  User 11883281
                  wrote on last edited by
                  #13

                  oh thankyou but that wasnt the error at all

                  L 1 Reply Last reply
                  0
                  • U User 11883281

                    This:

                    Dim i as Integer
                    for i = 0 To 20
                    ' MsgBox "Blubb" & i & "bla"
                    ' ticketno = Replace(ticketno,"("& i & ")","")
                    Next

                    or this

                    Dim i
                    for i = 0 To 20
                    ' MsgBox "Blubb" & i & "bla"
                    ' ticketno = Replace(ticketno,"("& i & ")","")
                    Next

                    is showing the error

                    W Offline
                    W Offline
                    Wombaticus
                    wrote on last edited by
                    #14

                    Well, the first will - you don't DIM variables with the As [type] in VBS. You could try

                    Dim i%

                    but other than that, and capitalizing the F in for, which shouldn't really be necessary, I really find it hard to believe that this is where the error really lies. You need to pin down the exact line.....

                    1 Reply Last reply
                    0
                    • U User 11883281

                      I'm new in VBs.. i've got this code:

                      For i = 0 To 20 Step 1.0
                      MsgBox "Blubb"& i &"bla"
                      Next i

                      and this error: 800A0401 "Statement completion expected" "Compile error in Microsoft VBScript"

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #15

                      No "i" after "next".

                      For i = 0 To 10 Step 1
                      MsgBox "Blubb" & i & "bla"
                      Next

                      works for me :)

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                      C 1 Reply Last reply
                      0
                      • L Lost User

                        No "i" after "next".

                        For i = 0 To 10 Step 1
                        MsgBox "Blubb" & i & "bla"
                        Next

                        works for me :)

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                        C Offline
                        C Offline
                        CHill60
                        wrote on last edited by
                        #16

                        Beat me to it by a couple of minutes!

                        1 Reply Last reply
                        0
                        • U User 11883281

                          This:

                          Dim i as Integer
                          for i = 0 To 20
                          ' MsgBox "Blubb" & i & "bla"
                          ' ticketno = Replace(ticketno,"("& i & ")","")
                          Next

                          or this

                          Dim i
                          for i = 0 To 20
                          ' MsgBox "Blubb" & i & "bla"
                          ' ticketno = Replace(ticketno,"("& i & ")","")
                          Next

                          is showing the error

                          C Offline
                          C Offline
                          CHill60
                          wrote on last edited by
                          #17

                          The key point you are missing here is that it is not actually the same error! If I paste your original code into t1.vbs I get the following error

                          C:\Temp\t1.vbs**(3, 6)** Microsoft VBScript compilation error: Expected end of statement

                          Removing the i after the Next fixes that problem (as suggested by @Wombaticus) If I do the same thing with your first block of code above I get

                          C:\Temp\t1.vbs**(1, 7)** Microsoft VBScript compilation error: Expected end of statement

                          ...getting rid of the as Integer fixes that one (as suggested by @Wombaticus) Your second block of code above does not produce anything - neither error nor output. If you were getting an error there are you sure you remembered to save the changes in your editor before attempting to run the script file? We've all done that a few times :laugh: However, to get to the point ... See those numbers in brackets in my error messages above that are in bold? They indicate the ROW and COLUMN that the error occurs in - so the error moved from line 3 in the first example to line 1 in the second. Much easier to find the problem when you know that little bit of extra infomation

                          1 Reply Last reply
                          0
                          • U User 11883281

                            oh thankyou but that wasnt the error at all

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #18

                            Yes it was. When I removed the i from the Next statement it worked correctly. I can only assume you are doing something different to what you posted.

                            1 Reply Last reply
                            0
                            • W Wombaticus

                              What's with

                              Hide Copy Code

                              ? Comment that out....

                              U Offline
                              U Offline
                              User 11883281
                              wrote on last edited by
                              #19

                              Thank you very much.... i don't even know what the error was. I had to restart the server, and now it works without doing anything :D but thank you :D

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups