Results 1 to 11 of 11

Thread: General questions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    General questions

    Hello,

    I hope I am posting in the right forum saw a few alike sub categorys.

    Anyway I recently started with VB2008, there seems to be a 2010 should I switch while I am still at the very beginning?

    I have a few questions in general. I used to program/script in other languages and there seem to be alot of differents for the moment. And yes I googled most of it and a clear answer never game out or I am looking in the complete wrong place.

    First of all Subs. This seem to be some sort of function but its not. What is it exactly?

    Global variables, I have read some tutorials but they refer to a tab in VB2008 that says '(general)' and '(Declaration)' however nothing changes withing VB2008 on selecting those.

    Modules, What are those? on first sight they seem to be sort of code structure to be called on later.

    Namespacing, Never really had to worry about those. It seems to be a sort of easy way to level your libary. Like I saw 'Me.system' and Me is the name of the namespace and it includes 'system' to your current page/program(sort of include?)

    How do you know where the program is running from? For example the program is running from C:\myprogam\ how do i know this so I could load files from there? like images/text/whatever.

    Multipule forms, Lets say I start form1, like the default naming, and I want on a button click to open an other form, form2, how can I interact with both of them? Like a page of 'settings' form1 has to adjust to that. Pass By Referrence comes to mind.

    When I click properties on my project in the Solution explorer I get a view tabs. What are the following: Resources, Service, settings(refers to my question above???), Reference?

    What is the 'main' for my program is it form1? and is that also the global scope?

    Threads, I heard thing about this during video tutorials like thread pool, single thread, thread synchronization. What are they and what do they do? I assume windows somehow works with this.

    If for example I got 'settings' in my program I have to save those in a file and load it in every time the program is being run?

    I assume that a programs written in VB only works on Windows? true/false?

    That are the questions for now. I do not expect any completly written explainations but would be much appreciated. Linking tutorials/other resource would be great.

    Thanks in advance

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: General questions

    Quote Originally Posted by Blixa View Post
    Hello,

    I hope I am posting in the right forum saw a few alike sub categorys.

    Anyway I recently started with VB2008, there seems to be a 2010 should I switch while I am still at the very beginning?
    I would stick with VS 2008 until 2010 is officially released, while they do work together just fine 2010 is still in Beta and bad things could happen, I prefer to be cautious
    Quote Originally Posted by Blixa View Post
    I have a few questions in general. I used to program/script in other languages and there seem to be alot of differents for the moment. And yes I googled most of it and a clear answer never game out or I am looking in the complete wrong place.

    First of all Subs. This seem to be some sort of function but its not. What is it exactly?
    A sub is a function that doesn't return anything.

    For example in Java and C# if you want a sub you declare a void function:
    private void function YourSubName{
    }

    In vb and vb.net you just use the sub keyword:
    Private Sub YourSubName

    End Sub
    Quote Originally Posted by Blixa View Post
    Global variables, I have read some tutorials but they refer to a tab in VB2008 that says '(general)' and '(Declaration)' however nothing changes withing VB2008 on selecting those.
    A global variable is just a variable that can be accessed anywhere in the project, usually in vb and vb.net you declare it in a module
    Quote Originally Posted by Blixa View Post

    Modules, What are those? on first sight they seem to be sort of code structure to be called on later.
    A module is a static shared class, all Public/Friend/Protect Public variables, subs, functions can be accessed from all other files in the project.
    Quote Originally Posted by Blixa View Post
    Namespacing, Never really had to worry about those. It seems to be a sort of easy way to level your libary. Like I saw 'Me.system' and Me is the name of the namespace and it includes 'system' to your current page/program(sort of include?)
    'Me' always refers to the current instance of the Class you're coding in, there is no 'System' namespace in 'Me', 'System' is a root namespace in the Framework. System.IO, for example, has tons of IO classes you can use to access things on the file system.
    Quote Originally Posted by Blixa View Post
    How do you know where the program is running from? For example the program is running from C:\myprogam\ how do i know this so I could load files from there? like images/text/whatever.
    Application.StartUpPath is the full path of where the executable is on the file system
    Quote Originally Posted by Blixa View Post
    Multiple forms, Lets say I start form1, like the default naming, and I want on a button click to open an other form, form2, how can I interact with both of them? Like a page of 'settings' form1 has to adjust to that. Pass By Referrence comes to mind.
    In form1:
    Dim frm2 As New Form2

    you now have declared and instantiated a Form2, so frm2.Show will physically show Form2, you can have multiple Form2's floating around.
    Quote Originally Posted by Blixa View Post
    When I click properties on my project in the Solution explorer I get a view tabs. What are the following: Resources, Service, settings(refers to my question above???), Reference?

    What is the 'main' for my program is it form1? and is that also the global scope?
    Sub Main is typically where Java and C# programs start (vb.net does to, but you generally never see the actual Sub Main) but vb.net allows you to specify your own Sub Main, you generally put it in a module and the program completely terminated when the code hits the 'End Sub' part of 'Sub Main'
    Quote Originally Posted by Blixa View Post
    Threads, I heard thing about this during video tutorials like thread pool, single thread, thread synchronization. What are they and what do they do? I assume windows somehow works with this.
    Threading is something you should get into a little later, get the basics of Subs/Functions and Multiple forms down first.
    Quote Originally Posted by Blixa View Post
    If for example I got 'settings' in my program I have to save those in a file and load it in every time the program is being run?
    Use My.Settings, they're saved to a file on exit and loaded from the file on start be default anyways
    Quote Originally Posted by Blixa View Post
    I assume that a programs written in VB only works on Windows? true/false?
    False, though there really isnt support for it other than on Windows.
    Quote Originally Posted by Blixa View Post
    That are the questions for now. I do not expect any completly written explainations but would be much appreciated. Linking tutorials/other resource would be great.

    Thanks in advance
    You've got a long road ahead of you, but welcome to the club!
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: General questions

    There's a lot there.... I'll try to answer what I can. First, I'd like to point out that we have a number of FAQ/Tutorial threads here, some of which will answer some of your questions.
    http://www.vbforums.com/forumdisplay.php?f=73


    Anyway I recently started with VB2008, there seems to be a 2010 should I switch while I am still at the very beginning?

    since you are just starting out, I wouldn't use VB2010 just yet. It's still in beta, so there are some quirks and problems with it. VB2008 should suit you just fine.

    First of all Subs. This seem to be some sort of function but its not. What is it exactly?
    Sub is a function that in short doesn't return anything. It's the same as a void function in C.

    Global variables, I have read some tutorials but they refer to a tab in VB2008 that says '(general)' and '(Declaration)' however nothing changes withing VB2008 on selecting those.
    This is something that is unique to the VB Editor. The one on the left "(general)" allows you to select objects (usually the ones on the form) and the one on the right allows your to select an event of the object (if you selected an object on the left drop down)... or a sub/function (if you select "(general)") ... The General selection option tells the IDE to look in the "general" section of the code.... When you select "Declaration" that takes you to the "general" "declaration" part of the file... usually all the way at the top, where your general declarations go (public/private variables, constants, etc.)

    Modules, What are those? on first sight they seem to be sort of code structure to be called on later.
    In short, yes. Modules are basically shared classes. Generally used for global declarations.

    Namespacing, Never really had to worry about those. It seems to be a sort of easy way to level your libary. Like I saw 'Me.system' and Me is the name of the namespace and it includes 'system' to your current page/program(sort of include?)
    It's a way of logically organizing your classes. For instance, the Me namespace. Several of the namespaces and classes found under "Me" reside in several different assemblies. But because they all reside in the Me namespace, they take on the appearance of being grouped together. You can even then extend the namespace and add your own class to it. Add a new class file to a project, at the top, put "Namespace Me" (don't forget the end namespace at the end) ... then put in some public functions in the class1 shell.... then from in your app, you should be able to type "Me." and at the "." get "Class1" to show up.

    How do you know where the program is running from? For example the program is running from C:\myprogam\ how do i know this so I could load files from there? like images/text/whatever.
    Application.StartupExe (or something along those lines). It's in the Application class.

    Multipule forms, Lets say I start form1, like the default naming, and I want on a button click to open an other form, form2, how can I interact with both of them? Like a page of 'settings' form1 has to adjust to that. Pass By Referrence comes to mind.
    This isn't simple, since a lot depends on what it is you are trying to accomplish. But there are a number of threads running around on how to get two forms to communicate with each other.

    When I click properties on my project in the Solution explorer I get a view tabs. What are the following: Resources, Service, settings(refers to my question above???), Reference?
    Resources are embedded resources... they can be images, files, strings, a number of things. It's a way of having related data (for example images) with out having to include the actual images as separate files. All you need to do is extract them and use them.
    Settings are stored in the config file. Application settings are readonly to the end user and can't be changed w/o editing the config file. User settings get stored in a user.config file and are read/write. It allows to you customize the app per user.

    What is the 'main' for my program is it form1? and is that also the global scope?
    It depends. By default, yes. But that can also be changed (by changing some of the settings in the Project Options.

    If for example I got 'settings' in my program I have to save those in a file and load it in every time the program is being run?
    If you use the Settings from the Project Options.... yes and know. You don't have to explicitly do anything to load them, they are automatically loaded when the application starts. Saving them.... there's an option to make it autosave when the app shuts down, but I tend to go ahead and explicitly issue a My.Settings.Save when ever the user changes an option and hits the OK/Save button.

    I assume that a programs written in VB only works on Windows? true/false?
    Sort of... there's a project called MONO which can take .NET projects and run them on Linux. as long as you don't use anything that is Windows specific, and target framework 2.0 (I don't know which latest version of the FW Mono supports) then you can use Mono to compile and run the application on Linux.

    Hope that helps.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: General questions

    wauw thanks for those amazing answer, never expected it.

    Going to try to write my first program and will get back if I got more questions.

    Thanks both of you for those awesome answers!

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

    Re: General questions

    Those answers covered much of it, so here's a little supporting information.

    A thread about passing things between forms:

    http://www.vbforums.com/showthread.p...ght=Definitive

    An item to watch out for:

    A form is just a class (an object), and it is like any other class. However, ever since VB2005, forms had one added feature: The default instance. For any other class, you have to actually create an instance of the class with the New keyword (in some cases, a method will return an instance of a class, such as the CreateCommand method of a database connection object, which creates a new Command Object). Unfortunately, all forms have a default instance that is created automatically in the background, and which have the same name as the class. Therefore, if you have a Form1 in your project, that is the name of a class, but there is also an instance called Form1 automatically added to your project. Therefore, you can either do something like this:

    Dim nf as New Form1
    nf.SomeProperty = something

    or you can do this:

    Form1.SomeProperty = something

    In the first case, you are creating a new instance of Form1 and calling it nf, while in the second case you are working with the default instance of Form1. Technically, there is nothing wrong with using the default instance. It is a valid instance of the form class, just like any other instance. However, because the instance has the same name as the class (which is just a category, not a specific object), people often get confused. They don't realize that an actual instance was created for them in secret. For this reason, I thoroughly despise the default instances, and always prefer to explicitly create a new form every time I want to show one (also I started with .NET prior to 2005 when the default instance didn't exist).

    Threads:
    Threading is certainly an advanced subject, but it is also one that you should definitely be aware of. Every process runs on a thread. Normally, you just have a single thread, which is known as the User Interface, or UI, thread. However, suppose you have some task that takes a long time to complete. If the UI thread runs that task, it will block all other messages from being processed, which means that buttons won't click, scroll bars won't scroll, screens won't paint themselves, and so on. The program will appear to be frozen until that long running process finishes. Not good. Multi-threading is a way to have multiple processes running simultaneoulsy. The processor will allocate some tiny slice of time to one process, then to the next, and so forth. If you only have a single core, and all processes take ALL the time they can have, then you would see little benefit from multithreading. However, in the earlier example, there is one process that is long running, and it is blocking the UI from processing input and other events. By moving the long running process onto a background thread, the UI thread is free to respond to events, and that is all that it needs to do. Consider that even for a fast typist, the rate of keystrokes is only a few per second. A computer can perform millions of computations between keystrokes, so why make it sit and wait if it has something else to do? By moving the long running process into a background thread, the computer can switch to working on that process in those lengthy pauses between keystrokes, and it will appear to be doing two things at once. Better yet, with the rise of multi-core processors, each processor can run a thread (or multiple threads) at the same time. In such a case, you can have two long running processes running at the same time and running at full speed. The OS will divvy up the processor cores to the running processes without you doing anything. The only thing you need to do would be to set up your long running processes in their own threads, and the OS will do the rest, whether it has one core to work with, or many.

    However, there are some real drawbacks to multithreading, as well. For one thing, an object is not specific to a single thread. This can mean that two different threads will alter the object, and you can never know when it will happen. For instance, if two threads both executed the statement:

    a = a + 1

    If thread X ran this and checked the value of A before and after this statement, then A could be 1 higher, or two higher, because the value of A would first be loaded into a register, then incremented. If A was loaded, then the processor switched to the other thread that loaded A and added 1, then switched back, thread X would add 1 to the original value, and all would be well....but nearly anything else could happen, too. For instance it could check A, then the other thread could increment A, then the first thread could increment A, and A would appear to have increased by two. Therefore, if multiple threads write to the same object, then you have a race condition. You can't predict which thread will get there first. Sometimes this doesn't matter, other times it becomes the most maddening of bugs, because it will be intermittent. To solve that, you have to make sure that reads and writes between different threads are synchronized, which can lead to deadlocks if not done properly, but I won't go into that. The point is that multithreading can be very useful, but it can also be very tricky.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: General questions

    Thanks for the explaination of threading I think I understand the basic.

    However I got a new question.

    I am trying to make a sort of ping pong program between a server and a client. (1 client at a time for now, multiple will come later).

    However the server seems to be listening but the client cant seem to connect and I cant figure out why.

    Code:
    Private Sub connectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connectButton.Click
            If Not ipText.Text = "" Then
                sock.RemoteHost = ipText.Text
                sock.RemotePort = portText.Text
                sock.Connect()
            End If
        End Sub
    server listening code
    Code:
    Private Sub startServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startServer.Click
            If Not portText.Text = "" Then
                sock.LocalPort = portText.Text
                sock.Listen()
                startServer.Enabled = False
                If sock.CtlState = MSWinsockLib.StateConstants.sckListening Then
                    writeLog("listening...")
                End If
            End If
        End Sub
    Code:
    Public Sub sock_connectionRequest(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles sock.ConnectionRequest
            If sock.CtlState <> MSWinsockLib.StateConstants.sckConnectedThen
            sock.Accept(e.requestID)
            End If
    
        End Sub
    tried: sckconnected,listening

    but when I check the status with: sock.CtlState = MSWinsockLib.StateConstants.sckClosing
    its true, I don't seem to get any errors or anything.

    the IP is my localIP (192.168.x.xxx) and port is 28920(just random).

    sock is the winSock object.
    When I press connect in the GUI it goes without problems. when I check the status it says its closing.

    anyone have an idea what the problem might me? Would pass on more code but it doesn't seem to be relevant. Is there someway I can find out why its closing?

    thanks in advance
    Last edited by Blixa; Jan 2nd, 2010 at 09:34 PM. Reason: added server listening+connectionRequest code

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: General questions

    I'm not sure if it would help but checkout the client/server example in my sig.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    86

    Re: General questions

    I checked your signature and I dont see any big differents (except its vb6).


    the sock.CtlState returns 6
    http://msdn.microsoft.com/en-us/libr...8VS.60%29.aspx

    I am wondering what state 8 "Peer is closing the connection" means.
    is the server closing it or the client?

    update:

    I tried to turn all my networks off and tried it at 127.0.0.1 (dont know why just be sure I guess)
    It however results directly in a state 6 and a sec later in state 8.
    When I try to connect on something that does not exist I get an error tho 'Connection is forcefully rejected'

    Is the connectionRequest event correct? I think that the problem is there but not sure.

    anyone sees the problem?
    Last edited by Blixa; Jan 3rd, 2010 at 08:51 AM. Reason: update

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: General questions

    Quote Originally Posted by Blixa View Post
    I checked your signature and I dont see any big differents (except its vb6).
    Yeah, since I haven't used vb.net I don't know what the differences are with the code.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: General questions

    Quote Originally Posted by Nightwalker83 View Post
    Yeah, since I haven't used vb.net I don't know what the differences are with the code.
    Well for one: winsock isn't used in .Net, I think it can be used but .Net has much more up to date networking classes already available in the FW
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  11. #11
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: General questions

    Quote Originally Posted by JuggaloBrotha View Post
    Well for one: winsock isn't used in .Net, I think it can be used but .Net has much more up to date networking classes already available in the FW
    I guess I will fine that out when I go back to school and start my programming course, one of my subjects is VB.NET.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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