Click here to Skip to main content
15,887,477 members
Home / Discussions / Algorithms
   

Algorithms

 
SuggestionRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
Richard MacCutchan5-Jan-16 21:31
mveRichard MacCutchan5-Jan-16 21:31 
AnswerRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. PinPopular
harold aptroot6-Jan-16 0:06
harold aptroot6-Jan-16 0:06 
GeneralRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
Member 113286206-Jan-16 1:33
Member 113286206-Jan-16 1:33 
GeneralRe: I want find intersection point between two ellipse or ellipse and circle, can someone please give me useful links or any suggestions. Pin
harold aptroot8-Jan-16 3:38
harold aptroot8-Jan-16 3:38 
QuestionProbability Pin
Member 122449725-Jan-16 0:18
Member 122449725-Jan-16 0:18 
AnswerRe: Probability Pin
Daniel Pfeffer5-Jan-16 0:30
professionalDaniel Pfeffer5-Jan-16 0:30 
AnswerRe: Probability Pin
Afzaal Ahmad Zeeshan5-Jan-16 0:39
professionalAfzaal Ahmad Zeeshan5-Jan-16 0:39 
QuestionConverting From Decimal to Custom Counting Definition Pin
BlueIshDan24-Dec-15 3:45
BlueIshDan24-Dec-15 3:45 
Hello There,

Please keep in mind that I am not the brightest person in the bunch, that is why I am here asking for help. Because of my lack of education in math, I've been kind of creating my own solutions =/

This code is written in Microsoft Visual Basic for Applications (VBA) 7.0 and used in a Microsoft Access 2010 application.

Sometime in the past year, I created a function that converted non-decimal based string values. Like HEX "0123456789ABCDEF" and/or any other numbering definition you can think of.

I have recently come across another application that requires a custom format of numbering. Bringing me to revise the old function with the new, containing a formula that I wrote out.

The Revised function:

Code:
VB
'---------------------------------------------------------------------------------------------------'
'|
'| Date Created: Feb, 27 2015
'| BY: Daniel Couillard
'| Written In: Microsoft Visual Basic for Applications (VBA) 7.0
'|
'| Revisions:
'|
'| Date Revised: Dec, 21 2015
'| BY: Daniel Couillard
'| Revision:
'|  - Created Mathmatical formula to shorten code.
'|  - Re-commented with respect to the changes.
'|
'| .-------------------------------------.
'| | Function  -  ConvertStringToDecimal |
'| `-------------------------------------`
'|
'|  PARAMETERS:
'|
'|       * str - Contains the value to be converted to decimal.
'|
'|       * def - Contains the definition that describes the value's
'|               format.
'|
'|               For example, HEX's definition would be: "0123456789ABCDEF"
'|
'|  RETURN:
'|
'|      * variant - _
'|
'|          The return value is a variant because it can contain one of the two following results:
'|
'|              1. (STRING) Error Message.
'|              2. (DECIMAL) Calculated Value.
'|                 We use the Decimal data type because of its abillity to store such a large number.
'|
'|
'|  NOTE:
'|
'|      FURTHER EXPLAINATION CAN BE FOUND WITHIN THE FUNCTION
'|
'---------------------------------------------------------------------------------------------------'


Public Function ConvertStringToDecimal(ByVal str As String, _
                                       ByVal def As String) As Variant


    ' ------------------------------------- '
    '           Prep Parameters.            '
    ' ------------------------------------- '
    str = Trim(str & vbNullString)
    def = Trim(def & vbNullString)
    ' ------------------------------------- '

    ' ------------------------------------- '
    '           Parse Parameters.           '
    ' ------------------------------------- '
    If Len(str) = 0 Then: ConvertStringToDecimal = "No value has been entered.": Exit Function
    If Len(def) < 2 Then: ConvertStringToDecimal = "Number definition must have 2 or more characters.": Exit Function
    ' ------------------------------------- '

    ' ------------------------------------- '
    ' Variable Declaration & Initialization '
    ' ------------------------------------- '
    Dim LD As Integer: LD = Len(def)        ' - Length of Definition
    Dim LV As Integer: LV = Len(str)        ' - Length of Value
    Dim N As Variant: N = CDec(0)           ' - The sum of the calculations.
    Dim I As Integer                        ' - Increment.
    Dim P As Integer                        ' - Position of Value[i] in Reverse Definition.
    ' ------------------------------------- '

    ' Reverse string for correct digit position calculation allows for
    ' minimization in calculations when traversing through string position
    ' & Or simplifies visualiztion of the code for the reader.
    str = ReverseString(str)

    ' Traverse through the characters(digits) of the string in
    ' an incremental order.
    For I = 1 To LV

        P = InStr(1, def, Mid(str, I, 1))

        If P > 0 Then: N = N + CDec((P - 1) * (LD ^ (I - 1)))

    Next

    ' Return the calculated value.
    ConvertStringToDecimal = N


