Question from a complete beginner

JohnnyK
01-07-2006, 03:55 PM
Ok. You may find this question stupid, I don't know. But I have absolutely no experience in Visual Basic or any programming (other than PHP, if that counts) and want to get an answer to this first before I start learning.

Visual Basic is a language to create programs, correct? What I don't understand is why you need a program (Visual Studio) to create programs. If Visual studio is a program that creates programs, what created Visual Studio? (It's like the chicken and the egg thing)

When I program PHP, all I need to do is write PHP in a text editor and save it with a .php extension to make it become a PHP file. Why does Visual Basic code (or script or whatever you call it) need to be created using a program, rather that just a text editor?

Thanks for the help.
(Please take this time to laugh at me for knowing nothing.)

Iceplug
01-07-2006, 04:10 PM
Well, a brief chain of events responsible for VB:
Visual Studio was written in C++.
C++ was written in Assembler
Assembler was written in machine language.
Machine language is written (according to the CPU architecture and how it accepts functions) in 0s and 1s in the Hard Drive memory.
Hard Drive Memory is written with little arms and stepper motors that send magnetic fields into a magnetic medium, causing it to have a certain domain sequence that corresponds to a 0 or 1.
Oh, did I go too far back? :p

You don't actually need the IDE to make a text file that contains the code that you need. You also don't need the IDE to compile a code file (or text file) into a program.
The advantage of the IDE is so that it is easier for you to manage an application, with tools such as error checking, syntax checking, tracking variables, and color-coding, allowing auto complete boxes and intellisense to tell you what parameters your function will accept, etc.

Also, PHP is interpreted code - that means that servers with PHP installed will actually run a PHP program that will read your file, translate it into machine commands that tell it to put certain things into an HTML form or elsewhere on the server. VB code compiles to EXE files, which are instructions to the CPU on what to do. You can 'save' the VB code as a code file, but it is not runnable in this state.

And I do not find any questions stupid unless they are stupid on purpose.

VisualaBasikka
01-07-2006, 05:47 PM
Another advantage of using Visual Studio to program in visual basic instead of doing everything in Notepad is the GUI graphic user interface.

With the GUI you can create command buttons, text boxes and scroll bars with just a few clicks of the mouse, whereas otherwise it would take several lines of programming therefore saving time and making it less boring.

JohnnyK
01-07-2006, 07:26 PM
You don't actually need the IDE to make a text file that contains the code that you need. You also don't need the IDE to compile a code file (or text file) into a program.

So does anyone actually write code without an IDE? I guess it's possible, but is it common?

Is using Visual Studio equivalent to using Dreamweaver? I only ask because I like creating the code myself. I don't want to think that Visual Studio is doing all the work.

mrjeffy321
01-07-2006, 07:41 PM
Writting a program in VB without the use of visual studio would not be my first choice, and I dont know anyone who actually does that. But if you dont want to buy the IDE, it is an option.
Is using Visual Studio equivalent to using Dreamweaver? I only ask because I like creating the code myself. I don't want to think that Visual Studio is doing all the work.
I dont think that using DreamWeaver to write HTML code for you is a very good comparison to what visual studio does for you. Dreamweaver can do pretty much everything for you without any real knowledge of HTML, whereas in VB, visual studio just writes the interface and helps you type out some of the code faster. In visual basic, you still very much need to know what your doing to get the job done.

JohnnyK
01-07-2006, 08:51 PM
visual studio just writes the interface and helps you type out some of the code faster. In visual basic, you still very much need to know what your doing to get the job done.

Doesn't it also translate what you write into some other code. I'm thinking machine code, but I'm probably wrong. What I'm talking about it the code you would see if you opened up a .exe in a text editor. Doesn't Visual Studio change stuff like functions and what not into that?

mrjeffy321
01-07-2006, 10:42 PM
when visual studio turns the code you write into an exe, it uses the visual basic compiler which is seperate from the exe. Nothing prevents you from writting all the code you want using a text editor and then using the VB compiler to make an exe.

JohnnyK
01-08-2006, 10:15 AM
when visual studio turns the code you write into an exe, it uses the visual basic compiler which is seperate from the exe. Nothing prevents you from writting all the code you want using a text editor and then using the VB compiler to make an exe.

So I guess my question really is about the compiler. I don't want to think the compiler is doing all the work. Does anyone create the exe code without a compiler?

Also, why is the code compiled when it becomes an exe? Why isn't an exe just plain VB code?

Iceplug
01-08-2006, 10:52 AM
The compiler is what turns English into machine code. Anyone who creates EXE code without using a compiler is either a compiler creator, computer architecture student/professor, or off of their rocker.

