Creating a Program Loop in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cricket
    New Member
    • Sep 2007
    • 9

    Creating a Program Loop in VB

    Hello,

    I am trying to create a loop in an MS Access application that will read in a list of iSeries system names from a file in my Access database, and then submit a command to each of the listed systems.

    I have the code working for submitting the commands to one iSeries system at a time, the problem I am encountering is when I try to us a loop to submit the command to a list of systems.

    Here is what I have for the command loop, my problem that I have hit, which is probably very rudamentary, is that I can't seem to specify a file within my database correctly.

    I keep receiving an error stating "Run-time error '53': File not found

    The file definitley exist, and the spelling is correct. Is there some syntax I am missing to specifiy the file in my current database?

    *note - iseries is the name of the field which I am trying to read in.

    Code:
    If system_name = "ALL" Then
    
        Open "myfile" For Input As #1
            Do While Not EOF(1)
            system_name = iseries
            YOUR400.Define system_name
    
            Set Command.system = YOUR400
    
            ' Enter USERID and PWD so the users will not be prompted
            Command.system.USERID = USERID
            Command.system.Password = Password
    
            CU = command_run
    
            Command.Run CU
            Loop
        Close #1
    
        MsgBox ("Command '" & command_run & "' has been issued to all systems by '" & USERID & "' ")
    
    End If
    Any help is greatly appreciated, and I apologize if this question is very elementary in nature.

    Thank you.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    I'm not really getting the question I'm afraid.

    With something like this it's important that you get all your details correct. My understanding starts to go grey and fuzzy in the first paragraph as Access databases don't contain files :S
    Originally posted by Cricket
    I am trying to create a loop in an MS Access application that will read in a list of iSeries system names from a file in my Access database, and then submit a command to each of the listed systems.
    There are other parts too which don't quite make sense so I couldn't get back on track.

    If you have code which does work (for a single item say) then post that explaining what it does.

    If you then go on to say where it goes wrong with your attempted loop then it may help someone to help you.

    Comment

    • cricket
      New Member
      • Sep 2007
      • 9

      #3
      Originally posted by NeoPa
      I'm not really getting the question I'm afraid.

      With something like this it's important that you get all your details correct. My understanding starts to go grey and fuzzy in the first paragraph as Access databases don't contain files :S

      There are other parts too which don't quite make sense so I couldn't get back on track.

      If you have code which does work (for a single item say) then post that explaining what it does.

      If you then go on to say where it goes wrong with your attempted loop then it may help someone to help you.
      Sorry for the confusion, I should have said there is a table in my database that I am trying to read in.

      Here is the code that I am using to send a command to a single iSeries server, this code currently works:

      Code:
      Private Sub Command10_Click()
      
      Dim systemNames As New cwbx.systemNames
      Dim YOUR400 As New cwbx.AS400System
      Dim Command As New cwbx.Command
      Dim CU As String
      
      
      
      YOUR400.Define system_name
      
      Set Command.system = YOUR400
      
      ' Enter USERID and PWD so the users will not be prompted
      Command.system.USERID = USERID
      Command.system.Password = Password
      
      CU = command_run
      
      Command.Run CU
      
      MsgBox ("Command '" & command_run & "' has been issued to '" & system_name & "' by '" & USERID & "' ")
      
      End Sub
      The variables are being passed from user input entered on a form, and the process is enacted by clicking a command button.

      What I am trying to do is to be able to submit a single command to multiple iSeries servers by reading the list of server names in from a table located in my Access database.

      Here is the code I have so far (assuming "myfile" is my table listing the iSeries machines in a column called "iseries":

      Code:
      Private Sub Command10_Click()
      
      
      Dim systemNames As New cwbx.systemNames
      Dim YOUR400 As New cwbx.AS400System
      Dim Command As New cwbx.Command
      Dim CU As String
      
      Open "myfile" For Input As #1
              Do While Not EOF(1)
              system_name = iseries
              YOUR400.Define system_name
      
              Set Command.system = YOUR400
      
              ' Enter USERID and PWD so the users will not be prompted
              Command.system.USERID = USERID
              Command.system.Password = Password
      
              CU = command_run
      
              Command.Run CU
              Loop
      Close #1
      
      MsgBox ("Command '" & command_run & "' has been issued to all systems by '" & USERID & "' ")
      
      End Sub
      Sorry if I am leaving anything out I apologize, I am really new to VB.

      Thanks again for all of your insight.

      Comment

      • cricket
        New Member
        • Sep 2007
        • 9

        #4
        Sorry, one more piece of information:

        The form that is submitting the VB script has four fields:

        userid (text box)
        Password (text box)
        system_name (combo box derived from a table (system_options .iseries)
        command_run

        The entire code uses two If...then statements to determine whether or not the user is trying to submit a command to a single iSeries (AS400) system or all of our iSeries systems (in which case the user would choose ALL instead of a specific system name.)

        I removed the If. . .then statements for the sake of separating the code into what works, and what doesn't.

        Hope this helps . . . thanks again.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          That's really quite well explained now Cricket.

          I will have a look at this over the weekend and see if I can't determine the problem.

          Comment

          • cricket
            New Member
            • Sep 2007
            • 9

            #6
            Originally posted by NeoPa
            That's really quite well explained now Cricket.

            I will have a look at this over the weekend and see if I can't determine the problem.

            I really appreciate the help, I have been racking my brain and scouring the internet, but all of the examples reference files outside of databases.

            On a side note, this site has been a valuable resource while I have been coding for various projects. There is a ton of good info archived here. Thanks to all who contribute, your efforts are helping a lot of people.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Nice of you to say so. We're trying to build up a useful archive so that it can be used not only as an interactive forum, but also a repository of knowledge for anyone to search through :)

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32656

                #8
                I didn't manage to get on at all over the weekend so I will fit in a look at this as soon as I can.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  I've had a deeper look now and I'm coming unstuck on your reference to a cwbx object. This is unclear and unreferenced as far as I can see. What and where is the code that defines or declares it?

                  Comment

                  • cricket
                    New Member
                    • Sep 2007
                    • 9

                    #10
                    Originally posted by NeoPa
                    I've had a deeper look now and I'm coming unstuck on your reference to a cwbx object. This is unclear and unreferenced as far as I can see. What and where is the code that defines or declares it?
                    I am a little embarrassed to admit I do not know. Most of my coding in VB has been done the "banging my head into walls" method, so some of structure etc. is a bit hazy to me.

                    I do know that when I have seen connections made to an AS/400 those Dim statements seem to be declared most of the time. I am not sure why they are referred to as cwbx though.

                    I am going to do some more reading, and will report back with anything further I find.

                    Thanks again for all of your help.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32656

                      #11
                      I expect it's declared somewhere in your code if not defined (Declaration is where a reference is made to a pre-existing entity (external library or such like) whereas a definition is where it's created within your code).

                      Comment

                      Working...