Coin Operated Machine RRS feed

  • Question

  • Hi I want to make a coin operated printer using VB. The task is VB language will detect the pages of documents if it says 5 pages it will prompt please insert 5 coins if it inserted it will now print the pages.
    Friday, November 30, 2018 2:41 PM

All replies

  • Hi

    I tried to find the coin slot on my PC, but I failed! Where is the coin slot on your PC?

    Regards Les, Livingston, Scotland

    Friday, November 30, 2018 3:24 PM
  • Detecting page count should be the first thing which will differ dependent on document type.

    For instance, for Office documents e.g. word, excel, power point you would use automation, OpenXML or third party library similarly with a PDF.

    Of course the hard way would be to understand document structures and use that to get page counts e.g. for a PDF we can use the following.

    Public Function GetNoOfPagesPDF(ByVal FileName As String) As Integer
        Dim Result As Integer = 0
        Dim fs As New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)
        Dim ReadStream As New IO.StreamReader(fs)
        Dim Contents As String = ReadStream.ReadToEnd()
        Dim regx As System.Text.RegularExpressions.Regex = _
           New System.Text.RegularExpressions.Regex("/Type\s*/Page[^s]")
        Dim matches As System.Text.RegularExpressions.MatchCollection = regx.Matches(Contents)
        Result = matches.Count
        Return Result
    End Function
    Once you have the above done it's plaim math from there.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, November 30, 2018 5:10 PM