If you decide to learn about the architecture of a microprocessor, you'll really see what executable code does.
But, what happens is the compiler will take code
let's say X = 10 - (Y + 3) / 2)
and turn that into some assembly instruction (not just one)
Pretend like:
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110
is the compiler code that turns your VB code into Assembler code

Mov Ax, Ds:[Y]
Add Ax, 3
Mov Bx, 2
Div Bx
Mov Cx, 10
Sub Cx, Ax
The above is assembler (aka assembly) code.

Etc. and then the compiler will then, using the interpretation for the CPU, convert each line into a series of 0s and 1s that will tell the CPU what to do for each instruction:
So the compiler runs the following instruction to turn the ASM into machine code.
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110 (converts ASM to machine code)

And the compiler will spit out:
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110 (this is your code that you wrote)

into the EXE which will tell the CPU to do that operation.

So, the EXE will contain direct instructions to the CPU as to what it needs to do.

Contrasting with a PHP file:

Let's say you put in a text file between PHP tags:

<?php
$echo (10 - ($y + 3) / 2);
?>

save it as a PHP.
At this point it is still a text file. This file will not run and cannot be executed.
Put it up on a server. When you go to www.place.com/stuff.php (the file above),
you tell the server to open a PHP file

So, the PHP executable (note it is an executable - already compiled code) that runs your .php file (uncompiled code). We'll call this application php.exe

The executable will end up containing instructions that will read your php file.
If LineInFile.Has("=") Then
LHS = LineInFile.LeftOf("=")
RHS = ParseExpression()

They've already been compiled into a bunch of instructions that are specifically set to parse PHP files, such as the one you've uploaded.
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110 (PHP file parsing code)

So, the php.exe on the server will then look at your file:
<?php
$echo 10 - ($y + 3) / 2;
?>

Parse it.
10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100 (adds Y + 3)

some more operation statements to do the rest of the math

Finally

10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100 (Turns result into a string that you can read and copies it to an HTML file)

So, you get a big "7" in the HTML file.

The HTML source file is passed through the internet connection in response to the browse to www.place.com/stuff.php

This HTML file is then passed on to you via the internet connection, where your internet browser Browser.exe (Internet Explorer, Mozilla Firefox, Netscape etc.) will then receives this HTML:

<html>
<body>
7
</body>
</html>

And then, since browser.exe is already compiled, you have more machine code that parses the HTML (returned by stuff.php from the server).

10101110 00010100 01111110 11110100 10101110 00010100 01111110 11110100
11110100 10101110 00010100 01111110 11110100 10101110 00010100 01111110 (shows the 7.)

And that's the chain of events occuring with PHP.

So, with PHP, at no time is your code converted into machine language - it is simply interpreted by other programs php.exe, browser.exe to show on the screen. With VB, your code actually becomes a program. (You could make your program parse files as well)

I hope this helps. :)

JohnnyK
01-08-2006, 11:48 AM
So what's the stuff you see when you open a .exe in a text editor.

