Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Go Back  Xtreme Visual Basic Talk > > > Converting Numbers to Roman Numerals and English written equivalents


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2012, 06:05 PM
01Stepside 01Stepside is offline
Newcomer
 
Join Date: Mar 2012
Posts: 5
Default Converting Numbers to Roman Numerals and English written equivalents


I'm sorry to bother everyone on here, but I really need help. I don't know where else to turn and I've tried everything.

I need to write a program to convert in a textbox a number to its roman numeral and written english equivalent. I can write everything except how to get the program to recognize the numbers and convert it into what I need it to.

This is what I have so far, and I'm not completely sure if this is even right, but I can't figure much else out. I've talked to other people who know about this and they aren't sure how to go about it, and my book isn't a big help either.

I would really appreciate any and all help than anyone could give me. I just don't know what else to do and I've been stuck here for a few days trying to learn how to do this...

Option Strict On

Public Class Form1

Private Sub btnRoman_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoman.Click
If CDbl(txtinput.Text) <= 0 Then
MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
ElseIf CDbl(txtinput.Text) >= 3999 Then
MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
End If
If CDbl(txtinput.Text) = 0 Then
MessageBox.Show("Please enter a number", "Enter a number")
End If


Const I As String = "1"
Const II As String = "2"
Const III As String = "3"
Const IV As String = "4"
Const V As String = "5"
Const VI As String = "6"
Const VII As String = "7"
Const VIII As String = "8"
Const IX As String = "9"
Const X As String = "10"
Const C As String = "100"
Const D As String = "500"
Const M As String = "1000"
End Sub

Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnglish.Click
If CDbl(txtinput.Text) <= 0 Then
MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
ElseIf CDbl(txtinput.Text) >= 3999 Then
MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
End If
If CDbl(txtinput.Text) = 0 Then
MessageBox.Show("Please enter a number", "Enter a number")
End If

Const One As String = "1"
Const Two As String = "2"
Const Three As String = "3"
Const Four As String = "4"
Const Five As String = "5"
Const Six As String = "6"
Const Seven As String = "7"
Const Eight As String = "8"
Const Nine As String = "9"
Const Ten As String = "10"
Const Eleven As String = "11"
Const Twelve As String = "12"
Const Thirteen As String = "13"
Const Fourteen As String = "14"
Const Fifteen As String = "15"
Const Sixteen As String = "16"
Const Seventeen As String = "17"
Const Eighteen As String = "18"
Const Nineteen As String = "19"
Const Twenty As String = "20"
Const Thirty As String = "30"
Const Forty As String = "40"
Const Fifty As String = "50"
Const Sixty As String = "60"
Const Seventy As String = "70"
Const Eighty As String = "80"
Const Ninety As String = "90"
Const One_Hundred As String = "100"
Const Two_Hundred As String = "200"
Const Three_Hundred As String = "300"
Const Four_Hundred As String = "400"
Const Five_Hundred As String = "500"
Const Six_Hundred As String = "600"
Const Seven_Hundred As String = "700"
Const Eight_Hundred As String = "800"
Const Nine_Hundred As String = "900"
Const One_Thousand As String = "1000"
Const Two_thousand As String = "2000"
Const Three_Thousand As String = "3000"
End Sub
End Class
Reply With Quote
  #2  
Old 03-08-2012, 06:10 PM
01Stepside 01Stepside is offline
Newcomer
 
Join Date: Mar 2012
Posts: 5
Default

Just realized I posted in Legacy VB.....
Reply With Quote
  #3  
Old 03-08-2012, 08:00 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Convert numbers to roman numerals VB6 and VB.net example

Quote:
Just realized I posted in Legacy VB...
I'm sure a moderator will be along eventually to move it.

I was all set to give you a VB6 link for converting numbers to roman numerals though:
http://vbnet.mvps.org/index.html?cod...bertoroman.htm

But I'll attach some old working roman convertor demos for VB.Net.

RNC1 is not that great (has some gotos and only calculates to 3999),
but maybe will give you some ideas..

RNC2 is a little cleaner and allows inputting numbers up to 65535, but no textbox validation.

Hopefully they'll give you some ideas..
Attached Files
File Type: zip RNC1.zip (146.2 KB, 17 views)
File Type: zip RNC2.zip (84.1 KB, 22 views)
Reply With Quote
  #4  
Old 03-09-2012, 02:53 AM
01Stepside 01Stepside is offline
Newcomer
 
Join Date: Mar 2012
Posts: 5
Default

Ok, I'm starting to get somwhere, but how can I let it know that if theres 4 numbers then the first digit corresponds to the thousandths place, and 2XXX means two thousand and 2XX means two hundred?
Reply With Quote
  #5  
