Results 1 to 18 of 18

Thread: VB roman calculator basic help - URGENT

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    VB roman calculator basic help - URGENT

    sorry if someone has posted about this before, but i require serious help

    i have desgined a roman calculator, that converts a roman numeral into an arabic number and adds them up, i have two problems however and require help.
    my first problem is that i must have a function that has a value as a parameter, so how do i pass a value through the function, at the moment i have each roman numeral button calling the function up

    also another problem i have is that the roman numerals must ALL be in descending order, not even IV is allowed, i am struggling to do this, i know that the code should check the numeral before and see if it is greater than or equal to, if it were smaller value, then it could bring up a message box, however i have no clue on doing this, also i have very basic programming knowledge

    so could someone pls suggest a piece of code to do this, it must not have any complicated variables, as the only statements i know are select case, if , do while, for- next, mod, div, Len() and MID, so pls only use those statements

    * I have uploaded my file for you to view(zip)*, as you can see it is very basic compared to the kind of variables i have seen posted in other examples of code.
    Attached Files Attached Files

  2. #2
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: VB roman calculator basic help - URGENT

    The file has nothing inside pal. Try re-attach it again.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    The excel file is blank but you must go to VB Editor (Alt + F11 while in Excel).

  4. #4
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: VB roman calculator basic help - URGENT

    can you simplify the explaination of your problem. I cannot figure it out. Why you need a function and what does the function do?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    i have a function but i do not understand how to pass a value in the functions parameter?

    second problem is how to make sure roman numerals can only be written in DESCENDING order, this could be done by checking the value of the last roman numeral, but i am unsure how to do that

    hope i have cleared the explanation up, was the file working?

  6. #6
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: VB roman calculator basic help - URGENT

    I just can give you some example to pass a value to a functions parameters. You could try it out once you know the idea. I don't really understand how your programs work since you didn't put any comment in your code. For the second problem, I have no idea how to sort roman numeral. If you set each of your Roman numeral into arrays or listbox this might be posible to sort. Sorry pal, I try hard to help but solution is hard to come


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Call sumUp(Text2, Text3) 'Pass the value from text1 and text2 into sumUp parameters
    5. End Sub
    6.  
    7. Private Function sumUp(ByVal firstNum As Integer, ByVal secNum As Integer)
    8.     Text1 = firstNum + secNum 'The operation in the sumUp function
    9. End Function
    10.  
    11. Private Sub Form_Load()
    12. 'Set the value into text1 and text2
    13. Text2 = 30
    14. Text3 = 40
    15. End Sub

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    thanks for the code help, i understand it is difficult to come up with code

  8. #8
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: VB roman calculator basic help - URGENT

    You know I like to learn like you pal but I'm not an expert. VB is exciting Anyway, I'll study your program. So please keep on check this thread. By the way, why you use excel rather than vb6?
    Last edited by Bearnerd; Apr 22nd, 2006 at 02:37 PM.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    i am only a basic programmer, so i do not need vb6

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: VB roman calculator basic help - URGENT

    kazoo, are you talking about the numerals having to be in alphabetical order? Like CCDIILMVX? If so, do a search on string sort - there have been quite a few string sort routines posted.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: VB roman calculator basic help - URGENT

    Quote Originally Posted by kazoo
    i am only a basic programmer, so i do not need vb6
    Programming is one thing, learning a computer language is another.

    Excel is a spreadsheet program. If you want to learn programming, and you don't want to learn it the correct way (which you evidently don't - you shouldn't be writing code before you've even learned simple sorts), at least learn it with a programming language. VBA isn't a language, it's a dialect - you'll have to unlearn a lot if you want to do any real programming after you've learned VBA.

    If you want to learn programming - as opposed to learning how to make programs in Excel - get a copy of Wirth's _Algorithms + Data Structures = Programs_ and study it. If you don't know algorithms and data structures you aren't really programming.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    no not in alphabetical order, in descending order of value which would be MDCLXVI
    is there a way to tell if the last chracter is less than or greater than the next character it is confusing, anyway thanks for explanation about programming, i think i have found out programming is not for me, and will not continue with it in the future.

  13. #13
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: VB roman calculator basic help - URGENT

    VB Code:
    1. Private Const SKEY As String = "MDCLXVI"
    2. Private Const KEYLEN As Integer = 7
    3.  
    4. Private Function checkprecedence(ByRef spinput As String) As Boolean
    5. Dim ilen As Integer
    6. Dim i As Integer, j As Integer, k As Integer
    7.  
    8. ilen = Len(spinput)
    9. For i = 1 To ilen - 1
    10.   j = getindex(Mid$(spinput, i, 1))
    11.   If j = 0 Then  'getindex returns 0 if the input string contains invalid characters
    12.     checkprecedence = False
    13.     Exit Function
    14.   End If
    15.   k = getindex(Mid$(spinput, i + 1, 1))
    16.  
    17.   If k = 0 Then  'getindex returns 0 if the input string contains invalid characters
    18.     checkprecedence = False
    19.     Exit Function
    20.   End If
    21.  
    22.   If j > k Then
    23.     checkprecedence = False
    24.     Exit Function
    25.   End If
    26. Next i
    27.  
    28. checkprecedence = True
    29.  
    30. End Function
    31. Private Function getindex(ByRef spinput As String) As Integer
    32. Dim i As Integer
    33. For i = 1 To KEYLEN
    34.   If spinput = Mid$(SKEY, i, 1) Then
    35.     getindex = i
    36.     Exit Function
    37.   End If
    38. Next i
    39. getindex = 0
    40. End Function
    You have to call the checkprecedence function with the string you want to check. It will return true if the string is in order otherwise false.

  14. #14
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: VB roman calculator basic help - URGENT

    Hi Kazoo! I've studied your coding and modified just a bit to make the program running completely. But for the sorting Roman alphabet I tried many times to make the needed code but I finally gave up. Hope you like your program now. I'm still looking for the solution on how to sort the Roman alphabet. If I found the answer I'll post it to you. If you know how to apply SRISA's code above, just try maybe it will help a lot. Good Luck then
    Attached Files Attached Files
    Last edited by Bearnerd; Apr 25th, 2006 at 05:52 AM.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    thank you very much for the program code and trying to help, it works well, but i have already reached the next part (converting arabic to roman equivalent), however i am having just one bit of trouble with the DIV operator, when you write :

    random value = mynumber div 1000

    it will appear with a error msgbox saying something like expected end of statement or line, why is that happening?

    thank you SRISA for your help and time you spent on the code, however its a bit too hard for my basic knowledge to understand, i would be grateful if you could help on the DIV problem.
    Last edited by kazoo; Apr 26th, 2006 at 01:24 PM.

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB roman calculator basic help - URGENT

    After reading through almost the entire thread, it turns out this is an Excel VBA question.

    Moved to Office Development

  17. #17
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: VB roman calculator basic help - URGENT

    As far as I know vb does not have the operator div. If you want to perform integer division, this is what you need : random value = mynumber \ 1000

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    18

    Re: VB roman calculator basic help - URGENT

    i understand now, i think div just symbolises the divide sign, thanks for your help everyone.

Posting Permissions

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



Click Here to Expand Forum to Full Width