Results 1 to 5 of 5

Thread: why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can impleme

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,958

    why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can impleme

    C , Python, Java, 50 lines of code.
    Why can't Microsoft and Oracle make it simpler, but high-level languages are as hard to understand as assembly?

    Implement similar event class functionality. What other programming language has a smaller amount of code, closer to the simplicity of VB6? Programmers are just like consumers, just like VB6. By adding byval and byref to the parameters, they can know whether the data can be modified and returned or read-only. In one sentence, but Java uses 30 lines of code. The VB6 language was already the most convenient in the world 30 years ago, and it should be called the most advanced and simplest programming language.

    Python demo
    Code:
    1. class WebSendEventArgs:
    2.     def __init__(self, data):
    3.         self.data = data
    
    5. class WebSender:
    6.     def __init__(self):
    7.         self.listeners = []
    
    9.     def add_listener(self, listener):
    10.         self.listeners.append(listener)
    
    12.     def remove_listener(self, listener):
    13.         self.listeners.remove(listener)
    
    15.     def send_data(self, initial_data):
    16.         event_args = WebSendEventArgs(initial_data)
    17.         for listener in self.listeners:
    18.             listener(event_args)
    19.         print(f"Modified data: {event_args.data}")
    
    21. # Simulate event handling function
    22. def handle_web_send(event_args):
    23.     event_args.data = f"Modified {event_args.data}"
    
    25. if __name__ == "__main__":
    26.     sender = WebSender()
    27.     sender.add_listener(handle_web_send)
    28.     sender.send_data("Initial data")
     
     
    The total number of non - blank lines of code is 24.
    Last edited by xiaoyao; Jan 11th, 2025 at 04:38 PM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,958

    Re: why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can imp

    c# code
    Code:
    csharp
      
    // Represents the event arguments for the WebSend event.
    public class WebSendEventArgs : EventArgs
    {
        // The data that can be modified during the event.
        public string Data { get; set; }
    
        // Constructor to initialize the data.
        public WebSendEventArgs(string data)
        {
            Data = data;
        }
    }
    
    // The class that raises the WebSend event.
    public class WebSender
    {
        // Declare the WebSend event.
        public event EventHandler<WebSendEventArgs> WebSend;
    
        // Method to trigger the WebSend event with initial data.
        public void SendData(string initialData)
        {
            var args = new WebSendEventArgs(initialData);
            OnWebSend(args);
            Console.WriteLine($"The modified data: {args.Data}");
        }
    
        // Protected virtual method to raise the WebSend event.
        protected virtual void OnWebSend(WebSendEventArgs e)
        {
            WebSend?.Invoke(this, e);
        }
    }
    
    class Program
    {
        static void Main()
        {
            var sender = new WebSender();
            // Subscribe to the WebSend event.
            sender.WebSend += (senderObj, e) =>
            {
                e.Data = $"Modified {e.Data}";
            };
            sender.SendData("Initial data");
        }
    }
     
     
    In this code:
     
     WebSendEventArgs  class is designed to hold the data passed with the  WebSend  event. The  Data  property is set to be writable, allowing the event handlers to modify it.
     WebSender  class contains the  WebSend  event. The  SendData  method creates an instance of  WebSendEventArgs  with the initial data, triggers the event, and then prints the modified data.
    In the  Main  method, an instance of  WebSender  is created. An event handler is attached to the  WebSend  event. This event handler modifies the  Data  property of the  WebSendEventArgs . Finally, the  SendData  method is called to trigger the event.
    java
    Code:
    java
      
    // Represents the event arguments for the WebSend event
    class WebSendEventArgs extends java.util.EventObject {
        private String data;
    
        // Constructor to initialize the event arguments with data
        public WebSendEventArgs(Object source, String data) {
            super(source);
            this.data = data;
        }
    
        // Getter method to retrieve the data
        public String getData() {
            return data;
        }
    
        // Setter method to modify the data
        public void setData(String data) {
            this.data = data;
        }
    }
    
    // The class that fires the WebSend event
    class WebSender {
        private java.util.ArrayList<WebSendListener> listeners = new java.util.ArrayList<>();
    
        // Method to add a listener to the WebSend event
        public void addWebSendListener(WebSendListener listener) {
            listeners.add(listener);
        }
    
        // Method to remove a listener from the WebSend event
        public void removeWebSendListener(WebSendListener listener) {
            listeners.remove(listener);
        }
    
        // Method to send data and trigger the WebSend event
        public void sendData(String initialData) {
            WebSendEventArgs event = new WebSendEventArgs(this, initialData);
            for (WebSendListener listener : listeners) {
                listener.onWebSend(event);
            }
            System.out.println("The modified data: " + event.getData());
        }
    }
    
    // The listener interface for the WebSend event
    interface WebSendListener extends java.util.EventListener {
        void onWebSend(WebSendEventArgs event);
    }
    
    public class Main {
        public static void main(String[] args) {
            WebSender sender = new WebSender();
            sender.addWebSendListener(event -> {
                event.setData("Modified " + event.getData());
            });
            sender.sendData("Initial data");
        }
    }
     
     
    In this code:
     
     WebSendEventArgs  class extends  java.util.EventObject  and holds the data which can be modified during the event handling. It has  getData  and  setData  methods for accessing and modifying the data.
     WebSender  class manages the list of  WebSendListener s. The  sendData  method creates an instance of  WebSendEventArgs  with the initial data, triggers the event for each listener, and then prints the modified data.
     WebSendListener  is an interface that defines the method  onWebSend  which will be called when the event is fired.
    In the  main  method of the  Main  class, a  WebSender  instance is created. A listener is added to the  WebSender  which modifies the data in the  WebSendEventArgs  during the event handling. Then the  sendData  method is called to trigger the event.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,958

    Re: why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can imp

    Python:
    Python can simulate similar functionality through functions and mutable objects, and the code is relatively concise. Although Python doesn't have a native event system like VB6, a similar effect can be achieved through a simple callback function mechanism.

    def web_send(data, callback):
    new_data = data.copy() if isinstance(data, (list, dict)) else data
    callback(new_data)
    return new_data


    def modify_data(data):
    if isinstance(data, str):
    data = "Modified " + data


    initial_data = "Initial data"
    result = web_send(initial_data, modify_data)
    print(result)


    Here, by passing a callback function modify_data to simulate the modification of data, the web_send function is similar to the role of event triggering, and the overall code is small and concise.

    JavaScript:
    JavaScript can also achieve similar functionality in a concise way. Like Python, it is based on the function and callback mechanism.

    function webSend(data, callback) {
    let newData = Array.isArray(data)? [...data] : typeof data === 'object'? {...data } : data;
    callback(newData);
    return newData;
    }


    function modifyData(data) {
    if (typeof data ==='string') {
    data = "Modified " + data;
    }
    }


    let initialData = "Initial data";
    let result = webSend(initialData, modifyData);
    console.log(result);


    Similarly, by passing the callback function modifyData to process the data, the webSend function simulates the event - triggering logic, and the code is simple and clear.

    Although VB6 has a concise syntax in specific scenarios, modern programming languages have more comprehensive considerations in terms of functionality, performance, and maintainability. The superiority of a language cannot be simply measured by the number of code lines. Each language has its applicable scenarios and advantages.


    Perhaps the article is longer, do not know the program of vb programmer s not everyone installed a few ai software.

    For example, does Google Chrome have its own translation function to open English pages and automatically convert them into your country's language?

    I feel that some of the current translation of the programming code is not perfect, so there are many translation errors. However, it does not affect the normal viewing principle and learning.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    4,958

    Re: why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can imp

    The number of VB6 programmers was 10 times that of VC + +.Is the best programming language in the world.
    Beat Delphi, C + + builder, PowerBuilder
    In the end, it was defeated by C # VB. Net.

    c#In fact, it is also a failed product. Imitating Java has caused Microsoft to completely forget that it used to be No.1 in the industry, and now it is No.10.
    In the end, Python beat C# , VB. Net.

    Maybe 99% of the programs are not used.office access,Use the form inside to realize the ERP management system or the inventory management system. Factory management, school management.

    like visual foxpro,The product has even been upgraded to around 2010. Finally, it was completely abandoned by Microsoft.
    In fact, it can also be updated continuously until 2030 like Excel in office word.

    A lot of Microsoft software is convenient. The number one in the world was finally completely cut down and abandoned by Microsoft.

    And now they all envy it. Why does Google Chrome make more money than Microsoft's operating system?
    Is it better to sell Microsoft earlier and use all the money to buy Google and Nvidia shares.
    Bill Gates used to own 46% of the stock, but now it's only about 1%.

    But he invested in a lot of relatively stable fund companies, the annual return may only be about 5 to 10%.
    Bill Gates is afraid to invest in Nvidia and Apple. If you can get a 30% return every year, why not buy it?

    Microsoft CEO Nadella revealed on the latest episode of the BG2Pod podcast that Google makes more money on Windows than Microsoft because of the dominance of the Chrome browser. "It's a real tragedy that Chrome is the dominant browser because we beat Netscape and lost to Google," he said. "This is the best news for Microsoft shareholders-we lost so badly, now we can compete and win back some market share," he joked.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,688

    Re: why Vb6 can implement the invocation of an event class in 5 lines.javaVb6 can imp

    What is the point of this? It starts out as a lament for VB6, then it goes off the rails and ends up talking about Bill Gates's investment strategy, which really isn't a question.
    My usual boring signature: Nothing

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