Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I desperately need some assistance. I have no experience with VBA or C# but my supervisor has been deadset on having me rewrite in C# a tool originally written in VBA 10 years ago. I don't wish to point finger at my supervisor, rather, I'm just seeking assistance in order to make the best of the situation.

I've tried YouTube and Google for weeks but have been frustrated by the results, primarily due to my lack of experience with C#.

How can I translate the below to C#?
It's about 20 pages of code but I'm hoping getting this piece going will be the starting point I need.

What I have tried:

'make A020 word document
Sub makeA020()
    Application.ScreenUpdating = False
    Call progress(0, "Initializing", "Making CDRL A020")
    Call setConstants
    'prep Sheet
    Call progress(5, "Prepping Sheet")
    releaseName = importSheet.Range("A3").text
    versionName = importSheet.Range("A2").text
    svdVersion = openSVD(releaseName)
    'open template
    Call progress(10, "Opening Template")
    Set wordApp = makeWordApp
    wordFileName = "\\intranet\busunits\Intel\CPASC\System%20Test\CDRLs\A020%20Software%20Test%20Report%20(STR)\CPASC-A020-STR-Main-Template.docx"
    FileCopy wordFileName, Environ("Temp") & "\CPASC-A020-STR-Main-Template.docx"
    wordFileName = Environ("Temp") & "\CPASC-A020-STR-Main-Template.docx"
    Set wordDoc = wordApp.Documents.Open(wordFileName)
    Call progress(15, "Fixing Bookmark Colors")
    Call fixBookmarkColors(wordDoc)
    Call fillReleaseNameAndDate(wordDoc, releaseName)
    'fill svd version #
    Call progress(25, "Filling SVD")
    wordDoc.bookmarks("ccscVer").Range.text = "Version " & svdVersion & "."
    Call clearCDRLJunk("a020", wordDoc)
    Call getAccessData
    Call clearJunkData(wordDoc)
    Call makeTestLog(wordDoc, svdVersion)
    Call getTestsFromA019(wordDoc)
    Call fillA020Tests(wordDoc)
    Call handleFouo(wordDoc)
    Call handleWitnesses(wordDoc)
    Call progress(80, "Updating Table of Contents")
    Call updateTOC(wordDoc)
    Call a020Deviations(wordDoc)
    Call testResultSummary(wordDoc)
    Call problemsEncountered(wordDoc)
    Call handleA020Security(wordDoc)
    Call fillNewIssues(wordDoc)
    Call deleteSheet
    Call makeA020Folders(wordDoc, releaseName)
    Call thisVersion(versionName, releaseName)
    Call progress(98, "Cleaning Up")
    Set wordDoc = Nothing
    Call pauseTime(2)
    Application.ScreenUpdating = True
    Call progress(100, "A020 Generation Complete")
    Exit Sub
    Call oopsie("makeA020")
End Sub
Updated 13-Apr-20 5:50am

There's nothing to translate! You have to determine what VBA code is doing and you to write it from scratch in c#.

When you get stuck, come back here and ask detailed question.
Share this answer
You should say no. Suggest your supervisor she let you hire someone for the job.
Share this answer
Benjaminj007 13-Apr-20 11:54am    
I see the humor, Bobby, but I feel fortunate to have a job when millions have lost theirs.
There really isn't anything to translate in that code. For the most part, it's a bunch of calls to other functions that do the actual work.
Share this answer
Benjaminj007 13-Apr-20 12:03pm    
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'set sheet names
Set valSheet = Sheets("CTF-Issue Val Tracker")
Set issueAssignments = Sheets("Issue Assignments")
'handle invalid stuff, exit if any are true
If valSheet.Cells(1, "AA").text <> "filled" Or Target.Row = 1 Or ActiveSheet.Name <> "CTF-Issue Val Tracker" Then GoTo exitHandler
'put it where it goes
On Error Resume Next
For Each aCell In Target
changedCell = valSheet.Cells(aCell.Row, aCell.Column).Value
Set tempCell = issueAssignments.Range("H:H").Find(What:=valSheet.Cells(aCell.Row, "A").Value)
If Not tempCell Is Nothing Then
Select Case aCell.Column
Case "9"
'link "Validated?" columns if filled
tempCell.offset(0, 9).Value = changedCell
Case "7"
'link "Tester?" columns if filled
tempCell.offset(0, 3).Value = changedCell
Case "8"
'link "Completed Date" columns if filled
tempCell.offset(0, 6).Value = changedCell
End Select
End If
On Error GoTo 0
'handle exit
Application.EnableEvents = True
Exit Sub
MsgBox Err.Description
Resume exitHandler
End Sub
'Private Sub fillValSheet_Click()
' Call Sheets("Import Sheet").fillValTracker
'End Sub
'Private Sub clearValSheet_Click()
' Call Sheets("Import Sheet").clearValTracker
'End Sub
Dave Kreskowiak 13-Apr-20 12:17pm    
OK, so what's the question? I'm not translating anything for you. It's not possible for you to do my job for me, so...

This comes down to learning both languages, understanding what the original code is doing and writing the equivalent code in C#. There is no shortcut for this, and no service where you can copy'n'paste the code to have it done for you.
Benjaminj007 13-Apr-20 12:23pm    
I'm not asking you to do my work for me, Dave. I have no experience in either language, and time is a factor. I have over twenty pages of code to translate and I don't have a starting point. That's why I'm seeking some assistance with this piece so I can take it from there. No shortcuts. I don't believe asking for help equates to a shortcut or wanting someone to do it for me.
Dave Kreskowiak 13-Apr-20 12:34pm    
A starting point? Creating a C# Windows Forms application or a Console application, depending on your requirements. Add a COM reference to the Microsoft Office xx.xx Object Library. Then it's a matter of understanding the code and writing new code to do the same thing.

If you attempt to do a line-by-line conversion of the original VBA code, you are going to fail very quickly. It will not work.
Benjaminj007 13-Apr-20 12:37pm    
Acknowledged. Thanks for the input. Much appreciated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900