Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: brew on April 13, 2007, 08:29 PM

Title: Console application
Post by: brew on April 13, 2007, 08:29 PM
So i made this console application and in order for the program to stay active, i have to run a constant loop.
this is VERY cpu consuming, and when I tried to connect to bnet with it, it took about 7-8 seconds. (if i commented out the loop it would connect much faster, but not work after that.)

Private Const STD_INPUT_HANDLE = -10&
Private Const STD_OUTPUT_HANDLE = -11&
Private Const STD_ERROR_HANDLE = -12&

Sub Main()
    Show
    Do
        DoEvents
        Select Case ReadText
            Case "/exit": Hide
            Case "/connect"
                frmMain.WS.Close
                frmMain.WS.Connect "213.248.106.200", 6112
                AddChat vbForeYellow, "[BNET] Connecting..."
        End Select
        DoEvents
    Loop
End Sub

Public Sub Show()
    AllocConsole
    SetConsoleTitle "Console Test"
    hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)
End Sub

so on...

Anyone got any ideas
Title: Re: Console application
Post by: warz on April 13, 2007, 08:33 PM
C
Title: Re: Console application
Post by: Barabajagal on April 13, 2007, 08:35 PM
Don't use VB for console apps?
Title: Re: Console application
Post by: brew on April 13, 2007, 08:36 PM
but... i like vb
Title: Re: Console application
Post by: warz on April 13, 2007, 08:42 PM
but... what you're trying to write is better suited for a different language
Title: Re: Console application
Post by: brew on April 13, 2007, 08:46 PM
acually you're right... the past two topics i've posted here pertains to things almost unheard of in vb6 and easy as hell in c/c++, but i still love vb if vb was a person i'd hug it
Uhh and btw i believe the way consoles in C work the same way, except they have a break(); (or something) at the end of execution, so it doesn't exit until it receives input (a key press) So i think the entire thread is paused in C, too. You just don't notice it. (correct me if im completely wrong) Yeah, using a console was a bad idea. Anyone know where I can get the "raster fonts" that console uses?
Title: Re: Console application
Post by: l2k-Shadow on April 13, 2007, 09:47 PM
instead, you could use CreateWindow() and code the application window, then implement a callback function
Title: Re: Console application
Post by: brew on April 13, 2007, 10:41 PM
Quote from: l2k-Shadow on April 13, 2007, 09:47 PM
instead, you could use CreateWindow() and code the application window, then implement a callback function
I acually tried that-- by using form_Load on startup, then calling sub main(). Now it no longer exits immediately, but the console window that is "spawned" is now "inactive" (no input/output). It seems like I no longer have a handle on that console window (but i know i do, i would have to. I don't call freeconsole() until hide, which is only called upon exit command)
Title: Re: Console application
Post by: l2k-Shadow on April 13, 2007, 11:23 PM
is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
Title: Re: Console application
Post by: Hell-Lord on April 14, 2007, 01:08 AM
One thing is to remove DoEvents.
Title: Re: Console application
Post by: warz on April 14, 2007, 01:52 AM
one thing one thing one thing, boo hoo
Title: Re: Console application
Post by: Hell-Lord on April 14, 2007, 04:01 AM
Quote from: ♥ on April 14, 2007, 01:52 AM
one thing one thing one thing, boo hoo

???
Title: Re: Console application
Post by: brew on April 14, 2007, 10:49 AM
Quote from: Hell-Lord on April 14, 2007, 01:08 AM
One thing is to remove DoEvents.
ok, please you try that
Title: Re: Console application
Post by: brew on April 14, 2007, 10:49 AM
Quote from: l2k-Shadow on April 13, 2007, 11:23 PM
is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
Wow, i just tried the sleep api like you said and it worked absolutely perfect. (although i'm not exactly sure why/how) Thanks, shadow.

Edit*
It doesn't work after you enter text 3 times. And if I use the loop way, which is guarenteed to work, it doesn't connect. What gives -_-
Title: Re: Console application
Post by: MyndFyre on April 16, 2007, 02:01 AM
Quote from: brew on April 13, 2007, 08:36 PM
but... i like vb

VB.NET.  Console.ReadLine() blocks the thread while in a loop preventing massive CPU usage.
Title: Re: Console application
Post by: Imperceptus on April 18, 2007, 06:32 PM
i strongly suggest not making a console app in vb. its really not going to perform like you would want it to. you can do everything you would want to in vb.net.  beyond which. Is a console bot what you really want to do?