+ Reply to Thread
Results 1 to 3 of 3

Is an array the solution?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    Is an array the solution?

    Hi all

    Last week I have made my first function. It works fine but needs fine tuning.

    My code looks like:
     Function SchaatsSeizoen(Time As Variant, Distance As Variant) As Variant
    
            Dim Minutes As Variant
            Dim Seconds As Variant
            Dim Hundredths As Variant
    
    '   When adding times, the character that divides Minutes from Seconds and Second from 1/100 can
    '   be e.g. , . : or any other character.
    '   To prevent error messages from happening, can these characters be captured in eg an array?
    '   like    Dim myarray As Variant
    '       myarray = Array(",", ".", ":")
    '   then the line where the layout is detemined would be eg  "#" & myArray & "##" & myArray & "##"
    
        If Time.Value Like "##" Then
            Minutes = 0
            Seconds = Time
            Hundredths = 0
            
            Call TimeToPoints(Minutes, Seconds, Hundredths, Distance)
            SchaatsSeizoen = Round(Left(TimeToPoints(Minutes, Seconds, Hundredths, Distance), 6), 3)
            
        ElseIf Time.Value Like "#.##.##" Then
            Minutes = 0
            Seconds = Left(Time, 2)
            Hundredths = Right(Time, 1) * 10        ' multiplied with 10 since this time is in 1/10, and not in 1/100
            
            Call TimeToPoints(Minutes, Seconds, Hundredths, Distance)
            SchaatsSeizoen = Round(Left(TimeToPoints(Minutes, Seconds, Hundredths, Distance), 6), 3)
    Basically my question is in this code.

    Is the solution I am thinking of is making any sense, or is there a different, better to get to what I want?

    Thanks in advance

    Hein

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Is an array the solution?

    this

    Call TimeToPoints(Minutes, Seconds, Hundredths, Distance)
            SchaatsSeizoen = Round(Left(TimeToPoints(Minutes, Seconds, Hundredths, Distance), 6), 3)
    seems common to all, so you don't need to do it in the if block, you can move it outside.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,107

    Re: Is an array the solution?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Never use Merged Cells in Excel

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1