vbaquine

The missing quines: Visual Basic (for Applications)


Today I surfed some random geek-stuff articles on wikipedia to get my daily dose of useless knowledge. I stumbled accross quines, which are programs that print their own source-code. I found that a great way to make my brain hurt, so I began working on a quine in VBA. I had two good reasons:

  1. I couldn't find a quine written in VBA
  2. VBA encourages you to write awkward code which makes your brain hurt

Here is my masterpiece:

Sub q()
c = "Sub q();c = #;Debug.Print Replace(Replace(c, Chr(59), vbNewLine), Chr(35), Chr(34) & c & Chr(34));End Sub"
Debug.Print Replace(Replace(c, Chr(59), vbNewLine), Chr(35), Chr(34) & c & Chr(34))
End Sub

My challenge: Can you make it even shorter (and preferably more awkward)?


Solution

  • I don't know if anybody reads this thread anomore but here's an even shorter one, based on the quine of das_weezul. It's independent of "Option Explicit" (unlike das_weezul's) and it's independent of the Office App you are working in (i.e. Excel, Access, Word etc.) - unlike Alex K's. Use it in the immediate window (Ctrl+G):

    c="c=#:?replace(c,chr(35),chr(34) &c &chr(34))":?replace(c,chr(35),chr(34) &c &chr(34))