locked
Visual Basic to Visual Studio RRS feed

  • Question

  • User-1520916068 posted

    Hi All,

    I have been using Excel VBA for a while and recently discovered Visual Studio.

    I have tried playing around with visual studio 2008 and to see how much more visual studio can do.

    However I am having problems understanding how this work and hope somebody can help.

    To start with, I have a set of code which has been developed in Excel VBA.

    In Visual Studio 2008, I have started a new project (Windows Forms Applications).

    I have copy my code from VBA into this Project but received a series of errors which I imagine must be because of the language I need to use to declare certain things in Visual Studio.

    Below is the Code

     

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim sSubMax As String
            Dim sSubMax2 As String
            Dim sSubRename As String
            Dim sPattern As String
            Dim sFile As String
            Dim sPath As String
            Dim lMax As Long
            Dim lCurrent As Long


            sSubMax = "C:\DEF\"
            sSubMax2 = "C:\DEF\"
            sSubRename = "C:\ABC\"
            sPattern = "B"
            sPath = sSubMax & sPattern & "*.pdf"
            lMax = 0

            sFile = Dir(sPath)
            Do While sFile <> ""
                lCurrent = Val(Mid(sFile, Len(sPattern) + 1, 4))
                If lCurrent > lMax Then lMax = lCurrent
                sFile = Dir
            Loop

            If lMax = 0 Then
                sPath = sSubMax2 & sPattern & "*.pdf"


                sFile = Dir(sPath)
                Do While sFile <> ""
                    lCurrent = Val(Mid(sFile, Len(sPattern) + 1, 4))
                    If lCurrent > lMax Then lMax = lCurrent
                    sFile = Dir
                Loop
            End If


            sPath = sSubRename & "*.pdf"
            sFile = Dir(sPath)
            Do While sFile <> ""
      Name sSubRename & sFile As _
        sSubMax2 & sPattern & Format(lMax + 1, "0000") & ".pdf"
                lMax = lMax + 1
                sFile = Dir
            Loop
          

     

        End Sub

    The first error I have is  Name sSubRename & sFile As, Method arguments must be enclosed in parentheses. 

    The second error I have is  the same line as above Error 3 Comma, ')', or a valid expression continuation expected.

    The Third error i have is also in the same line Error 1 Property access must assign to the property or use its value. 

     

    The fourth error i have is s SubMax2 & sPattern & Format(lMax + 1, "0000") & ".pdf", end of statement expected

     can somebody please help?

     

    Thanks

    Regards

     

    Gerard

     

    Thursday, October 22, 2009 7:08 AM

Answers