What is the error on my code...-VBForums
Results 1 to 9 of 9

Thread: What is the error on my code...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    210

    What is the error on my code...

    Dear all,
    I have a special code today. I could not find the optimization for this code. Thought for a long time but before new year try to mix the recipe with you. One step closer for this deployment. Simon says that it would be nice. Waiting for response inside our community. The preparation of code was described at our basic manual at page 156. Any suggestion would be much appreciated.
    Code:
    Option Explicit On
    Option Infer On
    Imports VB6 = Microsoft.VisualBasic
    
    Module Module1
    
        Public Function Main() As Integer
            On Error GoTo ErrorHandler
            Dim retcode As Integer = 0
            Dim d As Date = Date.Parse("01.01.2017")
            Dim dd As New Dictionary(Of Date, Double)
            Dim r As New Random
            Dim a As Double = Nothing
    
            For i As Integer = 0 To DateDiff(DateInterval.Day, DateSerial(2017, 1, 1), DateSerial(2017 + 4 + 4, 1, 1))
                d = d.Add(TimeSpan.FromDays(1))
                a = Math.Sin(i * Math.Atan(1) * 4 / 180)
                Console.WriteLine("{0}::{1}", d.ToString, a)
                If d.Day = 13 And d.DayOfWeek = DayOfWeek.Friday Then
                    dd.Add(d, a)
                End If
                If d.Year > 2017 + 4 + 4 Then
                    Exit For
                End If
            Next
            Console.WriteLine("...___...")
    
            For Each dda As KeyValuePair(Of Date, Double) In dd
                Console.WriteLine("{0}::{1}", dda.Key.ToString, dda.Value.ToString)
                If r.Next(2017, 2024) = dda.Key.Year Then
                    retcode = PerformOperation()
                    If retcode = 1 Then Err.Raise(1)
                    GoTo Terminate
                End If
            Next
    
            GoTo Terminate
    ErrorHandler:
            Console.WriteLine("Critical error {0}", Err.Number)
            Err.Clear()
    Terminate:
            Console.ReadKey()
            Return retcode
        End Function
    
        Private Function PerformOperation() As Integer
            Dim retcode As Integer = 0
            Dim L As New System.Text.StringBuilder
            L.AppendLine("Turkey")
            L.AppendLine("Red Hot Chillipaper")
            L.AppendLine("Sauce")
            Try
                Console.WriteLine("Thanksgiving Day EOS:")
                Console.WriteLine(L.ToString)
            Catch ex As Exception
                retcode = 1
            End Try
            Return retcode
        End Function
    
    End Module

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,333

    Re: What is the error on my code...

    I'm not sure what you are asking for. You ask about the error in the code, but then suggest that you are looking for a way to optimize the code. So, what is it you are looking for? There are certainly ways to improve the code, such as getting rid of that On Error statement, and nobody likes to see GOTO in code, but those are just details. You use Try...Catch in that snippet, so there's no reason for the On Error, since Try...Catch replaces it, and the GOTO can be replaced with a simple Exit For (once you clean up the error handling).
    My usual boring signature: Nothing

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,580

    Re: What is the error on my code...

    Ok....so what's wrong with the code?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,287

    Re: What is the error on my code...

    This is "special code" all right. If you're paying money for this class, get a refund? No one writes code like this in 2017, and very few people wrote it like that in 2003.

    The link auto-downloaded a .rar file. No one outside the file sharing community uses .rar, because for small files the 10-15 bytes it might save are irrelevant compared to "everyone can open a .zip file".

    Both of those are a lot meaner than I usually like to say, but the way I want to "optimize" this is to rewrite it. But I don't want to download 7-zip just to open a single .rar and skim through 150 pages of a bad manual. If your intent is to write VB6, please stop using VB .NET and ask questions in the VB6 forum. If your intent is to use VB .NET, you need to find a course that teaches VB .NET.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,394

    Re: What is the error on my code...

    It's worth noting that you're asking us how to optimise code without even describing what the code is supposed to do. A good rule to live by when posting on forums is to provide ALL the relevant information you can because the easier you make it for us to help you, the more likely you are to get the help you want. If we have start by trying to work out things that you already and could have told us then it starts to seem like we're putting in more effort than you are. I agree with Sitten Spynne that it's very hard to suggest a way to improve that code without suggesting that large parts of it simply be removed altogether and rewritten. If someone shows me there new house and it's upside down and inside out, I'm not going to start by suggesting that they paint the kitchen a different colour.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    210

    Re: What is the error on my code...

    Dear all donít punish me that I am using rar compression this is my conventional routine coming from past. But this code looks nice I remembered a film Nightmare before the Christmas good song of my love. I am supporting our family please donít quarrel with me just please. All we informed and with Luminance

  7. #7
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    839

    Re: What is the error on my code...

    Hi,

    what error, what 'rar compression' bit do you mean
    I can't see a purpose of the Code at all ? what do you do with it ?

    might help if you tell us what you want to accomplish

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,394

    Re: What is the error on my code...

    Quote Originally Posted by algea View Post
    Dear all don’t punish me that I am using rar compression this is my conventional routine coming from past. But this code looks nice I remembered a film Nightmare before the Christmas good song of my love. I am supporting our family please don’t quarrel with me just please. All we informed and with Luminance
    Noone is punishing you. I suggest that you learn the difference between punishment and criticism. You're asking us to volunteer our time to help you, a total stranger. Do we not have the right to expect you to make what effort you can to make that as easy as possible for us? You've been told how you can do that. The choice is now yours as to whether you'd rather play the put upon victim or make that effort to help us help you. I'm guessing that the second option is the more likely to result in your getting the help you want.
    Last edited by jmcilhinney; Dec 27th, 2017 at 10:31 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    210

    Re: What is the error on my code...

    Dear all
    I was thinking about my code for a long time. Then I realized that It was just related with Imports System.Globalization
    After adding simple line into my code now my code is running very native and fast. Thanks to all. Happy new years
    Code:
    My.Application.ChangeCulture("en-US")
    Regards
    algea

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.