End Function

What I would like to request your help with is the design of a Convert decimal to number definition function. I have a working one, but I can't seem to figure out if it is the most effective way to go about doing it.

This function will retrieves a decimal based number and converts it to a definition string:

number: "12345"
def: (hex) "0123456789ABCDEF"
or (binary) "01"
or (custom) "!@#$%^&*()1234567890ABCDEFGHIJKLMNOP"

I'm not satisfied with the way that I went about figuring out my starting point.

Here she is:

Code:
VB
Public Function ConvertNumberToDefinition(ByVal number As String, _
                                          ByVal def As String) As String
    
    Dim length_of_def As Integer: length_of_def = Len(def)
    Dim dec_number As Variant: dec_number = CDec(number)
    
    Dim I As Variant: I = CDec(0)
    Dim j As Variant: j = CDec(0)
    
    Dim val As String
    Dim temp As Variant: temp = CDec(0)
    Dim index_value As Variant: index_value = CDec(0)
    
    For I = 0 To dec_number
        
        If (length_of_def ^ I > dec_number) Then
            
            For j = I - 1 To 0 Step -1
                
                index_value = length_of_def ^ j
                
                temp = dec_number Mod index_value
                
                val = val & Mid(def, ((dec_number - temp) / index_value) + 1, 1)
                
                dec_number = temp
                
            Next
            
            Exit For
        End If
        
    Next
    
    ConvertNumberToDefinition = val
    
End Function

Thanks,
Dan
AnswerRe: Converting From Decimal to Custom Counting Definition Pin
Patrice T24-Dec-15 5:44
mvePatrice T24-Dec-15 5:44 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
Patrice T24-Dec-15 5:57
mvePatrice T24-Dec-15 5:57 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
BlueIshDan24-Dec-15 5:59
BlueIshDan24-Dec-15 5:59 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
BlueIshDan24-Dec-15 6:02
BlueIshDan24-Dec-15 6:02 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
Patrice T24-Dec-15 6:09
mvePatrice T24-Dec-15 6:09 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
Patrice T24-Dec-15 13:51
mvePatrice T24-Dec-15 13:51 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
BlueIshDan29-Dec-15 0:21
BlueIshDan29-Dec-15 0:21 
GeneralRe: Converting From Decimal to Custom Counting Definition Pin
Patrice T29-Dec-15 2:45
mvePatrice T29-Dec-15 2:45 
Questionwhat kind of algorithms we use to find minimum spanning tree Pin
Member 1211381321-Dec-15 5:39
Member 1211381321-Dec-15 5:39 
AnswerRe: what kind of algorithms we use to find minimum spanning tree Pin
Chris Losinger21-Dec-15 6:31
professionalChris Losinger21-Dec-15 6:31 
GeneralRe: what kind of algorithms we use to find minimum spanning tree Pin
harold aptroot21-Dec-15 6:57
harold aptroot21-Dec-15 6:57 
GeneralRe: what kind of algorithms we use to find minimum spanning tree Pin
Patrice T21-Dec-15 12:16
mvePatrice T21-Dec-15 12:16 
QuestionHow do I fix blinking or flashing web page in Chrome? (my project ASP.NET) Pin
ahasan nahid9-Dec-15 14:26
ahasan nahid9-Dec-15 14:26 
AnswerRe: How do I fix blinking or flashing web page in Chrome? (my project ASP.NET) Pin
Richard MacCutchan9-Dec-15 22:22
mveRichard MacCutchan9-Dec-15 22:22 
QuestionAlgorithm running time Pin
Lyuboslav Kakanakov4-Dec-15 5:13
Lyuboslav Kakanakov4-Dec-15 5:13 
AnswerRe: Algorithm running time Pin
Richard MacCutchan4-Dec-15 6:49
mveRichard MacCutchan4-Dec-15 6:49 
AnswerRe: Algorithm running time Pin
Patrice T4-Dec-15 10:17
mvePatrice T4-Dec-15 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.