Old 03-09-2012, 12:25 PM
passel's Avatar
passelConverting Numbers to Roman Numerals and English written equivalents passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Quote:
Originally Posted by 01Stepside View Post
Ok, I'm starting to get somwhere, but how can I let it know that if theres 4 numbers then the first digit corresponds to the thousandths place, and 2XXX means two thousand and 2XX means two hundred?
Use an If statement?

Like,
Code:
If the string length = 4 Then
  the first digit corresponds to thousands
ElseIf the string length = 3 Then
  the first digit corresonds to hundreds
End If

'Or
If  (Number \ 1000) > 0 Then
  The first digit is thousands 
ElseIf (Number \ 100) > 0 Then
  The first digit is hundreds
End If

'Or
If Number >= 1000 Then
  The first digit is thousands
ElseIf Number >= 100 then
  The first digit is hundreds
End If

'Or
'''any number of options....

'i.e.  a Select Case statement

Select Case Int(Log(Number)/Log(10))
  Case 3
    The first digit is thousands
  Case 2
    The first digit is hundreds
End Select
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 03-09-2012 at 12:32 PM.
Reply With Quote
  #6  
Old 03-09-2012, 01:24 PM
01Stepside 01Stepside is offline
Newcomer
 
Join Date: Mar 2012
Posts: 5
Default

This is where I find myself on this now:

I can't figure out how to actually do the converting...
Code:
Option Strict On
Public Class Form1
    Dim lastinput As String
    Dim value As String
    Dim hundred As String
    Dim thousand As String
    Dim ten As String
    Dim place() As String
    Private Sub btnRoman_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoman.Click
        If lastinput = txtinput.Text Then
            MessageBox.Show("Please enter a valid number", "Enter a number")
            Exit Sub
        End If

        If CDbl(txtinput.Text) <= 0 Then
            MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
        ElseIf CDbl(txtinput.Text) >= 3999 Then
            MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")


        End If
        If txtinput.Text = String.Empty Then
            MessageBox.Show("Please enter a number", "Enter a number")
        End If


        Select Case value
            Case Is < CStr(999 = CDbl(hundred))
            Case Is > CStr(999 = CDbl(thousand))
            Case Is < CStr(10 = CDbl(ten))

        End Select

        txtinput.Text = place.ToString

        Select Case place
            Case Is place(0) = thousand 
            Case Is place(1) = hundred
            Case Is place(2) = ten

        End Select



        Dim I As String = "1"
        Dim II As String = "2"
        Dim III As String = "3"
        Dim IV As String = "4"
        Dim V As String = "5"
        Dim VI As String = "6"
        Dim VII As String = "7"
        Dim VIII As String = "8"
        Dim IX As String = "9"
        Dim X As String = "10"
        Dim C As String = "100"
        Dim D As String = "500"
        Dim M As String = "1000"
    End Sub

    Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnglish.Click

        Dim text As String
        text = txtinput.Text.ToUpper
        text = txtinput.Text.Replace(",", "")
        text = txtinput.Text.Replace(" ", "")
        text = txtinput.Text.ToCharArray

        If lastinput = txtinput.Text Then
            MessageBox.Show("Please enter a valid number", "Enter a number")
            Exit Sub
        End If

        If CDbl(txtinput.Text) <= 0 Then
            MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
        ElseIf CDbl(txtinput.Text) >= 3999 Then
            MessageBox.Show("Please enter a whole number between 1 and 3999", " Enter a Valid Number")
        End If

        If txtinput.Text = String.Empty Then
            MessageBox.Show("Please enter a number", "Enter a number")
        End If

        txtinput.Text.ToCharArray()
        Dim One As Integer = 1
        Dim Two As Integer = 2
        Dim Three As Integer = 3
        Dim Four As Integer = 4
        Dim Five As Integer = 5
        Dim Six As Integer = 6
        Dim Seven As Integer = 7
        Dim Eight As Integer = 8
        Dim Nine As Integer = 9
        Dim Ten As Integer = 10
        Dim Eleven As Integer = 11
        Dim Twelve As Integer = 12
        Dim Thirteen As Integer = 13
        Dim Fourteen As Integer = 14
        Dim Fifteen As Integer = 15
        Dim Sixteen As Integer = 16
        Dim Seventeen As Integer = 17
        Dim Eighteen As Integer = 18
        Dim Nineteen As Integer = 19
        Dim Twenty As Integer = 20
        Dim Thirty As Integer = 30
        Dim Forty As Integer = 40
        Dim Fifty As Integer = 50
        Dim Sixty As Integer = 60
        Dim Seventy As Integer = 70
        Dim Eighty As Integer = 80
        Dim Ninety As Integer = 90
        Dim One_Hundred As Integer = 100
        Dim Two_Hundred As Integer = 200
        Dim Three_Hundred As Integer = 300
        Dim Four_Hundred As Integer = 400
        Dim Five_Hundred As Integer = 500
        Dim Six_Hundred As Integer = 600
        Dim Seven_Hundred As Integer = 700
        Dim Eight_Hundred As Integer = 800
        Dim Nine_Hundred As Integer = 900
        Dim One_Thousand As Integer = 1000
        Dim Two_thousand As Integer = 2000
        Dim Three_Thousand As Integer = 3000
    End Sub
End Class
Reply With Quote
  #7  
Old 03-09-2012, 02:14 PM
passel's Avatar
passelConverting Numbers to Roman Numerals and English written equivalents passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Is this for a Class?
Are they suppose to be teaching you how to program?
I don't think I see much of anything that is of any use in that code.

I really can't understand how they expect students to produce a program to accomplish this task without an understanding of how to parse a number or string into parts.
This code looks like a number of disjointed pieces of copied code.
For instance,
If lastinput = txtinput.Text Then ....

Where is lastinput ever set?
Why is it an error condition?

Code:
        Select Case value
            Case Is < CStr(999 = CDbl(hundred))
            Case Is > CStr(999 = CDbl(thousand))
            Case Is < CStr(10 = CDbl(ten))
        End Select
The above code, if the number is less than 1000, will take the first Case so you will never get to the third case where the number is less than 10 (since a number less than 10 is also less than 1000).
You would need to test the values in order, from smaller to greater.

Declaring all those variable with names and values doesn't seem helpful to me.
If you had strings in an array and used numbers to index into the array to translate the number into a string, that might be useful.

I'm afraid you need more help than I can give.
I would suggest looking at the projects that surfR2911 attached, but at your level of experience, I don't know whether that would help, because I don't think you would be able to follow and understand what the code is doing so you could implement something in your own style or method.

{edit}, I had some wrong information here.
Upon further looking at the code surfR2911 posted, I see you are copying bits of it into the code you've posted.
If you don't understand the code you're copying, it really doesn't help you.
I'm sorry I won't be of any help.

{edit 2} Back again. I would suggest, if you are trying to understand the code given, then hopefully you are familiar with debugging in the IDE.
You can set a breakpoint in the code where the number to numeral conversion is being done, and then step executing line by line and examining what values are being compared, what values are being modified, what parsing is going on, etc....
Watching the code execute one statement at a time, and investigating what the related values are and what decisions are being made, and calculations being done, is a very great strength of working with these languages and programming environment, to understand what unfamiliar code is doing, and what your own code is doing compared to what you intended.
Being able to debug is probably on par in importance with being able to program in the first place.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 03-09-2012 at 02:53 PM.
Reply With Quote
  #8  
Old 03-09-2012, 07:39 PM
01Stepside 01Stepside is offline
Newcomer
 
Join Date: Mar 2012
Posts: 5
Default

I looked at all the examples given to me, and I talked to my prof and showed him the code and he told me to keep working on it. I tried to do the best that I could but I have no idea how to get it to work. He never explains anything in class. Its this is what this does, hes a single example, and moving on. What he's asked us to do for this project he never had us ever do anything like in class and thats what my problem is, I really had no idea where to start.

And yes, there are a few pieces of code that are a bit scattered because they are from the examples given to me and the ones I could find. When I tried to run codes that were given to me to try and help me they did nothing but cause me dozens of runtime errors that I had no idea how to fix.

I tried to do some debugging, but the errors it kept giving me didn't make any sense to me at all, and again, everything that I had some faint bit of understanding of was touched on in class one single time and that was it. I really want to know how to do this, I've always wanted to learn how to do programming, but stuff like this and my prof. are starting to turn me away from it.

When I showed my prof. what code I had written so far he didn't really say anything to tell me that it was wrong, but told me to keep working on it, and he pretty much told me what I already knew but did not know how to accomplish.

This is the first time that hes had us write anything with Option Strict On, and I think thats a lot of whats messing me up. I've never worked with it before, and he didn't really explain what the difference is having it turned on or off.

When I looked at the drop box for the project today when I submitted it, I saw that only about half of my class had anything submitted, so I guess I'm not the only one who had serious problems with this...

I submitted the project unfinished and late, I really had no idea how to do this, and the assigned book for the class gives no help either.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
 
Converting Numbers to Roman Numerals and English written equivalents
Converting Numbers to Roman Numerals and English written equivalents
 
-->