[Help] Stuck on Program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [Help] Stuck on Program

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    [Help] Stuck on Program

    I have encountered a block in my programming escapade. The project that I am working on is from a visual basic 6.0 programming book and is a program that opens a data file filled with roman numerals, read to end of file, and outputs the numerals digit form, performs a mathematical operator on them, and then display output. I am also employing the use of subfunctions/subroutines to better organize my program. Below are my subs.

    ReadRoman - Reads a string which represents a Roman Number, calls GetDigit to convert this Roman Digit into a decimal number, adds this decimal number to the value of the roman number.

    GetDigit = Takes a roman digit and returns the decimal value to the caller.

    Calculate - Takes the decimal equivalent of both Roman numbers and the operator and computes their combined result. Uses WriteRoman to display the last line of output.

    WriteRoman - Takes a decimal number and converts it into a Roman Nubmer. Calls Writedigit in order to accomplish the above.

    WriteDigit - Print a Roman Digit

    To better explain it, I have included the data file as well as a little preview of what I would like to output.

    Output

    The First Numer is 1226
    The second number is 68
    The Operation is +
    MCCXXVI + LXVIII = MCCLXXXXIIII (1294)

    The DAT file is organized as seen below.Attachment 104365

    (Start of File)

    MCCXXVI
    LXVIII
    +
    MCCXXVI
    LXVIII
    -
    MCCXXVI
    XVII
    *
    DCI
    L
    MDCIIII
    L
    *
    CCCC
    XXXX
    -

    (End of File)

    Here is the code that I have so far. (I apologize for pastebin link, had trouble attempting to embed into this post)

    http://pastebin.com/NtV4tbzZ

    Code:
    Dim numerals As String
    Private Function ReadRoman()
    End Function
    Private Function GetDigit(ByVal Num As String) As Integer
     Select Case Num
        Case "I"
            GetDigit = 1
        Case "V"
            GetDigit = 5
        Case "X"
            GetDigit = 10
        Case "L"
            GetDigit = 50
        Case "C"
            GetDigit = 100
        Case "D"
            GetDigit = 500
        Case "M"
            GetDigit = 1000
    End Select
    End Function
    
    Private Function WriteRoman()
    Call WriteDigit
    output.Print Number
    End Function
    Private Function WriteDigit()
    output.Print numerals
    End Function
    
    Private Sub calculate_Click()
    Input #1, numerals
    For i = 1 To Len(numerals)
    End Sub
    
    Private Sub Form_Load()
    'open file
    Open App.Path & "\numerals.dat" For Input As #1
    'Do While Not EOF(1)
    End Sub
    Thank you for your time, and I apologize for any grammatical errors and lack of programming experience.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,998

    Re: [Help] Stuck on Program

    We don't do homework here. Google that, and you'll find many samples. Don't hand them in, though.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    Re: [Help] Stuck on Program

    It is unfortunately a tad more difficult than that. The problem you have now is that you have to literally check each character on input to determine some sort of macth to your Roman numerals. You would have to put the roman numerals inside arrays then loop through them. As in the attached example.

    I did not make this app, so I cannot and will not take credit for it. If you were to search on CG you will find it
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center