Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The missing quines: Visual Basic (for Applications)

Tags:

vba

quine

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)?

like image 407
das_weezul Avatar asked Apr 21 '11 13:04

das_weezul


1 Answers

How about

Sub q() '//in mdl1
Debug.Print Workbooks(1).VBProject.VBComponents(5).CodeModule.Lines(1, 3)
End Sub
like image 67
Alex K. Avatar answered Sep 20 '22 20:09

Alex K.