For example (part of aim.exe in a text editor):
P EPud@@ }u
}s}v `P\J@ h h@@ `Pl@@  PV@@ t&LP @@ PV@@ uV@@ 3u t
dA@ Y}x t
upp@@ A@ 8B@ Md_^[ h %A@ %A@ %A@ %L@@ %H@@ %D@@ %@@@ %8@@ %4@@ %0@@ %<@@ %LB@ %HB@ %XB@ %DB@ %PB@ %TB@ %@B@ %@@ %(@@ % @@ %$@@ %`B@ jhL@ | e j ji YY3@ËeMjt@@ ;
$`@ u%A@ %A@ %A@ %xA@ %tA@ %lA@ jPd PD$ d% l$ l$ P%`A@ %XA@ =j@ u% A@ hj@ hj@ t$  t$YH=  să PQL$  -  =  s+ȋą@PjthL@ _ 3ۉ]S=@@ f8MZuH<ȁ9PE uA=  t=  t]' v39 ytv39 E]j,A@ Y
j@
j@ (A@
j@ A@
j@ A@ j@   90`@ u h=@  A@ Y h`@ h`@ w h`=@ j@ E؍EP5j@ EPEPEP@@ E;}j Yh `@ h `@ ( YY@@ 0u܊< w]:

What is that and what's it called?

reboot
01-08-2006, 11:56 AM
Binary data. You can't see the source code anymore once it's compiled.

Iceplug
01-08-2006, 12:08 PM
P = 01001111
9 = 00111001
= 11111111

Each character corresponds to eight bits of binary code.

loquin
01-09-2006, 09:25 AM
Remember, the processor in your PC or in a server, ONLY understands 1's and 0's. That's it.

The various bytes represent EITHER a command that the processor will do, or data that the processor will use.

The VB compiler converts visual basic language statements (which WE understand) into the machine code that the processor understands. (Note - we CAN understand machine code, although it's difficult for US to read.) This means that the compiler only needs to be run ONCE.

An interpreted language like PHP reads the source code, and converts it (in a roundabout way) into machine code each and every time the program is run... But, means that there is an extra layer of code that is run each time you run an intrepreted app. This makes an executeable faster than an intrepreted app. Depending on the intrepeter and compiler, a compiled app can be much, MUCH faster than an intrepreted one.

JohnnyK
01-11-2006, 09:10 PM
Thanks much for the help, all!

sandwich
01-13-2006, 10:41 AM
Binary data. You can't see the source code anymore once it's compiled.

You can, using reverse engineering tools, like w32dsm, OllyDBG and other such things

reboot
01-13-2006, 11:16 AM
No you can't. You can disassemble it and see the ASM, you can't see the original source.

simons
01-13-2006, 11:23 AM
P = 01001111
9 = 00111001
= 11111111

Each character corresponds to eight bits of binary code.

well.. interesting topic...

so every character is a binary code.. but how many combinations are there? is there a list of binary code for each letter/number?

thanks
simons

VisualaBasikka
01-13-2006, 02:13 PM
There are 256 (2^8) combinations for a byte (8 bits) each bit can be 0 or 1.

mrjeffy321
01-13-2006, 06:01 PM
Each character has an ascii code, this code can be represented as an 8 digit binary number.

To use Iceplug's example,
P = 80 = 01010000
9 = 57 = 00111001
= 255 = 11111111

Iceplug
01-13-2006, 06:15 PM
well.. interesting topic...

so every character is a binary code.. but how many combinations are there? is there a list of binary code for each letter/number?

thanks
simons
Once you get the character code for a certain character, you convert the character to base 2.

Step 1: Divide number by 2
Step 2: Check the remainder of the above division
Step 3: Go to step 1 until your division result is 0 with a remainder of 0 or 1.

The 0s or 1s that you get for the remainder are most significant to least significant:
= 207
(207/2 = 103R1) 1
(103/2 = 51R1) 1
(51/2 = 25R1) 1
(25/2 = 12R1) 1
(12/2 = 6R0) 0
(6/2 = 3R0) 0
(3/2 = 1R1) 1
(1/2 = 0R1) 1
Therefore Asc("") = 207 (in decimal) = 11110011 (in binary)

reboot
01-13-2006, 06:27 PM
And F3 in hex. :)

JohnnyK
01-15-2006, 05:18 PM
And F3 in hex. :)
You guys explained alot. Thanks much!

While you're at it, what's hex? I have a hex editor (used it to clone aim), but what is the code it displays?

Examples:
AF8AECE7
and, at the same time on the right window
GetWindowThreadProcessId....FindWindowA.USER32.dll....RegOp

Those aren't corresponding, just two lines I took from each window. Anyway, what is it?

How about Octal?

When you're done with those I got an unrelated question. YAY!

ronson
01-15-2006, 06:07 PM
Hex is properly termed Hexedecimal i think and its like another form of binary as it uses 0's and 1's.

Say you have 11111111 in binary which equals to 255, you can convert that into hex by putting the numbers into a group of four so it would be like:
1111|1111 which in hex equals FF.

In short, hexidecimal uses base 16. There is 10 digits and six letters in Hex. In hexadecimal notation, the decimal numbers 0 through 15 are represented by the decimal 0 through 9 and the alphabet letters A through F.

So:
Meaning
0 - 0
1 - 1
2 - 2
3 - 3
4 - 4
5 - 5
6 - 6
7 - 7
8 - 8
9 - 9
10 - A
11 - B
12 - C
13 - D
14 - E
15 - F

Although i myself still don't understand why its used, i just know how to convert.

mrjeffy321
01-15-2006, 06:14 PM
Hex (short for Hexadecimal) and Octal are just other numbering systems that use a different base.
Ordinary, everyday, number are base 10 (0 though 9), binary is base 2 (0 to 1). Hexadecimal is base 16, using the characters 0 though 9 and A though F to represent its number, Octal is base 8.

You can more easily represent bytes with Hex[adecimal] than you can with binary. In Hex it only takes two characters what in binary would take 8.
You will commonly see Hex used to represent colors, for example FFFFFF is white. Each set of 2 characters represents a component of the color, FF = 255, so in rbg format it would be 255, 255, 255.

JohnnyK
01-15-2006, 06:43 PM
Nice, thanks

So my next question is this...
I downloaded Visual Basic Express and created an incredibly simple program that was explained in a tutorial book I have. Anyway, I had to use the toolbox to add things like buttons and text fields and what not to the the form (or main window or whatever its called). Is there a way to format the window without using the toolbox (like in a text editor).

ronson
01-15-2006, 07:07 PM
If you mean use your own control? Yes you can create your own controls and you can also code them uses classes and such.

JohnnyK
01-15-2006, 07:41 PM
No I mean how do I create something like say a text box or a radio button without using Visual Studios toolbox?

JohnnyK
01-19-2006, 07:20 PM
Anyone?

shaul_ahuva
01-19-2006, 11:39 PM
You can create any control in code; the toolbox is just a shortcut...


Dim Button1 As New Button
Dim TextBox1 As TextBox = New TextBox()


are two different ways to create a control. Then, you need to add them to the form so they can be displayed:


Me.Controls.Add(Button1)
Me.Controls.Add(TextBox1)


From there, you can set properties and call methods:


Button1.Text = "Click Here"
TextBox1.Enabled = False

Button1.PerformClick()
TextBox1.Paste("Some text")


When you use the toolbox, Visual Studio takes care of the basic chores for you so you can concentrate on designing the form.

JohnnyK
01-21-2006, 05:04 PM
Cool, thanks. So why doesn't Visual Basic Express display that code with the other code (like Subs and such)?

Iceplug
01-21-2006, 05:20 PM
Because MS thinks that all VB programmers should be cut-and-paste dummies that don't know how to create controls because they've been using VB6 for an entire 0.2 years.
Er, um... the control instantiation code is hidden in the form's partial class, which has the Designer Created code. For the most part, you won't have to actually create a control on the form at runtime, but rather, add the forms to the designer and let them work for you. Having the control instantiation functions with the code makes the code look very cluttered, although you *could* minimize it. :)

JohnnyK
01-21-2006, 05:51 PM
How do I display the code that shaul_ahuva was talking about

mrjeffy321
01-21-2006, 06:21 PM
In 2002/2003, the code to auto generated code create the controls on the form is located in 'Windows Form Designer generated code' region at the top of the code section. In 2005, they have hidden it a bit, located in the form_name.Designer.vb file.
But nothing stops you from creating your own controls at runtime.

Timbuk2
01-21-2006, 06:23 PM
I think that you can press on the Form_Designer.vb Tab and you will see the design of the form there, but I am not sure about that:
I don't worry about the designing code, I just let Visual Basic IDE do the diirty work for me

JohnnyK
01-21-2006, 07:24 PM
What's a good VB compiler? Something small that just compiles without all the IDE stuff and what not.

mrjeffy321
01-21-2006, 07:44 PM
What's a good VB compiler? Something small that just compiles without all the IDE stuff and what not.
I think the best VB compiler is the VB compiler.
The compiler is not the IDE, but a file in and of itself that is free to download and use. The IDE is just a facy way of making your programs. You could in theory (But I wouldnt) write it in note pad if you wanted to and then compile it manually.

JohnnyK
01-22-2006, 11:51 AM
You could in theory (But I wouldnt) write it in note pad if you wanted to and then compile it manually.
How would I do that, step by step? I tried to do it but I don't know how.

reboot
01-22-2006, 12:00 PM
What version of VB are you talking about? If VB6, you have to buy it to get the compiler. If you're talking vb.Net, you can download the compiler from Microsoft. There are instructions on how to do command line compiling on MSDN.

calder
01-28-2006, 05:47 PM
I have slightly more experience than Johnny, not a lot in vb but I do know other languages and the basics behind it. I want to thank the guys that replied here for giving me some new knowledge as well.

Johnny I do web design as well, and I use Dreamweaver as my main tool. I have a feeling I understand where your questions are coming from. It seems to be a very deep seated feeling among most web designers that using a wysiwyg environment is a bad thing. And to some extent yes it can be, we all know they can create strange and sometimes badly optimized code. But there is a difference here. If you want to code the way it sounds like you design websites VB is likely not the language you are after.

Now I may very well be behind the times here but I think some of this still applies. VB was created to allow programmers to make applications easily for Windows. It started out as kind of a poor cousin to languages like C and C++, it couldn't make stand alone applications in the beginning, you needed to have the VB runtime files on your system for VB programs to work. The code was clunky and slow compared to other languages. It has improved immensely since then obviously. I have studio 2005 but still work primarily in VB 6 because I find it a little easier for the web based apps I build. But rest assured unlike a web design wysiwyg program there is no benefit to creating a textbox programatically as compared to drawing it on the form. Yes you can if for example you make a form where you want one to appear at the click of a button, but again, draw it and use it's visible property to control that.

And again correct me if I am wrong but the lower level a program is (the closer to the 1's and 0's the processor understands) the faster it will run and generally the smaller it is. There are programmers that write in very low level languages Steve Gibson www.grc.com for example writes Windows gui apps in assembly I believe, but it is my feeling they are few and far between.

Microsoft gives you the tools you need to make your life easier, they work and they work well. Use em lol. But I am impressed by your desire to understand and the fact that you are working through a book to learn rather than just asking people to write the code for you ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum